diff options
| -rw-r--r-- | AufgabeFFP5.hs | 6 | ||||
| -rw-r--r-- | TestAufgabeFFP5.hs | 102 |
2 files changed, 29 insertions, 79 deletions
diff --git a/AufgabeFFP5.hs b/AufgabeFFP5.hs index 3fb926c..78ed0fe 100644 --- a/AufgabeFFP5.hs +++ b/AufgabeFFP5.hs | |||
| @@ -41,7 +41,7 @@ compAS a t (i,j) | |||
| 41 | | i<j = compAS a t (j,i) | 41 | | i<j = compAS a t (j,i) |
| 42 | | otherwise = findTable t (i-1, j) + a!i | 42 | | otherwise = findTable t (i-1, j) + a!i |
| 43 | 43 | ||
| 44 | -- computes table for array | 44 | -- computes distance-sum-table for array |
| 45 | asTbl :: Array Int Int -> Table Int (Int, Int) | 45 | asTbl :: Array Int Int -> Table Int (Int, Int) |
| 46 | asTbl a = dynamic (compAS a) (bndsAS a) | 46 | asTbl a = dynamic (compAS a) (bndsAS a) |
| 47 | 47 | ||
| @@ -59,10 +59,10 @@ mas a = tblMax $ asTbl a | |||
| 59 | 59 | ||
| 60 | -- all indices where the value equals to the maximum distance-sum | 60 | -- all indices where the value equals to the maximum distance-sum |
| 61 | amas :: Array Int Int -> [(Int, Int)] | 61 | amas :: Array Int Int -> [(Int, Int)] |
| 62 | amas a = [(i,j) | ((i,j),v) <- (assocs array), i<=j, v>=m] | 62 | amas a = [(i,j) | ((i,j),v) <- (assocs array), i<=j, v>=maxAS] |
| 63 | where | 63 | where |
| 64 | t@(Tbl array) = asTbl a | 64 | t@(Tbl array) = asTbl a |
| 65 | m = tblMax t | 65 | maxAS = tblMax t |
| 66 | 66 | ||
| 67 | ------------------------------------------------------------------------------- | 67 | ------------------------------------------------------------------------------- |
| 68 | -- 3. | 68 | -- 3. |
diff --git a/TestAufgabeFFP5.hs b/TestAufgabeFFP5.hs index eaace62..7e0b731 100644 --- a/TestAufgabeFFP5.hs +++ b/TestAufgabeFFP5.hs | |||
| @@ -25,91 +25,41 @@ data Week = Mon | Tue | Wed | Thu | Fri | Sat | Sun deriving (Eq, Ord, Ix, Show) | |||
| 25 | w :: Array Week String | 25 | w :: Array Week String |
| 26 | w = array (Tue, Sat) [(Wed, "work"), (Thu, "study"), (Tue, "study"), (Fri, "chill"), (Sat, "relax")] | 26 | w = array (Tue, Sat) [(Wed, "work"), (Thu, "study"), (Tue, "study"), (Fri, "chill"), (Sat, "relax")] |
| 27 | 27 | ||
| 28 | cases1 = TestLabel "mas" $ TestList [ | 28 | cases1 = "mas" ~: TestList [ |
| 29 | TestCase $ assertEqual "mas a" | 29 | "mas a" ~: 12 ~=? (mas a), |
| 30 | 12 | 30 | "mas b" ~: 12 ~=? (mas b), |
| 31 | (mas a), | 31 | "mas c" ~: 5 ~=? (mas c), |
| 32 | TestCase $ assertEqual "mas b" | 32 | "mas d" ~: 21 ~=? (mas d), |
| 33 | 12 | 33 | "mas minA" ~: 0 ~=? (mas minA) |
| 34 | (mas b), | ||
| 35 | TestCase $ assertEqual "mas c" | ||
| 36 | 5 | ||
| 37 | (mas c), | ||
| 38 | TestCase $ assertEqual "mas d" | ||
| 39 | 21 | ||
| 40 | (mas d), | ||
| 41 | TestCase $ assertEqual "mas minA" | ||
| 42 | 0 | ||
| 43 | (mas minA) | ||
| 44 | ] | 34 | ] |
| 45 | 35 | ||
| 46 | cases2 = TestLabel "amas" $ TestList [ | 36 | cases2 = TestLabel "amas" $ TestList [ |
| 47 | TestCase $ assertEqual "amas a" | 37 | "amas a" ~: [(3,7), (4,7)] ~=? (amas a), |
| 48 | [(3,7), (4,7)] | 38 | "amas b" ~: [(1,7),(1,8),(4,7),(4,8)] ~=? (amas b), |
| 49 | (amas a), | 39 | "amas c" ~: [(1,2),(4,5)] ~=? (amas c), |
| 50 | TestCase $ assertEqual "amas b" | 40 | "amas d" ~: [(2,6)] ~=? (amas d), |
| 51 | [(1,7),(1,8),(4,7),(4,8)] | 41 | "amas minA" ~: [(0,0)] ~=? (amas minA) |
| 52 | (amas b), | ||
| 53 | TestCase $ assertEqual "amas c" | ||
| 54 | [(1,2),(4,5)] | ||
| 55 | (amas c), | ||
| 56 | TestCase $ assertEqual "amas d" | ||
| 57 | [(2,6)] | ||
| 58 | (amas d), | ||
| 59 | TestCase $ assertEqual "amas minA" | ||
| 60 | [(0,0)] | ||
| 61 | (amas minA) | ||
| 62 | ] | 42 | ] |
| 63 | 43 | ||
| 64 | cases3 = TestLabel "lmas" $ TestList [ | 44 | cases3 = TestLabel "lmas" $ TestList [ |
| 65 | TestCase $ assertEqual "lmas a" | 45 | "lmas a" ~: (3,7) ~=? (lmas a), |
| 66 | (3,7) | 46 | "lmas b" ~: (1,8) ~=? (lmas b), |
| 67 | (lmas a), | 47 | "lmas c" ~: (1,2) ~=? (lmas c), |
| 68 | TestCase $ assertEqual "lmas b" | 48 | "lmas d" ~: (2,6) ~=? (lmas d), |
| 69 | (1,8) | 49 | "lmas minA" ~: (0,0) ~=? (lmas minA) |
| 70 | (lmas b), | ||
| 71 | TestCase $ assertEqual "lmas c" | ||
| 72 | (1,2) | ||
| 73 | (lmas c), | ||
| 74 | TestCase $ assertEqual "lmas d" | ||
| 75 | (2,6) | ||
| 76 | (lmas d), | ||
| 77 | TestCase $ assertEqual "lmas minA" | ||
| 78 | (0,0) | ||
| 79 | (lmas minA) | ||
| 80 | ] | 50 | ] |
| 81 | 51 | ||
| 82 | cases4 = TestLabel "minIndex" $ TestList [ | 52 | cases4 = TestLabel "minIndex" $ TestList [ |
| 83 | TestCase $ assertEqual "minIndex a (>5)" | 53 | "minIndex a (>5)" ~: 4 ~=? (minIndex a (>5)), |
| 84 | 4 | 54 | "minIndex a (<0)" ~: 2 ~=? (minIndex a (<0)), |
| 85 | (minIndex a (>5)), | 55 | "minIndex a (even)" ~: 3 ~=? (minIndex a (even)), |
| 86 | TestCase $ assertEqual "minIndex a (<0)" | 56 | "minIndex b (odd)" ~: 1 ~=? (minIndex b (odd)), |
| 87 | 2 | 57 | -- "minIndex b (>100)" ~: error "No matching index" ~=? (minIndex b (>100)), |
| 88 | (minIndex a (<0)), | 58 | "minIndex w (=='relax')" ~: Sat ~=? (minIndex w (=="relax")), |
| 89 | TestCase $ assertEqual "minIndex a (even)" | 59 | "minIndex w (=='work')" ~: Wed ~=? (minIndex w (=="work")), |
| 90 | 3 | 60 | "minIndex w (=='chill')" ~: Fri ~=? (minIndex w (=="chill")), |
| 91 | (minIndex a (even)), | 61 | "minIndex w (/='chill')" ~: Tue ~=? (minIndex w (/="chill")) |
| 92 | TestCase $ assertEqual "minIndex b (odd)" | 62 | -- "minIndex w (=='swim')" ~: error "No matching index" ~=? (minIndex w (=="swim")) |
| 93 | 1 | ||
| 94 | (minIndex b (odd)), | ||
| 95 | -- TestCase $ assertEqual "minIndex b (>100)" | ||
| 96 | -- error "No matching index" | ||
| 97 | -- (minIndex b (>100)), | ||
| 98 | TestCase $ assertEqual "minIndex w (=='relax')" | ||
| 99 | Sat | ||
| 100 | (minIndex w (=="relax")), | ||
| 101 | TestCase $ assertEqual "minIndex w (=='work')" | ||
| 102 | Wed | ||
| 103 | (minIndex w (=="work")), | ||
| 104 | TestCase $ assertEqual "minIndex w (=='chill')" | ||
| 105 | Fri | ||
| 106 | (minIndex w (=="chill")), | ||
| 107 | TestCase $ assertEqual "minIndex w (/='chill')" | ||
| 108 | Tue | ||
| 109 | (minIndex w (/="chill")) | ||
| 110 | -- TestCase $ assertEqual "minIndex w (=='swim')" | ||
| 111 | -- error "No matching index" | ||
| 112 | -- (minIndex w (=="swim")) | ||
| 113 | ] | 63 | ] |
| 114 | 64 | ||
| 115 | 65 | ||
