on master help sign in
add a mkRelation test
2c7f52aAgentM
RelationTest.hs+10−1
@@ -2,6 +2,7 @@ import Test.HUnit
2import RelationType
2import RelationType
3import Relation
3import Relation
4import RelationTuple
4import RelationTuple
5+import RelationTupleSet
5import qualified Data.Set as S
6import qualified Data.Set as S
6import qualified Data.Map as M
7import qualified Data.Map as M
7import qualified Data.HashSet as HS
8import qualified Data.HashSet as HS
@@ -49,6 +50,7 @@ validateAttrTypesMatchTupleAttrTypes rel@(Relation _ tupMapSet)
49
50
50simpleRel = case mkRelation attrs tupleSet of
51simpleRel = case mkRelation attrs tupleSet of
51 Right rel -> rel
52 Right rel -> rel
53+ Left err -> undefined
52 where
54 where
53 attrs = M.fromList [("a", Attribute "a" StringAtomType), ("b", Attribute "b" StringAtomType)]
55 attrs = M.fromList [("a", Attribute "a" StringAtomType), ("b", Attribute "b" StringAtomType)]
54 tupleSet = HS.fromList $ mkRelationTuples attrs [
56 tupleSet = HS.fromList $ mkRelationTuples attrs [
@@ -62,4 +64,11 @@ testRename1 = TestCase $ assertEqual "attribute invalid" (rename "a" "b" relatio
62testRename2 :: Test
64testRename2 :: Test
63testRename2 = TestCase $ assertEqual "attribute in use" (rename "b" "a" simpleRel) (Left $ RelationalError 1 "Attribute \"a\" already in use.")
65testRename2 = TestCase $ assertEqual "attribute in use" (rename "b" "a" simpleRel) (Left $ RelationalError 1 "Attribute \"a\" already in use.")
64
66
65−
67+--mkRelation tests
68+--test tupleset key mismatch failure
69+testMkRelation1 :: Test
70+testMkRelation1 = TestCase $ assertEqual "key mismatch" (mkRelation testAttrs testTupSet) (Left $ RelationalError 1 "Tuple values not of the same type for same keys")
71+ where
72+ testAttrs = M.singleton "a" (Attribute "a" StringAtomType)
73+ testTupSet = HS.fromList [(RelationTuple (M.singleton "a" $ StringAtom "v")),
74+ RelationTuple (M.singleton "a" $ IntAtom 2)]
RelationTupleSet.hs+5−3
@@ -4,17 +4,19 @@ import qualified Data.Map as M
4import qualified Data.Set as S
4import qualified Data.Set as S
5import qualified Data.List as L
5import qualified Data.List as L
6import qualified Data.HashSet as HS
6import qualified Data.HashSet as HS
7+import Debug.Trace
7
8
8emptyTupleSet = HS.empty
9emptyTupleSet = HS.empty
9emptyAttributeSet = M.empty
10emptyAttributeSet = M.empty
10
11
11--ensure that all maps have the same keys and key count
12--ensure that all maps have the same keys and key count
13+
12−verifyRelationTuple :: RelationTupleSet -> (Bool,String)
14+verifyRelationTupleSet :: RelationTupleSet -> (Bool,String)
13−verifyRelationTuple tupleSet = if HS.size failedTupleSet > 0
15+verifyRelationTupleSet tupleSet = if HS.size failedTupleSet > 0
14 then (False,"Tuple count or key mismatch: " ++ show failedTupleSet)
16 then (False,"Tuple count or key mismatch: " ++ show failedTupleSet)
15 else (True, "")
17 else (True, "")
16 where
18 where
17 allKeys = HS.foldr allKeysFolder S.empty tupleSet
19 allKeys = HS.foldr allKeysFolder S.empty tupleSet
18 allKeysFolder (RelationTuple m) = (S.union . M.keysSet) m
20 allKeysFolder (RelationTuple m) = (S.union . M.keysSet) m
19− failedTupleSet = HS.filter (\(RelationTuple m) -> (M.keysSet m) == allKeys) tupleSet
21+ failedTupleSet = HS.filter (\(RelationTuple m) -> (M.keysSet m) /= allKeys) tupleSet
20
22