Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
curry
curry-tools
Commits
1169979f
Commit
1169979f
authored
Jan 03, 2019
by
Michael Hanus
Browse files
Tools updated
parent
5a5d0e87
Changes
24
Expand all
Hide whitespace changes
Inline
Side-by-side
optimize/.cpm/packages/finite-map/package.json
0 → 100644
View file @
1169979f
{
"name"
:
"finite-map"
,
"version"
:
"0.0.1"
,
"author"
:
"Michael Hanus <mh@informatik.uni-kiel.de>"
,
"synopsis"
:
"Library implementing finite maps (efficient mappings from keys to values)"
,
"category"
:
[
"Data"
],
"license"
:
"BSD-3-Clause"
,
"licenseFile"
:
"LICENSE"
,
"dependencies"
:
{
"base"
:
">= 1.0.0, < 2.0.0"
,
"random"
:
">= 0.0.1"
},
"compilerCompatibility"
:
{
"pakcs"
:
">= 2.0.0"
,
"kics2"
:
">= 2.0.0"
},
"exportedModules"
:
[
"Data.Map"
,
"Data.FiniteMap"
],
"testsuite"
:
[
{
"src-dir"
:
"src"
,
"modules"
:
[
"Data.Map"
,
"Data.FiniteMap"
]
},
{
"src-dir"
:
"test"
,
"modules"
:
[
"TestFiniteMap"
]
}
],
"source"
:
{
"git"
:
"https://git.ps.informatik.uni-kiel.de/curry-packages/finite-map.git"
,
"tag"
:
"$version"
}
}
optimize/.cpm/packages/finite-map/src/Data/FiniteMap.curry
0 → 100644
View file @
1169979f
This diff is collapsed.
Click to expand it.
optimize/.cpm/packages/finite-map/src/Data/Map.curry
0 → 100644
View file @
1169979f
This diff is collapsed.
Click to expand it.
optimize/.cpm/packages/finite-map/test/TestFiniteMap.curry
0 → 100644
View file @
1169979f
import List
import Sort
import Maybe
import System.Random
import Test.Prop
import Data.FiniteMap
fm f = f . (listToFM (<)) . map (\x ->(x,x))
fms f = map fst . fmToList . fm f
fms' f = map snd . fmToList . fm f
so f = spnub . mergeSortBy (<) . f
testAddToFM = eq (fms (\x-> addToFM x 73 73)) (so (73:))
testDelFromFM = test
(\nums -> fms (flip delListFromFM (take 500 nums)) nums == so (drop 500) nums)
testPlusFM =
test (\nums -> let l=length nums
(xs,ys) = splitAt (div l 2) nums
in (map fst $ fmToList $ plusFM (fm id xs) (fm id ys)) == so id nums)
testMinusFM =
test (\nums -> let l = length nums
(xs,ys) = splitAt (div l 2) nums
in (map fst $ fmToList $ minusFM (fm id nums) (fm id ys)) == so id xs)
testIntersectFM = test
(\nums -> let l=length nums
(_,ys) = splitAt (div l 2) nums
in (map fst $ fmToList $ intersectFM (fm id nums) (fm id ys)) == so id ys)
testFoldFM = eq (fm (foldFM (\x _ z->x+z) 0)) (foldl (+) 0)
testMapFM = eq (fms' (mapFM (\_ z->z+1))) (so (map (+1)))
testFilterFM = eq (fms (filterFM (\x _->x>0))) (so (filter (>0)))
testSizeFM = eq (fm sizeFM) length
testEqFM = test
(\nums -> let l=length nums
(xs,ys) = splitAt (div l 2) nums
in eqFM (fm id nums) (fm id (ys++xs)))
testElemFM_LookupFM = eq (fm (\x-> elemFM 73 (addToFM x 73 73))) (const True)
testKeysFM_eltsFM = test
(\nums -> let finm=fm id nums in unzip (fmToList finm)==(keysFM finm, eltsFM finm))
testFmSortBy = eq (fmSortBy (<)) (so id)
testMinFM_MaxFM = eq (fm (\finm -> (fst $ fromJust $ minFM finm,
fst $ fromJust $ maxFM finm)))
((\l->(head l,last l)) .so id)
testUpdFM = eq (fm (\x-> lookupFM (updFM (addToFM x 73 73) 73 (+7)) 73)) (const $ Just 80)
spnub [] = []
spnub [x] = [x]
spnub (x:y:xs) = if x==y then spnub (y:xs) else x:spnub (y:xs)
------------------------------------------------------------------------------
-- 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
------------------------------------------------------------------------------
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment