@@ -12,7 +12,7 @@ main = do
12 counts <- runTestTT (TestList tests)
12 counts <- runTestTT (TestList tests)
13 if errors counts + failures counts > 0 then exitFailure else exitSuccess
13 if errors counts + failures counts > 0 then exitFailure else exitSuccess
15− tests = map (\(tutd, expected) -> TestCase $ assertTutdEqual basicDatabaseContext tutd expected) simpleRelTests ++ map (\(tutd, expected) -> TestCase $ assertTutdEqual dateExamples tutd expected) dateExampleRelTests
15+ tests = map (\(tutd, expected) -> TestCase $ assertTutdEqual basicDatabaseContext expected tutd) simpleRelTests ++ map (\(tutd, expected) -> TestCase $ assertTutdEqual dateExamples expected tutd) dateExampleRelTests
16 simpleRelTests = [("x:=true", Right relationTrue),
16 simpleRelTests = [("x:=true", Right relationTrue),
17 ("x:=false", Right relationFalse),
17 ("x:=false", Right relationFalse),
18 ("x:=true union false", Right relationTrue),
18 ("x:=true union false", Right relationTrue),
@@ -22,6 +22,7 @@ main = do
22 ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty),
22 ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty),
23 ("x:=relation{tuple{a char(\"spam\"), b int(5)}}", mkRelation simpleCAttributes (HS.fromList $ map RelationTuple [M.fromList [("a", StringAtom "spam"),("b",IntAtom 5)]])),
23 ("x:=relation{tuple{a char(\"spam\"), b int(5)}}", mkRelation simpleCAttributes (HS.fromList $ map RelationTuple [M.fromList [("a", StringAtom "spam"),("b",IntAtom 5)]])),
24 ("constraint failc true in false; x:=true", Left $ InclusionDependencyCheckError "failc"),
24 ("constraint failc true in false; x:=true", Left $ InclusionDependencyCheckError "failc"),
25+ ("x:=y; x:=true", Left $ RelVarNotDefinedError "y"),
25 ("x:=true where true", Right relationTrue),
26 ("x:=true where true", Right relationTrue),
26 ("x:=true where false", Right relationFalse),
27 ("x:=true where false", Right relationFalse),
27 ("x:=true where true or false", Right relationTrue),
28 ("x:=true where true or false", Right relationTrue),
@@ -30,7 +31,7 @@ main = do
30 ("x:=true where true and true", Right relationTrue),
31 ("x:=true where true and true", Right relationTrue),
31 ("x:=true=true", Right relationTrue),
32 ("x:=true=true", Right relationTrue),
32 ("x:=true=false", Right relationFalse),
33 ("x:=true=false", Right relationFalse),
33− ("x:=true; undefine x", Right relationTrue),
34+ ("x:=true; undefine x", Left (RelVarNotDefinedError "x")),
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)]])),
35 ("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)]])),
35 ("x:=relation{tuple{b int(5),a char(\"spam\")},tuple{b int(6),a char(\"sam\")}}; delete x where b=6", mkRelation simpleCAttributes $ HS.fromList [RelationTuple $ M.fromList [("a", StringAtom "spam"), ("b", IntAtom 5)]])
36 ("x:=relation{tuple{b int(5),a char(\"spam\")},tuple{b int(6),a char(\"sam\")}}; delete x where b=6", mkRelation simpleCAttributes $ HS.fromList [RelationTuple $ M.fromList [("a", StringAtom "spam"), ("b", IntAtom 5)]])
@@ -45,12 +46,10 @@ main = do
45 ("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)
46 ("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)
48−testSimple1 = TestCase $ assertTutdEqual basicDatabaseContext "true" (Right relationTrue)
50−assertTutdEqual databaseContext tutd expected = assertEqual tutd interpreted expected
49+assertTutdEqual databaseContext expected tutd = assertEqual tutd expected interpreted
52 interpreted = case interpret databaseContext tutd of
51 interpreted = case interpret databaseContext tutd of
53 (Just err, _) -> Left err
52 (Just err, _) -> Left err
54 (Nothing, context) -> case M.lookup "x" (relationVariables context) of
53 (Nothing, context) -> case M.lookup "x" (relationVariables context) of
55 Nothing -> Left $ RelVarNotDefinedError "x"
54 Nothing -> Left $ RelVarNotDefinedError "x"
56− Just rel -> Right rel
55+ Just rel -> Right rel