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.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