1import TutorialDInterpreter
7import qualified Data.HashSet as HS
8import qualified Data.Map as M
10import Data.UUID.V4 (nextRandom)
13 counts <- runTestTT (TestList tests)
14 if errors counts + failures counts > 0 then exitFailure else exitSuccess
16 tests = map (\(tutd, expected) -> TestCase $ assertTutdEqual basicDatabaseContext tutd expected) simpleRelTests ++ map (\(tutd, expected) -> TestCase $ assertTutdEqual dateExamples tutd expected) dateExampleRelTests
17 simpleRelTests = [("x:=true", Right relationTrue),
18 ("x:=false", Right relationFalse),
19 ("x:=true union false", Right relationTrue),
20 ("x:=true; x:=false", Right relationFalse),
21 ("x:=relation{a int}", mkRelation simpleAAttributes HS.empty),
22 ("x:=relation{c int} rename {c as d}", mkRelation simpleBAttributes HS.empty),
23 ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty),
24 ("x:=relation{tuple{a char(\"spam\"), b int(5)}}", mkRelation simpleCAttributes (HS.fromList $ map RelationTuple [M.fromList [("a", StringAtom "spam"),("b",IntAtom 5)]])),
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),
32 ("x:=true=true", Right relationTrue),
33 ("x:=true=false", Right relationFalse),
34 ("x:=relation {b int, a char}; insert x relation{tuple{b int(5), a char(\"spam\")}}", mkRelation simpleCAttributes (HS.fromList [RelationTuple $ M.fromList [("a", StringAtom "spam"), ("b", IntAtom 5)]]))
36 simpleAAttributes = M.fromList [("a", Attribute "a" IntAtomType)]
37 simpleBAttributes = M.fromList [("d", Attribute "d" IntAtomType)]
38 simpleCAttributes = M.fromList [("a", Attribute "a" StringAtomType), ("b", Attribute "b" IntAtomType)]
39 simpleProjectionAttributes = M.fromList [("c", Attribute "c" IntAtomType)]
40 dateExampleRelTests = [("x:=S where true", Right s),
41 ("x:=S where CITY = \"London\"", restrict (\(RelationTuple tupMap) -> tupMap M.! "CITY" == StringAtom "London") s),
42 ("x:=S where false", Right $ Relation (attributes s) HS.empty),
43 ("a:=S; update a (STATUS:=50); x:=a{STATUS}", mkRelation (M.fromList [("STATUS", Attribute "STATUS" IntAtomType)]) (HS.fromList [RelationTuple $ M.fromList [("STATUS", IntAtom 50)]])),
44 ("x:=S; update x where SNAME=\"Blake\" (CITY:=\"Boston\")", relMap (\(RelationTuple tupMap) -> RelationTuple $ if tupMap M.! "SNAME" == StringAtom "Blake" then M.insert "CITY" (StringAtom "Boston") tupMap else tupMap) s)
47testSimple1 = TestCase $ assertTutdEqual basicDatabaseContext "true" (Right relationTrue)
49assertTutdEqual databaseContext tutd expected = assertEqual tutd interpreted expected
51 interpreted = case interpret databaseContext tutd of
52 (Just err, _) -> Left err
53 (Nothing, context) -> Right $ (relationVariables context) M.! "x"
55transactionGraphTest1 = TestCase $ assertEqual "validate bootstrapped graph"
57 interpreted = interpretOps U.nextRandom
58 (discon, graph) = dateExampleGraph
60dateExamplesGraph :: IO (DisconnectedTransaction, TransactionGraph)
62 firstTransactionUUID <- U.nextRandom
63 let graph = bootstrapTransactionGraph firstTransactionUUID dateExamples
64 let discon = newDisconnectedTransaction firstTransactionUUID dateExamples
65 return (discon, graph)
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