on master help sign in
add inclusion dependency tutd test and fix constraint checking function
commitf0a3d88f93c6087da9cbe0303c03692c15aba51e authorAgentM <agentm@themactionfaction.com> dateThu 4 Dec 2014, 10:22 (12 years ago) parentfbfd20c
2 files changed+16−10
RelationExpr.hs+13−9 TutorialDInterpreterTest.hs+3−1
RelationExpr.hs+13−9
@@ -209,25 +209,29 @@ checkConstraints context = case failures of
209209 deps = inclusionDependencies context
210210 eval expr = runState (evalRelationalExpr expr) context
211211 checkIncDep (InclusionDependency depName subsetExpr supersetExpr) = case evaldSub of
212− Left err -> Just err
213− Right relSub -> case evaldSub of
214− Left err -> Just err
215− Right relSuper -> case union relSub relSuper of
212+ (Left err, _) -> Just err
213+ (Right relSub, _) -> case evaldSuper of
214+ (Left err, _) -> Just err
215+ (Right relSuper, _) -> case union relSub relSuper of
216216 Left err -> Just err
217− Right resultRel -> case resultRel of
217+ Right resultRel -> case resultRel == relSuper of
218218 False -> Just $ InclusionDependencyCheckError depName
219219 True -> Nothing
220220 where
221221 evaldSub = eval subsetExpr
222222 evaldSuper = eval supersetExpr
223223
224+{-
224225checkConstraint :: InclusionDependency -> DatabaseState (Maybe RelationalError)
225226checkConstraint (InclusionDependency name subDep superDep) = do
226− evalSub <- evalRelExpr subDep
227− evalSuper <- evalRelExpr superDep
227+ evalSub <- evalRelationalExpr subDep
228+ evalSuper <- evalRelationalExpr superDep
229+ case evalSub of
230+ Left err -> Just err
231+ Right relSub
228232 result <- liftM2 union evalSub evalSuper
229−
230−
233+ return $ Nothing
234+-}
231235
232236
233237
TutorialDInterpreterTest.hs+3−1
@@ -2,6 +2,7 @@ import TutorialDInterpreter
22import Test.HUnit
33import RelationExpr
44import Relation
5+import RelationalError
56import RelationType
67import qualified Data.HashSet as HS
78import qualified Data.Map as M
@@ -18,7 +19,8 @@ main = do
1819 ("x:=true; x:=false", Right relationFalse),
1920 ("x:=relation{a int}", mkRelation simpleAAttributes HS.empty),
2021 ("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+ ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty),
23+ ("constraint failc true in false; x:=true", Left $ InclusionDependencyCheckError "failc")
2224 ]
2325 simpleAAttributes = M.fromList [("a", Attribute "a" IntAtomType)]
2426 simpleBAttributes = M.fromList [("d", Attribute "d" IntAtomType)]