From 858b0cbc8800d695ddd3797d5eccd9a4205ecc5d Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Tue, 8 May 2012 09:50:20 +0200 Subject: Comments, shorter tests --- AufgabeFFP5.hs | 6 ++-- 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) | i Table Int (Int, Int) asTbl a = dynamic (compAS a) (bndsAS a) @@ -59,10 +59,10 @@ mas a = tblMax $ asTbl a -- all indices where the value equals to the maximum distance-sum amas :: Array Int Int -> [(Int, Int)] -amas a = [(i,j) | ((i,j),v) <- (assocs array), i<=j, v>=m] +amas a = [(i,j) | ((i,j),v) <- (assocs array), i<=j, v>=maxAS] where t@(Tbl array) = asTbl a - m = tblMax t + maxAS = tblMax t ------------------------------------------------------------------------------- -- 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) w :: Array Week String w = array (Tue, Sat) [(Wed, "work"), (Thu, "study"), (Tue, "study"), (Fri, "chill"), (Sat, "relax")] -cases1 = TestLabel "mas" $ TestList [ - TestCase $ assertEqual "mas a" - 12 - (mas a), - TestCase $ assertEqual "mas b" - 12 - (mas b), - TestCase $ assertEqual "mas c" - 5 - (mas c), - TestCase $ assertEqual "mas d" - 21 - (mas d), - TestCase $ assertEqual "mas minA" - 0 - (mas minA) +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 [ - TestCase $ assertEqual "amas a" - [(3,7), (4,7)] - (amas a), - TestCase $ assertEqual "amas b" - [(1,7),(1,8),(4,7),(4,8)] - (amas b), - TestCase $ assertEqual "amas c" - [(1,2),(4,5)] - (amas c), - TestCase $ assertEqual "amas d" - [(2,6)] - (amas d), - TestCase $ assertEqual "amas minA" - [(0,0)] - (amas minA) + "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 [ - TestCase $ assertEqual "lmas a" - (3,7) - (lmas a), - TestCase $ assertEqual "lmas b" - (1,8) - (lmas b), - TestCase $ assertEqual "lmas c" - (1,2) - (lmas c), - TestCase $ assertEqual "lmas d" - (2,6) - (lmas d), - TestCase $ assertEqual "lmas minA" - (0,0) - (lmas minA) + "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 [ - TestCase $ assertEqual "minIndex a (>5)" - 4 - (minIndex a (>5)), - TestCase $ assertEqual "minIndex a (<0)" - 2 - (minIndex a (<0)), - TestCase $ assertEqual "minIndex a (even)" - 3 - (minIndex a (even)), - TestCase $ assertEqual "minIndex b (odd)" - 1 - (minIndex b (odd)), - -- TestCase $ assertEqual "minIndex b (>100)" - -- error "No matching index" - -- (minIndex b (>100)), - TestCase $ assertEqual "minIndex w (=='relax')" - Sat - (minIndex w (=="relax")), - TestCase $ assertEqual "minIndex w (=='work')" - Wed - (minIndex w (=="work")), - TestCase $ assertEqual "minIndex w (=='chill')" - Fri - (minIndex w (=="chill")), - TestCase $ assertEqual "minIndex w (/='chill')" - Tue - (minIndex w (/="chill")) - -- TestCase $ assertEqual "minIndex w (=='swim')" - -- error "No matching index" - -- (minIndex w (=="swim")) + "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")) ] -- cgit v1.2.3