0.1.0 base collection of features
Implemented evaluation of tree calculus terms alongside referentially transparent variable identifiers. Implemented evaluation of defined functions into tree calculus.
This commit is contained in:
		
							
								
								
									
										43
									
								
								test/Spec.hs
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								test/Spec.hs
									
									
									
									
									
								
							| @ -5,6 +5,7 @@ import Lexer | ||||
| import Parser | ||||
| import Research | ||||
|  | ||||
| import qualified Data.Map as Map | ||||
| import Test.Tasty | ||||
| import Test.Tasty.HUnit | ||||
| import Test.Tasty.QuickCheck | ||||
| @ -77,36 +78,64 @@ evaluationTests = testGroup "Evaluation Tests" | ||||
|   [ testCase "Evaluate single Leaf" $ do | ||||
|       let input = "t" | ||||
|       let ast = parseSapling input | ||||
|       evalSapling ast @?= Leaf | ||||
|       (result $ evalSapling Map.empty ast) @?= Leaf | ||||
|  | ||||
|   , testCase "Evaluate single Stem" $ do | ||||
|       let input = "t t" | ||||
|       let ast = parseSapling input | ||||
|       evalSapling ast @?= Stem Leaf | ||||
|       (result $ evalSapling Map.empty ast) @?= Stem Leaf | ||||
|  | ||||
|   , testCase "Evaluate single Fork" $ do | ||||
|       let input = "t t t" | ||||
|       let ast = parseSapling input | ||||
|       evalSapling ast @?= Fork Leaf Leaf | ||||
|       (result $ evalSapling Map.empty ast) @?= Fork Leaf Leaf | ||||
|  | ||||
|   , testCase "Evaluate nested Fork and Stem" $ do | ||||
|       let input = "t (t t) t" | ||||
|       let ast = parseSapling input | ||||
|       evalSapling ast @?= Fork (Stem Leaf) Leaf | ||||
|       (result $ evalSapling Map.empty ast) @?= Fork (Stem Leaf) Leaf | ||||
|  | ||||
|   , testCase "Evaluate `not` function" $ do | ||||
|       let input = "t (t (t t) (t t t)) t)" | ||||
|       let ast = parseSapling input | ||||
|       evalSapling ast @?= Fork (Fork (Stem Leaf) (Fork Leaf Leaf)) Leaf | ||||
|       (result $ evalSapling Map.empty ast) @?=  | ||||
|         Fork (Fork (Stem Leaf) (Fork Leaf Leaf)) Leaf | ||||
|  | ||||
|   , testCase "Environment updates with definitions" $ do | ||||
|       let input = "x = t\ny = x" | ||||
|       let env = evalMulti Map.empty (parseMulti input) | ||||
|       Map.lookup "x" env @?= Just Leaf | ||||
|       Map.lookup "y" env @?= Just Leaf | ||||
|  | ||||
|   , testCase "Variable substitution" $ do | ||||
|       let input = "x = t t\ny = t x\ny" | ||||
|       let env = evalMulti Map.empty (parseMulti input) | ||||
|       (result env) @?= Stem (Stem Leaf) | ||||
|  | ||||
|   , testCase "Multiline input evaluation" $ do | ||||
|       let input = "x = t\ny = t t\nx" | ||||
|       let env = evalMulti Map.empty (parseMulti input) | ||||
|       (result env) @?= Leaf | ||||
|  | ||||
|   , testCase "Evaluate string literal" $ do | ||||
|       let input = "\"hello\"" | ||||
|       let ast = parseSapling input | ||||
|       (result $ evalSapling Map.empty ast) @?= toString "hello" | ||||
|  | ||||
|   , testCase "Evaluate list literal" $ do | ||||
|       let input = "[t (t t)]" | ||||
|       let ast = parseSapling input | ||||
|       (result $ evalSapling Map.empty ast) @?= toList [Leaf, Stem Leaf] | ||||
|  | ||||
|   ] | ||||
|  | ||||
| propertyTests :: TestTree | ||||
| propertyTests = testGroup "Property Tests" | ||||
|   [ testProperty "Lexing and parsing round-trip" $ \input -> | ||||
|       case runParser saplingLexer "" input of | ||||
|         Left _ -> property True  -- Ignore invalid lexes | ||||
|         Left _ -> property True  | ||||
|         Right tokens -> case runParser parseExpression "" tokens of | ||||
|           Left _ -> property True  -- Ignore invalid parses | ||||
|           Left _ -> property True | ||||
|           Right ast -> parseSapling input === ast | ||||
|   ] | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 James Eversole
						James Eversole