diff --git a/Language/Nock5K/Spec.hs b/Language/Nock5K/Spec.hs index 1102368..9d1bd0a 100644 --- a/Language/Nock5K/Spec.hs +++ b/Language/Nock5K/Spec.hs @@ -57,14 +57,12 @@ tis a = Left "=a" \/[(a + a + 1) b] \/[3 \/[a b]] \/a \/a @-} -fas (Atom 1 :- a) = return a -fas (Atom 2 :- a :- b) = return a -fas (Atom 3 :- a :- b) = return b -fas (Atom a :- b) | a > 2 && a `mod` 2 == 0 = do x <- fas $ Atom (a `div` 2) :- b - fas $ Atom 2 :- x -fas (Atom a :- b) | a > 3 && a `mod` 2 == 1 = do x <- fas $ Atom (a `div` 2) :- b - fas $ Atom 3 :- x -fas a = Left "/a" +fas (Atom 1 :- a) = return a +fas (Atom 2 :- a :- b) = return a +fas (Atom 3 :- a :- b) = return b +fas (Atom a :- b) | a > 3 = do x <- fas $ Atom (a `div` 2) :- b + fas $ Atom (2 + (a `mod` 2)) :- x +fas a = Left "/a" {-|@ \*[a [b c] d] [\*[a b c] \*[a d]] diff --git a/test.hs b/test.hs index 9dacdea..0bf906a 100644 --- a/test.hs +++ b/test.hs @@ -34,6 +34,12 @@ prop_6_is_if a' b = nock (ifs $ Atom 0) == Right (Atom (a + 1)) && nock (ifs $ A ifs c = Atom a :- Atom 6 :- (Atom 1 :- c) :- (Atom 4 :- Atom 0 :- Atom 1) :- (Atom 1 :- b) a = abs a' +prop_fas_induct a' b = fas (a + a) b == fasmn 2 a b && fas (a + a + 1) b == fasmn 3 a b + where fas c d = nock $ d :- Atom c + fasmn m n c = do x <- fas n c + fas m x + a = abs a' + test_hint_crash = assert $ nock bad == Left "/a" where bad = pn "[42 10 [0 0 2] 0 1]" @@ -43,6 +49,7 @@ test_eval_strict = assert $ nock bad == Left "/a" tests = [ testProperty "parse.show" prop_parse_show , testProperty "decrement" prop_dec , testProperty "6_is_if" prop_6_is_if + , testProperty "fas_induct" prop_fas_induct , testCase "10_hint_crash" test_hint_crash , testCase "eval_strict" test_eval_strict ]