diff options
Diffstat (limited to 'TestAufgabeFFP5.hs')
| -rw-r--r-- | TestAufgabeFFP5.hs | 70 |
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 @@ | |||
| 1 | module Main where | ||
| 2 | |||
| 3 | import Test.HUnit | ||
| 4 | import Control.Monad | ||
| 5 | import Data.Array | ||
| 6 | import AufgabeFFP5 | ||
| 7 | |||
| 8 | a :: Array Int Int | ||
| 9 | a = array (1,9) [(1,3),(2,(-5)),(3,0),(4,9),(5,2),(6,(-1)),(7,2),(8,(-5)),(9,1)] | ||
| 10 | |||
| 11 | b :: Array Int Int | ||
| 12 | b = array (1,9) [(1,3),(2,(-1)),(3,(-2)),(4,9),(5,2),(6,(-1)),(7,2),(8,0),(9,(-1))] | ||
| 13 | |||
| 14 | c :: Array Int Int | ||
| 15 | c = array (1,5) [(1,2),(2,3),(3,(-10)),(4,1),(5,4)] | ||
| 16 | |||
| 17 | d :: Array Int Int | ||
| 18 | d = array (1,6) [(1, (-3)), (2, 1), (3, 10), (4, (-5)), (5, 8), (6, 7)] | ||
| 19 | |||
| 20 | minA :: Array Int Int | ||
| 21 | minA = array (0,0) [(0,0)] | ||
| 22 | |||
| 23 | data Week = Mon | Tue | Wed | Thu | Fri | Sat | Sun deriving (Eq, Ord, Ix, Show) | ||
| 24 | |||
| 25 | w :: Array Week String | ||
| 26 | w = array (Tue, Sat) [(Wed, "work"), (Thu, "study"), (Tue, "study"), (Fri, "chill"), (Sat, "relax")] | ||
| 27 | |||
| 28 | cases1 = "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 | |||
| 36 | cases2 = 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 | |||
| 44 | cases3 = 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 | |||
| 52 | cases4 = 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 | |||
| 65 | tests :: [Test] | ||
| 66 | tests = [cases1, cases2, cases3, cases4] | ||
| 67 | |||
| 68 | main = do | ||
| 69 | forM tests $ \test -> | ||
| 70 | runTestTT test | ||
