Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
queue
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
curry-packages
queue
Commits
8311f161
Commit
8311f161
authored
6 years ago
by
Michael Hanus
Browse files
Options
Downloads
Patches
Plain Diff
Imports updated
parent
d512925b
Branches
Branches containing commit
Tags
v0.0.1
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/RandomTest.curry
+0
-29
0 additions, 29 deletions
test/RandomTest.curry
test/TestQueue.curry
+30
-1
30 additions, 1 deletion
test/TestQueue.curry
with
30 additions
and
30 deletions
test/RandomTest.curry
deleted
100644 → 0
+
0
−
29
View file @
d512925b
-- 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
This diff is collapsed.
Click to expand it.
test/TestQueue.curry
+
30
−
1
View file @
8311f161
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
------------------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment