@@ -1,12 +1,19 @@
11import Test.HUnit
22import RelationType
33import Relation
4+import RelationTuple
45import qualified Data.Set as S
56import qualified Data.Map as M
67import qualified Data.HashSet as HS
8+import System.Exit
9+import Control.Monad
710
8−testList = TestList [testRelation relationTrue, testRelation relationFalse]
9−main = runTestTT testList
11+
12+testList = TestList [testRelation relationTrue, testRelation relationFalse,
13+ testRename1, testRename2]
14+main = do
15+ counts <- runTestTT testList
16+ if errors counts + failures counts > 0 then exitFailure else exitSuccess
1017
1118testRelation :: Relation -> Test
1219testRelation rel = TestCase $ assertEqual "nope" relationValidation (Right rel)
@@ -40,4 +47,19 @@ validateAttrTypesMatchTupleAttrTypes rel@(Relation _ tupMapSet)
4047 _ -> False
4148 invalidSet = HS.filter (not . tupleTypeCheck) tupMapSet
4249
50+simpleRel = case mkRelation attrs tupleSet of
51+ Right rel -> rel
52+ where
53+ attrs = M.fromList [("a", Attribute "a" StringAtomType), ("b", Attribute "b" StringAtomType)]
54+ tupleSet = HS.fromList $ mkRelationTuples attrs [
55+ M.fromList [("a", StringAtom "spam"), ("b", StringAtom "spam2")]
56+ ]
57+
58+--rename tests
59+testRename1 :: Test
60+testRename1 = TestCase $ assertEqual "attribute invalid" (rename "a" "b" relationTrue) (Left $ RelationalError 1 "No such attribute")
61+
62+testRename2 :: Test
63+testRename2 = TestCase $ assertEqual "attribute in use" (rename "b" "a" simpleRel) (Left $ RelationalError 1 "Attribute \"a\" already in use.")
64+
4365