on 52182bc help sign in
project-m36/test/DataFrame.hs
61 lines 2.4 kB history raw
1import ProjectM36.Client
2import ProjectM36.DataFrame
3import TutorialD.Interpreter.TestBase
5import Test.HUnit
6import System.Exit
7import qualified Data.Set as S
9testList :: Test
10testList = TestList [testOrderBy, testLimit, testOffset]
12main :: IO ()
13main = do
14 tcounts <- runTestTT testList
15 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
17testOrderBy :: Test
18testOrderBy = TestCase $ do
19 (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
20 Right df <- executeDataFrameExpr sessionId dbconn (
21 DataFrameExpr {
22 convertExpr = Project (AttributeNames (S.singleton "status")) (RelationVariable "s" ()),
23 orderExprs = [AttributeOrderExpr "status" AscendingOrder],
24 offset = Nothing,
25 limit = Nothing
26 })
27 let vals = map (\tup -> case atomForAttributeName "status" tup of
28 Left err -> error (show err)
29 Right atom -> atom) (tuples df)
30 assertEqual "sort order of s" [IntegerAtom 10, IntegerAtom 20, IntegerAtom 30] vals
32testOffset :: Test
33testOffset = 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
47testLimit :: Test
48testLimit = 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