Skip to content

Commit 7e67239

Browse files
committed
add resize tests
1 parent 40b8167 commit 7e67239

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/Main.purs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import Control.Monad.Eff (Eff)
66
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
77
import Control.Monad.Eff.Exception (try, EXCEPTION)
88
import Control.Monad.Eff.Random (RANDOM)
9+
import Control.Monad.Gen.Class as MGen
910
import Data.Array.Partial (head)
1011
import Data.Either (isLeft)
1112
import Data.Foldable (sum)
1213
import Data.Generic.Rep (class Generic)
1314
import Data.Generic.Rep.Show (genericShow)
15+
import Data.Tuple (fst)
1416
import Partial.Unsafe (unsafePartial)
1517
import Test.Assert (assert, ASSERT)
1618
import Test.QuickCheck (class Testable, quickCheck, (/=?), (<=?), (<?), (==?), (>=?), (>?))
1719
import Test.QuickCheck.Arbitrary (arbitrary, genericArbitrary, class Arbitrary)
18-
import Test.QuickCheck.Gen (Gen, vectorOf, randomSample')
20+
import Test.QuickCheck.Gen (Gen, vectorOf, randomSample', resize, Size, runGen, sized)
21+
import Test.QuickCheck.LCG (mkSeed)
1922

2023
data Foo a = F0 a | F1 a a | F2 { foo :: a, bar :: Array a }
2124
derive instance genericFoo :: Generic (Foo a) _
@@ -31,8 +34,26 @@ quickCheckFail
3134
quickCheckFail = assert <=< map isLeft <<< try <<< quickCheck
3235

3336

37+
testResize :: (forall a. Size -> Gen a -> Gen a) -> Boolean
38+
testResize resize' =
39+
let
40+
initialSize = 2
41+
gen = do
42+
s1 <- sized pure
43+
s2 <- resize' 1 (sized pure)
44+
s3 <- sized pure
45+
pure $ [ s1, s2, s3 ] == [ initialSize, 1, initialSize ]
46+
in
47+
fst $ runGen gen { newSeed: mkSeed 0, size: initialSize }
48+
49+
3450
main :: Eff (assert :: ASSERT, console :: CONSOLE, random :: RANDOM, exception :: EXCEPTION) Unit
3551
main = do
52+
log "MonadGen.resize"
53+
assert (testResize (MGen.resize <<< const))
54+
log "Gen.resize"
55+
assert (testResize (resize))
56+
3657
log "Try with some little Gens first"
3758
logShow =<< go 10
3859
logShow =<< go 100

0 commit comments

Comments
 (0)