More applicative

This commit is contained in:
Steven Dee 2013-10-20 20:53:19 -04:00
parent a17eefc8a0
commit c91a108699

21
test.hs
View File

@ -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
Left e -> error "parse"
Right n -> n
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