From 1f33246d13fdc722c17a3c5a10aed373848b78ec Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Sun, 6 May 2012 15:56:23 +0200 Subject: Aufgabe 5, 1 --- TestAufgabeFFP5.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 TestAufgabeFFP5.hs (limited to 'TestAufgabeFFP5.hs') diff --git a/TestAufgabeFFP5.hs b/TestAufgabeFFP5.hs new file mode 100644 index 0000000..03cd00b --- /dev/null +++ b/TestAufgabeFFP5.hs @@ -0,0 +1,22 @@ +module Main where + +import Test.HUnit +import Control.Monad +import Data.Array +import AufgabeFFP5 + +cases1 = TestLabel "mas" $ TestList [ + TestCase $ assertEqual "exercise example" + 12 + (mas $ array (1,9) [(1,3),(2,(-5)),(3,0),(4,9),(5,2),(6,(-1)),(7,2),(8,(-5)),(9,1)]), + TestCase $ assertEqual "short list" + 21 + (mas $ array (1,6) [(1, (-3)), (2, 1), (3, 10), (4, (-5)), (5, 8), (6, 7)]) + ] + +tests :: [Test] +tests = [cases1] + +main = do + forM tests $ \test -> + runTestTT test -- cgit v1.2.3 From 6d5084dde0a659debb606e837e8edf06b4b534cf Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Sun, 6 May 2012 19:22:14 +0200 Subject: Aufgabe 5, 1-3 --- TestAufgabeFFP5.hs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 5 deletions(-) (limited to 'TestAufgabeFFP5.hs') diff --git a/TestAufgabeFFP5.hs b/TestAufgabeFFP5.hs index 03cd00b..256c1ea 100644 --- a/TestAufgabeFFP5.hs +++ b/TestAufgabeFFP5.hs @@ -5,17 +5,78 @@ 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)] + cases1 = TestLabel "mas" $ TestList [ - TestCase $ assertEqual "exercise example" + TestCase $ assertEqual "mas a" 12 - (mas $ array (1,9) [(1,3),(2,(-5)),(3,0),(4,9),(5,2),(6,(-1)),(7,2),(8,(-5)),(9,1)]), - TestCase $ assertEqual "short list" + (mas a), + TestCase $ assertEqual "mas b" + 12 + (mas b), + TestCase $ assertEqual "mas c" + 5 + (mas c), + TestCase $ assertEqual "mas d" 21 - (mas $ array (1,6) [(1, (-3)), (2, 1), (3, 10), (4, (-5)), (5, 8), (6, 7)]) + (mas d), + TestCase $ assertEqual "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) ] + +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) + ] + tests :: [Test] -tests = [cases1] +tests = [cases1, cases2, cases3] main = do forM tests $ \test -> -- cgit v1.2.3 From 2eb3ebc3247656c246258fd6a078fa5801ff80f3 Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Sun, 6 May 2012 22:24:13 +0200 Subject: Aufgabe 5, 4. Almost done, except testing errors --- TestAufgabeFFP5.hs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'TestAufgabeFFP5.hs') diff --git a/TestAufgabeFFP5.hs b/TestAufgabeFFP5.hs index 256c1ea..eaace62 100644 --- a/TestAufgabeFFP5.hs +++ b/TestAufgabeFFP5.hs @@ -20,6 +20,11 @@ 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 = TestLabel "mas" $ TestList [ TestCase $ assertEqual "mas a" 12 @@ -73,10 +78,43 @@ cases3 = TestLabel "lmas" $ TestList [ (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")) + ] tests :: [Test] -tests = [cases1, cases2, cases3] +tests = [cases1, cases2, cases3, cases4] main = do forM tests $ \test -> -- cgit v1.2.3 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 --- TestAufgabeFFP5.hs | 102 ++++++++++++++--------------------------------------- 1 file changed, 26 insertions(+), 76 deletions(-) (limited to 'TestAufgabeFFP5.hs') 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 From 3cc0356cae5bc03e2331a68c3411e3df7cd222d6 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 12 May 2012 13:42:06 +0200 Subject: fix method renaming --- TestAufgabeFFP5.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'TestAufgabeFFP5.hs') diff --git a/TestAufgabeFFP5.hs b/TestAufgabeFFP5.hs index 7e0b731..865f503 100644 --- a/TestAufgabeFFP5.hs +++ b/TestAufgabeFFP5.hs @@ -32,7 +32,7 @@ cases1 = "mas" ~: TestList [ "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), @@ -40,7 +40,7 @@ cases2 = TestLabel "amas" $ TestList [ "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), @@ -48,7 +48,7 @@ cases3 = TestLabel "lmas" $ TestList [ "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)), @@ -62,7 +62,6 @@ cases4 = TestLabel "minIndex" $ TestList [ -- "minIndex w (=='swim')" ~: error "No matching index" ~=? (minIndex w (=="swim")) ] - tests :: [Test] tests = [cases1, cases2, cases3, cases4] -- cgit v1.2.3