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