diff options
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs index d772fe0..f07b5a2 100644 --- a/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs @@ -2,8 +2,11 @@ module Minilang.Lambda.EvalSpec (spec) where import Control.Concurrent (threadDelay) import Control.Concurrent.Async (race_) -import Minilang.Lambda.Eval (Term (..), Value, eval, normalise) -import Test.Hspec (Spec, describe, it, pending, shouldBe) +import Minilang.Lambda.Eval (Term (..), Value (..), eval, normalise) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.QuickCheck (prop) +import Data.Text (pack) +import Test.QuickCheck (NonEmptyList (..), arbitrary, forAll, (===)) spec :: Spec spec = do @@ -65,6 +68,25 @@ spec = do normalise (App (App add' one) one) `shouldBe` two + describe "integer literals" $ do + -- An integer literal is already a normal form: normalise must return it unchanged. + prop "any integer literal normalises to itself" $ \n -> + normalise (Num n) === Num (n :: Int) + + -- eval on a bare Num must always produce the VNum value form, never a closure + -- or neutral, regardless of the integer's sign or magnitude. + prop "eval of any integer literal produces VNum" $ \n -> + eval [] (Num n) === VNum (n :: Int) + + -- A number is not a function. Applying it to any argument must leave a stuck + -- neutral application: App (Num n) (normalise arg). We test this with free + -- variables as arguments, which are themselves already in normal form. + prop "an integer in function position produces a stuck application" $ + forAll arbitrary $ \n -> + forAll (getNonEmpty <$> arbitrary) $ \x -> + normalise (App (Num n) (Var (pack x))) + === App (Num (n :: Int)) (Var (pack x)) + -- describe "call-by-name eval" $ do -- it "evaluates 'x' as itself" $ do -- normalise' (Var "x") `shouldBe` Var "x" |
