From 9545fb945e42151afe04a384cb7acf43c1ab9350 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 14 Apr 2012 18:52:18 +0200 Subject: * remove trailing whitespaces * fix wrong indention (no tabs, use 2 spaces, don't mix) * name testcaselists by their methods * add (more or less) individual testname per testcase * call testcase lists in a do-loop so that every testcase list generates a seperate output --- AufgabeFFP2.hs | 36 ++++++++++++++-------------- TestAufgabeFFP2.hs | 70 +++++++++++++++++++++++++++--------------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/AufgabeFFP2.hs b/AufgabeFFP2.hs index 7ed19fc..aef3bfb 100644 --- a/AufgabeFFP2.hs +++ b/AufgabeFFP2.hs @@ -6,33 +6,33 @@ where -- primality check isPrime :: Integer -> Bool isPrime n = n > 1 && - foldr (\p r -> - p*p > n - || ( - (n `mod` p) /= 0 - && r - ) - ) - True primes - + foldr (\p r -> + p*p > n + || ( + (n `mod` p) /= 0 + && r + ) + ) + True primes + -- series of primes primes :: [Integer] primes = 2:filter isPrime [3,5..] --- pairs of (p,p+2) | p,p+2 <- primes +-- pairs of (p,p+2) | p,p+2 <- primes -- generate all pairs with map and then filter only the valid ones -- pair is valid if the second component n is a prime pps :: [(Integer, Integer)] pps = filter (\(_,x) -> isPrime x) $ map (\p -> (p,p+2)) primes - + ------------------------------------------------------------------------------- -- 2 --- generates powers of 2 +-- generates powers of 2 pof2s :: [Integer] pof2s = [1] ++ map (2*) pof2s - + -- calculates 2^n pow :: Int -> Integer pow 0 = 1 @@ -70,7 +70,7 @@ f z k = g z k h -- actual function g (converts Int to Integer for more precision) g :: Int -> Int -> (Integer -> Integer -> Float) -> Float g z k h = sum $ map (h $ fromIntegral z) [0..(fromIntegral k)] - + -- helper function h using mem-table for the power-series (z^i) and for factorial (i!) hMT :: Integer -> Integer -> Float hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facs !! (fromInteger i)) @@ -86,15 +86,15 @@ h z i = (fromInteger $ z^i) / (fromInteger $ fac i) -- gets the digits of an integer as a list digits :: Integer -> [Integer] digits x - | x<=0 = [] - | otherwise = (digits $ x `div` 10)++[x `mod` 10] + | x<=0 = [] + | otherwise = (digits $ x `div` 10)++[x `mod` 10] -- calculates the goedel-number for the given integer -- returns 0 for non-positive numbers gz :: Integer -> Integer gz n - | n<=0 = 0 - | otherwise = product $ zipWith (^) primes (digits n) + | n<=0 = 0 + | otherwise = product $ zipWith (^) primes (digits n) -- goedel-number generator gzs :: [Integer] diff --git a/TestAufgabeFFP2.hs b/TestAufgabeFFP2.hs index 61fdb51..ef6d48a 100644 --- a/TestAufgabeFFP2.hs +++ b/TestAufgabeFFP2.hs @@ -4,38 +4,38 @@ import Test.HUnit import Control.Monad import AufgabeFFP2 - -cases1 = TestLabel "2.1" $ TestList [ - TestCase $ - [(3,5),(5,7),(11,13),(17,19),(29,31),(41,43), (59,61),(71,73),(101,103),(107,109)] - @=? (take 10 pps), - TestCase $ (347,349) @=? (pps!!20), - TestCase $ (809,811) @=? (head (drop 30 pps)) - ] - - -cases2 = TestLabel "2.2" $ TestList [ - TestCase $ 1024 @=? (powFast 10), - TestCase $ (pow 10) @=? (powFast 10), - TestCase $ 1048576 @=? (powFast 20), - TestCase $ (pow 20) @=? (powFast 20) - ] - - -cases3 = TestLabel "2.3" $ TestList [ - TestCase $ (fMT 10 10) @=? (f 10 10), - TestCase $ (fMT 50 10) @=? (f 50 10), - TestCase $ (fMT 1000 10) @=? (f 1000 10) - ] - - -cases4 = TestLabel "2.4" $ TestList [ - TestCase $ 144 @=? (gz 42), - TestCase $ 400 @=? (gz 402), - TestCase $ 144 @=? (gzs!!42), - TestCase $ 400 @=? (gzs!!402) - ] - - - -main = runTestTT $ TestList [cases1, cases2, cases3, cases4] +cases1 = TestLabel "pps" $ TestList [ + TestCase $ assertEqual "take 10 pps" + [(3,5),(5,7),(11,13),(17,19),(29,31),(41,43), (59,61),(71,73),(101,103),(107,109)] + (take 10 pps), + TestCase $ assertEqual "pps!!20" (347,349) (pps!!20), + TestCase $ assertEqual "head (drop 30 pps)" (809,811) (head (drop 30 pps)) + ] + + +cases2 = TestLabel "powFast" $ TestList [ + TestCase $ assertEqual "powFast 10" 1024 (powFast 10), + TestCase $ assertEqual "powFast 10" (pow 10) (powFast 10), + TestCase $ assertEqual "powFast 20" 1048576 (powFast 20), + TestCase $ assertEqual "powFast 20" (pow 20) (powFast 20) + ] + +cases3 = TestLabel "fMT/f" $ TestList [ + TestCase $ assertEqual "fMT/f 10 10" (fMT 10 10) (f 10 10), + TestCase $ assertEqual "fMT/f 50 10" (fMT 50 10) (f 50 10), + TestCase $ assertEqual "fMT/f 1000 10" (fMT 1000 10) (f 1000 10) + ] + +cases4 = TestLabel "gz/gzs" $ TestList [ + TestCase $ assertEqual "gz 42" 144 (gz 42), + TestCase $ assertEqual "gz 402" 400 (gz 402), + TestCase $ assertEqual "gzs!!42" 144 (gzs!!42), + TestCase $ assertEqual "gzs!!402" 400 (gzs!!402) + ] + +tests :: [Test] +tests = [cases1, cases2, cases3, cases4] + +main = do + forM tests $ \test -> + runTestTT test -- cgit v1.2.3