@@ -2,67 +2,15 @@ module Test.Main where
2
2
3
3
import Prelude
4
4
5
- import Test.Assert ( ASSERT , assert )
6
- import Partial.Unsafe ( unsafeCrashWith )
5
+ import Test.Frequency as Frequency
6
+ import Test.Assert ( ASSERT )
7
7
import Control.Monad.Eff (Eff )
8
8
import Control.Monad.Eff.Console (CONSOLE , log )
9
- import Control.Monad.Gen (class MonadGen , frequency )
10
- import Data.NonEmpty ((:|), NonEmpty (..))
11
- import Data.Traversable (sequence )
12
- import Data.Array (replicate , group' , length )
13
- import Data.Tuple (Tuple (..))
14
- import Data.Newtype (unwrap )
15
- import Math (remainder )
16
- import Control.Monad.State (State , class MonadState , get , put , evalStateT )
17
9
18
- type TestEffects = (console :: CONSOLE , assert :: ASSERT )
19
- type Tests = Eff TestEffects Unit
20
-
21
- newtype TestGen a = TestGen (State Number a )
22
- derive newtype instance testGenFunctor :: Functor TestGen
23
- derive newtype instance testGenApply :: Apply TestGen
24
- derive newtype instance testGenBind :: Bind TestGen
25
- derive newtype instance testGenApplicative :: Applicative TestGen
26
- derive newtype instance testGenMonad :: Monad TestGen
27
- derive newtype instance testGenMonadState :: MonadState Number TestGen
28
-
29
- instance testGenMonadGen :: MonadGen TestGen where
30
- sized _ = unsafeCrashWith " sized should not be called"
31
- resize _ _ = unsafeCrashWith " resize should not be called"
32
- chooseBool = pure unit >>= \_ -> unsafeCrashWith " chooseBool should not be called"
33
- chooseFloat s e = do
34
- c <- get
35
- put (c + 1.0 )
36
- pure ((s + c) `remainder` e)
37
- chooseInt _ _ = unsafeCrashWith " chooseFloat should not be called"
38
-
39
- runTestGen :: TestGen ~> State Number
40
- runTestGen (TestGen x) = x
10
+ type Tests = Eff (console :: CONSOLE , assert :: ASSERT ) Unit
41
11
42
12
main :: Tests
43
13
main = do
44
14
log " check frequency"
45
- let
46
- abcGen :: TestGen String
47
- abcGen =
48
- frequency $
49
- ( Tuple 10.0 $ pure " A" ) :|
50
- [ Tuple 20.0 $ pure " B"
51
- , Tuple 0.0 $ pure " Z"
52
- , Tuple 30.0 $ pure " C"
53
- , Tuple 40.0 $ pure " D"
54
- , Tuple 50.0 $ pure " E"
55
- , Tuple 50.0 $ pure " F"
56
- ]
57
- abcArrGen = sequence $ replicate 200 abcGen
58
- abcArr = runTestGen abcArrGen `evalStateT` 0.0 # unwrap
59
- actual = group' abcArr <#> \(NonEmpty x xs) -> Tuple (length xs + 1 ) x
60
- expected =
61
- [ (Tuple 10 " A" )
62
- , (Tuple 20 " B" )
63
- , (Tuple 30 " C" )
64
- , (Tuple 40 " D" )
65
- , (Tuple 50 " E" )
66
- , (Tuple 50 " F" )
67
- ]
68
- assert (expected == actual)
15
+ Frequency .check
16
+
0 commit comments