on master help sign in
add tests for data frame sorting, limiting, offsetting
a92ad77AgentM
src/lib/ProjectM36/Tuple.hs+1−1
@@ -188,7 +188,7 @@ verifyTuple :: Attributes -> RelationTuple -> Either RelationalError RelationTup
188verifyTuple attrs tuple = let attrsTypes = V.map atomType attrs
188verifyTuple attrs tuple = let attrsTypes = V.map atomType attrs
189 tupleTypes = V.map atomTypeForAtom (tupleAtoms tuple) in
189 tupleTypes = V.map atomTypeForAtom (tupleAtoms tuple) in
190 if V.length attrs /= V.length tupleTypes then
190 if V.length attrs /= V.length tupleTypes then
191− Left $ traceShow (attrs, tupleTypes) $ TupleAttributeCountMismatchError 0
191+ Left $ TupleAttributeCountMismatchError 0
192 else do
192 else do
193 mapM_ (uncurry atomTypeVerify) (V.zip attrsTypes tupleTypes)
193 mapM_ (uncurry atomTypeVerify) (V.zip attrsTypes tupleTypes)
194 Right tuple
194 Right tuple
test/DataFrame.hs+30−3
@@ -7,7 +7,7 @@ import System.Exit
7import qualified Data.Set as S
7import qualified Data.Set as S
8
8
9testList :: Test
9testList :: Test
10−testList = TestList []
10+testList = TestList [testOrderBy, testLimit, testOffset]
11
11
12main :: IO ()
12main :: IO ()
13main = do
13main = do
@@ -29,6 +29,33 @@ testOrderBy = TestCase $ do
29 Right atom -> atom) (tuples df)
29 Right atom -> atom) (tuples df)
30 assertEqual "sort order of s" [IntegerAtom 10, IntegerAtom 20, IntegerAtom 30] vals
30 assertEqual "sort order of s" [IntegerAtom 10, IntegerAtom 20, IntegerAtom 30] vals
31
31
32−--testOffset :: Test
32+testOffset :: Test
33+testOffset = TestCase $ do
34+ (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
35+ Right df <- executeDataFrameExpr sessionId dbconn (
36+ DataFrameExpr {
37+ convertExpr = Project (AttributeNames (S.singleton "status")) (RelationVariable "s" ()),
38+ orderExprs = [AttributeOrderExpr "status" AscendingOrder],
39+ offset = Just 1,
40+ limit = Nothing
41+ })
42+ let vals = map (\tup -> case atomForAttributeName "status" tup of
43+ Left err -> error (show err)
44+ Right atom -> atom) (tuples df)
45+ assertEqual "sort + offset" [IntegerAtom 20, IntegerAtom 30] vals
33
46
34−--testLimit :: Test
47+testLimit :: Test
48+testLimit = TestCase $ do
49+ (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
50+ Right df <- executeDataFrameExpr sessionId dbconn (
51+ DataFrameExpr {
52+ convertExpr = Project (AttributeNames (S.singleton "status")) (RelationVariable "s" ()),
53+ orderExprs = [AttributeOrderExpr "status" DescendingOrder],
54+ offset = Nothing,
55+ limit = Just 1
56+ })
57+ let vals = map (\tup -> case atomForAttributeName "status" tup of
58+ Left err -> error (show err)
59+ Right atom -> atom) (tuples df)
60+ assertEqual "sort + limit" [IntegerAtom 30] vals
61+
test/TutorialD/Interpreter/TestBase.hs+2−1
@@ -49,10 +49,11 @@ expectTutorialDErr sessionId conn matchFunc tutd = case parseTutorialD tutd of
49 DisplayResult _ -> assertFailure "display?"
49 DisplayResult _ -> assertFailure "display?"
50 DisplayIOResult _ -> assertFailure "displayIO?"
50 DisplayIOResult _ -> assertFailure "displayIO?"
51 DisplayRelationResult _ -> assertFailure "displayrelation?"
51 DisplayRelationResult _ -> assertFailure "displayrelation?"
52+ DisplayDataFrameResult _ -> assertFailure "displaydataframe?"
52 DisplayParseErrorResult _ _ -> assertFailure "displayparseerrorresult?"
53 DisplayParseErrorResult _ _ -> assertFailure "displayparseerrorresult?"
53 DisplayErrorResult err -> assertBool ("match error on: " ++ unpack err) (matchFunc err)
54 DisplayErrorResult err -> assertBool ("match error on: " ++ unpack err) (matchFunc err)
54 QuietSuccessResult -> pure ()
55 QuietSuccessResult -> pure ()
55
56
56eitherFail :: Either RelationalError a -> IO ()
57eitherFail :: Either RelationalError a -> IO ()
57eitherFail (Left err) = assertFailure (show err)
58eitherFail (Left err) = assertFailure (show err)
58−eitherFail (Right _) = pure ()
59+eitherFail (Right _) = pure ()