mirror of
https://github.com/mrdomino/hsnock.git
synced 2024-08-16 09:10:34 +03:00
More applicative
This commit is contained in:
parent
a17eefc8a0
commit
c91a108699
17
test.hs
17
test.hs
@ -1,4 +1,4 @@
|
||||
import Control.Monad
|
||||
import Control.Applicative
|
||||
import Nock5K.Parse
|
||||
import Nock5K.Spec
|
||||
import Test.QuickCheck
|
||||
@ -10,22 +10,19 @@ main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests
|
||||
instance Arbitrary Noun where
|
||||
arbitrary = do coin <- arbitrary
|
||||
if coin
|
||||
then liftM (Atom . abs) arbitrary
|
||||
else do a <- arbitrary
|
||||
b <- arbitrary
|
||||
return $ a :- b
|
||||
then (Atom . abs) <$> arbitrary
|
||||
else (:-) <$> arbitrary <*> arbitrary
|
||||
|
||||
prop_parse_show n = n == ps n
|
||||
where ps n = case parse noun "" (show n) of
|
||||
parsenoun n = case parse noun "" n of
|
||||
Left e -> error "parse"
|
||||
Right n -> n
|
||||
|
||||
prop_parse_show n = n == (parsenoun . show) n
|
||||
|
||||
prop_dec a' = nock (Atom (a + 1) :- dec) == Atom a
|
||||
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]"
|
||||
dec = case parse noun "" ds of
|
||||
Left e -> error "parse"
|
||||
Right n -> n
|
||||
dec = parsenoun ds
|
||||
a = abs a'
|
||||
|
||||
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