1import TutorialDInterpreter
7import qualified Data.HashSet as HS
8import qualified Data.Map as M
14 counts <- runTestTT (TestList tests)
15 if errors counts + failures counts > 0 then exitFailure else exitSuccess
17 tests = map (\(tutd, expected) -> TestCase $ assertTutdEqual basicDatabaseContext tutd expected) simpleRelTests ++ map (\(tutd, expected) -> TestCase $ assertTutdEqual dateExamples tutd expected) dateExampleRelTests
18 simpleRelTests = [("x:=true", Right relationTrue),
19 ("x:=false", Right relationFalse),
20 ("x:=true union false", Right relationTrue),
21 ("x:=true; x:=false", Right relationFalse),
22 ("x:=relation{a int}", mkRelation simpleAAttributes HS.empty),
23 ("x:=relation{c int} rename {c as d}", mkRelation simpleBAttributes HS.empty),
24 ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty),
25 ("constraint failc true in false; x:=true", Left $ InclusionDependencyCheckError "failc"),
26 ("x:=true where true", Right relationTrue),
27 ("x:=true where false", Right relationFalse),
28 ("x:=true where true or false", Right relationTrue),
29 ("x:=true where false or false", Right relationFalse),
30 ("x:=true where true and false", Right relationFalse),
31 ("x:=true where true and true", Right relationTrue)
33 simpleAAttributes = M.fromList [("a", Attribute "a" IntAtomType)]
34 simpleBAttributes = M.fromList [("d", Attribute "d" IntAtomType)]
35 simpleProjectionAttributes = M.fromList [("c", Attribute "c" IntAtomType)]
36 dateExampleRelTests = [("x:=S where true", Right s),
37 ("x:=S where CITY = \"London\"", restrict (\(RelationTuple tupMap) -> tupMap M.! "CITY" == StringAtom "London") s),
38 ("x:=S where false", Right $ Relation (attributes s) HS.empty),
39 ("a:=S; update a (STATUS:=50); x:=a{STATUS}", mkRelation (M.fromList [("STATUS", Attribute "STATUS" IntAtomType)]) (HS.fromList [RelationTuple $ M.fromList [("STATUS", IntAtom 50)]])),
40 ("x:=S; update x where SNAME=\"Blake\" (CITY:=\"Boston\")", relMap (\(RelationTuple tupMap) -> RelationTuple $ if (traceShowId tupMap) M.! "SNAME" == StringAtom "Blake" then M.insert "CITY" (StringAtom "Boston") tupMap else tupMap) s)
43testSimple1 = TestCase $ assertTutdEqual basicDatabaseContext "true" (Right relationTrue)
45assertTutdEqual databaseContext tutd expected = assertEqual tutd interpreted expected
47 interpreted = case interpret databaseContext tutd of
48 (Just err, _) -> Left err
49 (Nothing, context) -> Right $ (relationVariables context) M.! "x"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list