mirror of
https://github.com/mrdomino/hsnock.git
synced 2024-09-11 13:57:42 +03:00
More applicative
This commit is contained in:
parent
a17eefc8a0
commit
c91a108699
21
test.hs
21
test.hs
@ -1,4 +1,4 @@
|
|||||||
import Control.Monad
|
import Control.Applicative
|
||||||
import Nock5K.Parse
|
import Nock5K.Parse
|
||||||
import Nock5K.Spec
|
import Nock5K.Spec
|
||||||
import Test.QuickCheck
|
import Test.QuickCheck
|
||||||
@ -10,22 +10,19 @@ main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests
|
|||||||
instance Arbitrary Noun where
|
instance Arbitrary Noun where
|
||||||
arbitrary = do coin <- arbitrary
|
arbitrary = do coin <- arbitrary
|
||||||
if coin
|
if coin
|
||||||
then liftM (Atom . abs) arbitrary
|
then (Atom . abs) <$> arbitrary
|
||||||
else do a <- arbitrary
|
else (:-) <$> arbitrary <*> arbitrary
|
||||||
b <- arbitrary
|
|
||||||
return $ a :- b
|
|
||||||
|
|
||||||
prop_parse_show n = n == ps n
|
parsenoun n = case parse noun "" n of
|
||||||
where ps n = case parse noun "" (show n) of
|
Left e -> error "parse"
|
||||||
Left e -> error "parse"
|
Right n -> n
|
||||||
Right n -> n
|
|
||||||
|
prop_parse_show n = n == (parsenoun . show) n
|
||||||
|
|
||||||
prop_dec a' = nock (Atom (a + 1) :- dec) == Atom a
|
prop_dec a' = nock (Atom (a + 1) :- dec) == Atom a
|
||||||
where
|
where
|
||||||
ds = "[8 [1 0] 8 [1 6 [5 [0 7] 4 0 6] [0 6] 9 2 [0 2] [4 0 6] 0 7] 9 2 0 1]"
|
ds = "[8 [1 0] 8 [1 6 [5 [0 7] 4 0 6] [0 6] 9 2 [0 2] [4 0 6] 0 7] 9 2 0 1]"
|
||||||
dec = case parse noun "" ds of
|
dec = parsenoun ds
|
||||||
Left e -> error "parse"
|
|
||||||
Right n -> n
|
|
||||||
a = abs a'
|
a = abs a'
|
||||||
|
|
||||||
prop_6_is_if a' b' = nock (ifs $ Atom 0) == Atom (a + 1) && nock (ifs $ Atom 1) == Atom b
|
prop_6_is_if a' b' = nock (ifs $ Atom 0) == Atom (a + 1) && nock (ifs $ Atom 1) == Atom b
|
||||||
|
Loading…
Reference in New Issue
Block a user