#!/usr/bin/runhugs +l module Main where import Test.HUnit import Control.Monad import System 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] isSuccess :: Counts -> Bool isSuccess Counts{ cases = _, tried = _, errors = 0, failures = 0 } = True isSuccess Counts{ cases = _, tried = _, errors = _, failures = _ } = False runTest :: Test -> IO () runTest test = do result <- runTestTT test unless (isSuccess result) exitFailure main = do forM tests $ (\test -> runTest test)