on af03e83 help sign in
project-m36/TutorialDInterpreterTest.hs
34 lines 1.6 kB history raw
1import TutorialDInterpreter
2import Test.HUnit
3import RelationExpr
4import Relation
5import RelationType
6import qualified Data.HashSet as HS
7import qualified Data.Map as M
8import System.Exit
10main = do
11 counts <- runTestTT (TestList tests)
12 if errors counts + failures counts > 0 then exitFailure else exitSuccess
13 where
14 tests = map (\(tutd, expected) -> TestCase $ assertTutdEqual basicDatabaseContext tutd expected) simpleRelTests
15 simpleRelTests = [("x:=true", Right relationTrue),
16 ("x:=false", Right relationFalse),
17 ("x:=true union false", Right relationTrue),
18 ("x:=true; x:=false", Right relationFalse),
19 ("x:=relation{a int}", mkRelation simpleAAttributes HS.empty),
20 ("x:=relation{c int} rename {c as d}", mkRelation simpleBAttributes HS.empty),
21 ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty)
22 ]
23 simpleAAttributes = M.fromList [("a", Attribute "a" IntAtomType)]
24 simpleBAttributes = M.fromList [("d", Attribute "d" IntAtomType)]
25 simpleProjectionAttributes = M.fromList [("c", Attribute "c" IntAtomType)]
28testSimple1 = TestCase $ assertTutdEqual basicDatabaseContext "true" (Right relationTrue)
30assertTutdEqual databaseContext tutd expected = assertEqual tutd interpreted expected
31 where
32 interpreted = case interpret databaseContext tutd of
33 (Just err, _) -> Left err
34 (Nothing, context) -> Right $ (relationVariables context) M.! "x"