Expansion of testing suite to cover incl. library
Expands the testing suite to verify behavior of provided library functions. Updates the README further for clarification on important concepts.
This commit is contained in:
130
test/Spec.hs
130
test/Spec.hs
@ -4,6 +4,7 @@ import Eval
|
||||
import Lexer
|
||||
import Library
|
||||
import Parser
|
||||
import REPL
|
||||
import Research
|
||||
import Control.Exception (evaluate, try, SomeException)
|
||||
import Test.Tasty
|
||||
@ -27,6 +28,7 @@ tests = testGroup "Tricu Tests"
|
||||
, integrationTests
|
||||
, evaluationTests
|
||||
, lambdaEvalTests
|
||||
, libraryTests
|
||||
, propertyTests
|
||||
]
|
||||
|
||||
@ -67,12 +69,12 @@ lexerTests = testGroup "Lexer Tests"
|
||||
|
||||
parserTests :: TestTree
|
||||
parserTests = testGroup "Parser Tests"
|
||||
[ --testCase "Error when parsing incomplete definitions" $ do
|
||||
-- let input = lexTricu "x = "
|
||||
-- case (runParser parseExpression "" input) of
|
||||
-- Left _ -> return ()
|
||||
-- Right _ -> assertFailure "Expected failure on invalid input"
|
||||
testCase "Error when assigning a value to T" $ do
|
||||
[-- testCase "Error when parsing incomplete definitions" $ do
|
||||
-- let input = lexTricu "x = "
|
||||
-- case (runParser parseExpression "" input) of
|
||||
-- Left _ -> return ()
|
||||
-- Right _ -> assertFailure "Expected failure on invalid input"
|
||||
testCase "Error when assigning a value to T" $ do
|
||||
let input = lexTricu "t = x"
|
||||
case (runParser parseExpression "" input) of
|
||||
Left _ -> return ()
|
||||
@ -222,30 +224,6 @@ evaluationTests = testGroup "Evaluation Tests"
|
||||
let input = "x = (\\a : a)\nx " ++ not
|
||||
env = evalTricu Map.empty (parseTricu input)
|
||||
result env @?= Fork (Fork (Stem Leaf) (Fork Leaf Leaf)) Leaf
|
||||
, testCase "Constant function matches" $ do
|
||||
let input = "k = (\\a b : a)\nk (t t) t"
|
||||
env = evalTricu Map.empty (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
, testCase "Boolean AND_ TF" $ do
|
||||
let input = "and (t t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "Boolean AND_ FT" $ do
|
||||
let input = "and (t) (t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "Boolean AND_ FF" $ do
|
||||
let input = "and (t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "Boolean AND_ TT" $ do
|
||||
let input = "and (t t) (t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
, testCase "Verifying Equality" $ do
|
||||
let input = "equal (t t t) (t t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
]
|
||||
|
||||
lambdaEvalTests :: TestTree
|
||||
@ -309,6 +287,98 @@ lambdaEvalTests = testGroup "Lambda Evaluation Tests"
|
||||
runTricu input @?= "Fork Leaf (Fork (Stem Leaf) Leaf)"
|
||||
]
|
||||
|
||||
libraryTests :: TestTree
|
||||
libraryTests = testGroup "Library Tests"
|
||||
[ testCase "K combinator 1" $ do
|
||||
let input = "k (t) (t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "K combinator 2" $ do
|
||||
let input = "k (t t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
, testCase "K combinator 3" $ do
|
||||
let input = "k (t t t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Fork Leaf Leaf
|
||||
, testCase "S combinator" $ do
|
||||
let input = "s (t) (t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Fork Leaf (Stem Leaf)
|
||||
, testCase "SKK == I" $ do -- Tests for fully expanded I form
|
||||
let input = "s k k"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Fork (Stem (Stem Leaf)) (Stem Leaf)
|
||||
, testCase "I combinator" $ do
|
||||
let input = "i not"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Fork (Fork (Stem Leaf) (Fork Leaf Leaf)) (Fork Leaf (Fork Leaf Leaf))
|
||||
, testCase "Triage test Leaf" $ do
|
||||
let input = "test t"
|
||||
env = decodeResult $ result $ evalTricu library (parseTricu input)
|
||||
env @?= "Leaf"
|
||||
, testCase "Triage test (Stem Leaf)" $ do
|
||||
let input = "test (t t)"
|
||||
env = decodeResult $ result $ evalTricu library (parseTricu input)
|
||||
env @?= "Stem"
|
||||
, testCase "Triage test (Fork Leaf Leaf)" $ do
|
||||
let input = "test (t t t)"
|
||||
env = decodeResult $ result $ evalTricu library (parseTricu input)
|
||||
env @?= "Fork"
|
||||
, testCase "Boolean NOT: true" $ do
|
||||
let input = "not true"
|
||||
env = result $ evalTricu library (parseTricu input)
|
||||
env @?= Leaf
|
||||
, testCase "Boolean NOT: false" $ do
|
||||
let input = "not false"
|
||||
env = result $ evalTricu library (parseTricu input)
|
||||
env @?= Stem Leaf
|
||||
, testCase "Boolean AND TF" $ do
|
||||
let input = "and (t t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "Boolean AND FT" $ do
|
||||
let input = "and (t) (t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "Boolean AND FF" $ do
|
||||
let input = "and (t) (t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "Boolean AND TT" $ do
|
||||
let input = "and (t t) (t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
, testCase "List head" $ do
|
||||
let input = "head [(t) (t t) (t t t)]"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Leaf
|
||||
, testCase "List tail" $ do
|
||||
let input = "head (tail (tail [(t) (t t) (t t t)]))"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Fork Leaf Leaf
|
||||
, testCase "List map" $ do
|
||||
let input = "head (tail (map (\\a : (t t t)) [(t) (t) (t)]))"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Fork Leaf Leaf
|
||||
, testCase "Empty list check" $ do
|
||||
let input = "emptyList []"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
, testCase "Non-empty list check" $ do
|
||||
let input = "not (emptyList [(1) (2) (3)])"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
, testCase "Concatenate strings" $ do
|
||||
let input = "listConcat \"Hello, \" \"world!\""
|
||||
env = decodeResult $ result $ evalTricu library (parseTricu input)
|
||||
env @?= "Hello, world!"
|
||||
, testCase "Verifying Equality" $ do
|
||||
let input = "equal (t t t) (t t t)"
|
||||
env = evalTricu library (parseTricu input)
|
||||
result env @?= Stem Leaf
|
||||
]
|
||||
|
||||
propertyTests :: TestTree
|
||||
propertyTests = testGroup "Property Tests"
|
||||
[ testProperty "Lexing and parsing round-trip" $ \input ->
|
||||
|
Reference in New Issue
Block a user