From 3cc0356cae5bc03e2331a68c3411e3df7cd222d6 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 12 May 2012 13:42:06 +0200 Subject: fix method renaming --- AufgabeFFP5.hs | 30 +++++++++++++++--------------- TestAufgabeFFP5.hs | 7 +++---- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/AufgabeFFP5.hs b/AufgabeFFP5.hs index 430fb22..75383f7 100644 --- a/AufgabeFFP5.hs +++ b/AufgabeFFP5.hs @@ -1,8 +1,8 @@ module AufgabeFFP5 where - + import Data.Array - + newtype Table a b = Tbl (Array b a) deriving Show @@ -31,7 +31,7 @@ dynamic compute bnds = t bndsAS :: Array Int Int -> ((Int, Int), (Int, Int)) bndsAS a = ((l,l), (h,h)) where - (l,h) = bounds a + (l,h) = bounds a -- fill the table. Lower half below diagonal not necessary -- but filled with the symmetric value @@ -44,7 +44,7 @@ compAS a t (i,j) -- computes distance-sum-table for array asTbl :: Array Int Int -> Table Int (Int, Int) asTbl a = dynamic (compAS a) (bndsAS a) - + -- maximum function for tables tblMax :: (Ord a, Ix b) => Table a b -> a tblMax (Tbl a) = maximum $ elems a @@ -79,7 +79,7 @@ maxL (x:xs) l (x,y) = y-x maxTail = maxL xs --- index with maximum distance-sum and maximum index-difference +-- index with maximum distance-sum and maximum index-difference lmas :: Array Int Int -> (Int, Int) lmas a = maxL $ amas a @@ -92,27 +92,27 @@ divideAndConquer indiv solve divide combine initPb = dAC initPb | indiv pb = solve pb | otherwise = combine pb (map dAC (divide pb)) - + ------------------------------------------------------------------------------- -- 4. ------------------------------------------------------------------------------- mi_indiv :: [a] -> Bool -miIndiv a = length a <= 1 +mi_indiv a = length a <= 1 mi_solve :: (Ix a, Show a) => (b -> Bool) -> [(a,b)] -> [(a,b)] -miSolve wf [(a,b)] +mi_solve wf [(a,b)] | wf b = [(a,b)] | otherwise = [] - + mi_divide :: [a] -> [[a]] -miDivide (x:xs) = [[x], xs] +mi_divide (x:xs) = [[x], xs] mi_combine :: [a] -> [[a]] -> [a] -miCombine _ [] = error "No matching index" -miCombine a (x:xs) - | null x = miCombine a xs +mi_combine _ [] = error "No matching index" +mi_combine a (x:xs) + | null x = mi_combine a xs | otherwise = [head x] - + minIndex :: (Ix a, Show a) => Array a b -> (b -> Bool) -> a -minIndex a wf = fst $ head $ divideAndConquer miIndiv (miSolve wf) miDivide miCombine $ assocs a \ No newline at end of file +minIndex a wf = fst $ head $ divideAndConquer mi_indiv (mi_solve wf) mi_divide mi_combine $ assocs a 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