Skip to content
Snippets Groups Projects
Commit 8311f161 authored by Michael Hanus's avatar Michael Hanus
Browse files

Imports updated

parent d512925b
Branches
Tags v0.0.1
No related merge requests found
-- A few auxiliary functions to formulate tests with random numbers.
module RandomTest ( test, eq ) where
import List ( nub )
import Test.Prop
import System.Random
--- Tests a given predicate on a list of distinct random numbers.
--- In case of a failure, the list of random numbers is returned
--- in order to see the test cases in the CurryTest tool.
test :: ([Int] -> Bool) -> PropIO
test f = (rndList lenRnds >>= \xs -> return (if f xs then Nothing else Just xs))
`returns` Nothing
--- Tests whether two operations return equal results
--- on a list of distinct random numbers.
--- In case of a failure, the list of random numbers is returned
--- in order to see the test cases in the CurryTest tool.
eq :: Eq a => ([Int] -> a) -> ([Int] -> a) -> PropIO
eq f g = test (\x -> (f x)==(g x))
--- generate a list of at most n random numbers (without duplicated elements)
rndList :: Int -> IO [Int]
rndList n = getRandomSeed >>= return . nub . take n . (flip nextIntRange 100000)
--- maximal length of test lists
lenRnds :: Int
lenRnds = 1000
import List
import Test.Prop
import System.Random
import Data.Queue
import RandomTest
deq f = f . listToDeq
......@@ -29,3 +31,30 @@ testLength = eq (deq deqLength) length
testRotate = eq (deqs rotate) (\ (x:xs) -> xs ++ [x])
------------------------------------------------------------------------------
-- Random test:
--- Tests a given predicate on a list of distinct random numbers.
--- In case of a failure, the list of random numbers is returned
--- in order to see the test cases in the CurryTest tool.
test :: ([Int] -> Bool) -> PropIO
test f =
(rndList lenRnds >>= \xs -> return (if f xs then Nothing else Just xs))
`returns` Nothing
--- Tests whether two operations return equal results
--- on a list of distinct random numbers.
--- In case of a failure, the list of random numbers is returned
--- in order to see the test cases in the CurryTest tool.
eq :: Eq a => ([Int] -> a) -> ([Int] -> a) -> PropIO
eq f g = test (\x -> (f x)==(g x))
--- generate a list of at most n random numbers (without duplicated elements)
rndList :: Int -> IO [Int]
rndList n = getRandomSeed >>= return . nub . take n . (flip nextIntRange 100000)
--- maximal length of test lists
lenRnds :: Int
lenRnds = 1000
------------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment