summaryrefslogtreecommitdiffstats
path: root/TestAufgabeFFP5.hs
diff options
context:
space:
mode:
Diffstat (limited to 'TestAufgabeFFP5.hs')
-rw-r--r--TestAufgabeFFP5.hs70
1 files changed, 70 insertions, 0 deletions
diff --git a/TestAufgabeFFP5.hs b/TestAufgabeFFP5.hs
new file mode 100644
index 0000000..865f503
--- /dev/null
+++ b/TestAufgabeFFP5.hs
@@ -0,0 +1,70 @@
1module Main where
2
3import Test.HUnit
4import Control.Monad
5import Data.Array
6import AufgabeFFP5
7
8a :: Array Int Int
9a = array (1,9) [(1,3),(2,(-5)),(3,0),(4,9),(5,2),(6,(-1)),(7,2),(8,(-5)),(9,1)]
10
11b :: Array Int Int
12b = array (1,9) [(1,3),(2,(-1)),(3,(-2)),(4,9),(5,2),(6,(-1)),(7,2),(8,0),(9,(-1))]
13
14c :: Array Int Int
15c = array (1,5) [(1,2),(2,3),(3,(-10)),(4,1),(5,4)]
16
17d :: Array Int Int
18d = array (1,6) [(1, (-3)), (2, 1), (3, 10), (4, (-5)), (5, 8), (6, 7)]
19
20minA :: Array Int Int
21minA = array (0,0) [(0,0)]
22
23data Week = Mon | Tue | Wed | Thu | Fri | Sat | Sun deriving (Eq, Ord, Ix, Show)
24
25w :: Array Week String
26w = array (Tue, Sat) [(Wed, "work"), (Thu, "study"), (Tue, "study"), (Fri, "chill"), (Sat, "relax")]
27
28cases1 = "mas" ~: TestList [
29 "mas a" ~: 12 ~=? (mas a),
30 "mas b" ~: 12 ~=? (mas b),
31 "mas c" ~: 5 ~=? (mas c),
32 "mas d" ~: 21 ~=? (mas d),
33 "mas minA" ~: 0 ~=? (mas minA)
34 ]
35
36cases2 = TestLabel "amas" $ TestList [
37 "amas a" ~: [(3,7), (4,7)] ~=? (amas a),
38 "amas b" ~: [(1,7),(1,8),(4,7),(4,8)] ~=? (amas b),
39 "amas c" ~: [(1,2),(4,5)] ~=? (amas c),
40 "amas d" ~: [(2,6)] ~=? (amas d),
41 "amas minA" ~: [(0,0)] ~=? (amas minA)
42 ]
43
44cases3 = TestLabel "lmas" $ TestList [
45 "lmas a" ~: (3,7) ~=? (lmas a),
46 "lmas b" ~: (1,8) ~=? (lmas b),
47 "lmas c" ~: (1,2) ~=? (lmas c),
48 "lmas d" ~: (2,6) ~=? (lmas d),
49 "lmas minA" ~: (0,0) ~=? (lmas minA)
50 ]
51
52cases4 = TestLabel "minIndex" $ TestList [
53 "minIndex a (>5)" ~: 4 ~=? (minIndex a (>5)),
54 "minIndex a (<0)" ~: 2 ~=? (minIndex a (<0)),
55 "minIndex a (even)" ~: 3 ~=? (minIndex a (even)),
56 "minIndex b (odd)" ~: 1 ~=? (minIndex b (odd)),
57 -- "minIndex b (>100)" ~: error "No matching index" ~=? (minIndex b (>100)),
58 "minIndex w (=='relax')" ~: Sat ~=? (minIndex w (=="relax")),
59 "minIndex w (=='work')" ~: Wed ~=? (minIndex w (=="work")),
60 "minIndex w (=='chill')" ~: Fri ~=? (minIndex w (=="chill")),
61 "minIndex w (/='chill')" ~: Tue ~=? (minIndex w (/="chill"))
62 -- "minIndex w (=='swim')" ~: error "No matching index" ~=? (minIndex w (=="swim"))
63 ]
64
65tests :: [Test]
66tests = [cases1, cases2, cases3, cases4]
67
68main = do
69 forM tests $ \test ->
70 runTestTT test