diff options
| -rw-r--r-- | AufgabeFFP2.hs | 6 | ||||
| -rw-r--r-- | TestAufgabeFFP2.hs | 78 |
2 files changed, 28 insertions, 56 deletions
diff --git a/AufgabeFFP2.hs b/AufgabeFFP2.hs index 0415b32..7ed19fc 100644 --- a/AufgabeFFP2.hs +++ b/AufgabeFFP2.hs | |||
| @@ -69,11 +69,11 @@ f z k = g z k h | |||
| 69 | 69 | ||
| 70 | -- actual function g (converts Int to Integer for more precision) | 70 | -- actual function g (converts Int to Integer for more precision) |
| 71 | g :: Int -> Int -> (Integer -> Integer -> Float) -> Float | 71 | g :: Int -> Int -> (Integer -> Integer -> Float) -> Float |
| 72 | g z k h = sum $ map (h $ fromIntegral z) [1..(fromIntegral k)] | 72 | g z k h = sum $ map (h $ fromIntegral z) [0..(fromIntegral k)] |
| 73 | 73 | ||
| 74 | -- helper function h using mem-table for the power-series (z^i) and for factorial (i!) | 74 | -- helper function h using mem-table for the power-series (z^i) and for factorial (i!) |
| 75 | hMT :: Integer -> Integer -> Float | 75 | hMT :: Integer -> Integer -> Float |
| 76 | hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facs !! (fromInteger i-1)) | 76 | hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facs !! (fromInteger i)) |
| 77 | 77 | ||
| 78 | -- helper function h without memoization | 78 | -- helper function h without memoization |
| 79 | h :: Integer -> Integer -> Float | 79 | h :: Integer -> Integer -> Float |
| @@ -98,4 +98,4 @@ gz n | |||
| 98 | 98 | ||
| 99 | -- goedel-number generator | 99 | -- goedel-number generator |
| 100 | gzs :: [Integer] | 100 | gzs :: [Integer] |
| 101 | gzs = map gz [1..] | 101 | gzs = map gz [0..] |
diff --git a/TestAufgabeFFP2.hs b/TestAufgabeFFP2.hs index 0df8612..61fdb51 100644 --- a/TestAufgabeFFP2.hs +++ b/TestAufgabeFFP2.hs | |||
| @@ -4,66 +4,38 @@ import Test.HUnit | |||
| 4 | import Control.Monad | 4 | import Control.Monad |
| 5 | import AufgabeFFP2 | 5 | import AufgabeFFP2 |
| 6 | 6 | ||
| 7 | assertBoolF :: String -> Bool -> Assertion | ||
| 8 | assertBoolF msg b = when b (assertFailure msg) | ||
| 9 | 7 | ||
| 10 | ------------------------------------------------------------------------------- | 8 | cases1 = TestLabel "2.1" $ TestList [ |
| 11 | -- 1 | 9 | TestCase $ |
| 10 | [(3,5),(5,7),(11,13),(17,19),(29,31),(41,43), (59,61),(71,73),(101,103),(107,109)] | ||
| 11 | @=? (take 10 pps), | ||
| 12 | TestCase $ (347,349) @=? (pps!!20), | ||
| 13 | TestCase $ (809,811) @=? (head (drop 30 pps)) | ||
| 14 | ] | ||
| 12 | 15 | ||
| 13 | pps1 :: Test | ||
| 14 | pps1 = TestCase (assertEqual "pps" | ||
| 15 | [(3,5),(5,7),(11,13),(17,19),(29,31),(41,43), (59,61),(71,73),(101,103),(107,109)] | ||
| 16 | (take 10 pps)) | ||
| 17 | 16 | ||
| 18 | pps2 :: Test | 17 | cases2 = TestLabel "2.2" $ TestList [ |
| 19 | pps2 = TestCase (assertEqual "pps" | 18 | TestCase $ 1024 @=? (powFast 10), |
| 20 | (347,349) | 19 | TestCase $ (pow 10) @=? (powFast 10), |
| 21 | (pps!!20)) | 20 | TestCase $ 1048576 @=? (powFast 20), |
| 22 | 21 | TestCase $ (pow 20) @=? (powFast 20) | |
| 23 | pps3 :: Test | 22 | ] |
| 24 | pps3 = TestCase (assertEqual "pps" | ||
| 25 | (809,811) | ||
| 26 | (head (drop 30 pps))) | ||
| 27 | 23 | ||
| 28 | ppsTests = TestList [pps1, pps2, pps3] | ||
| 29 | 24 | ||
| 30 | ------------------------------------------------------------------------------- | 25 | cases3 = TestLabel "2.3" $ TestList [ |
| 31 | -- 2 | 26 | TestCase $ (fMT 10 10) @=? (f 10 10), |
| 27 | TestCase $ (fMT 50 10) @=? (f 50 10), | ||
| 28 | TestCase $ (fMT 1000 10) @=? (f 1000 10) | ||
| 29 | ] | ||
| 32 | 30 | ||
| 33 | ------------------------------------------------------------------------------- | ||
| 34 | -- 3 | ||
| 35 | 31 | ||
| 36 | ------------------------------------------------------------------------------- | 32 | cases4 = TestLabel "2.4" $ TestList [ |
| 37 | -- 4 | 33 | TestCase $ 144 @=? (gz 42), |
| 34 | TestCase $ 400 @=? (gz 402), | ||
| 35 | TestCase $ 144 @=? (gzs!!42), | ||
| 36 | TestCase $ 400 @=? (gzs!!402) | ||
| 37 | ] | ||
| 38 | 38 | ||
| 39 | gz1 :: Test | ||
| 40 | gz1 = TestCase (assertEqual "gz" | ||
| 41 | 144 | ||
| 42 | (gz 42)) | ||
| 43 | 39 | ||
| 44 | gz2 :: Test | ||
| 45 | gz2 = TestCase (assertEqual "gz" | ||
| 46 | 400 | ||
| 47 | (gz 402)) | ||
| 48 | 40 | ||
| 49 | gzs1 :: Test | 41 | main = runTestTT $ TestList [cases1, cases2, cases3, cases4] |
| 50 | gzs1 = TestCase (assertEqual "gzs" | ||
| 51 | 144 | ||
| 52 | (gzs!!41)) | ||
| 53 | |||
| 54 | gzs2 :: Test | ||
| 55 | gzs2 = TestCase (assertEqual "gzs" | ||
| 56 | 400 | ||
| 57 | (gzs!!401)) | ||
| 58 | |||
| 59 | |||
| 60 | gzTests = TestList [gz1, gz2, gzs1, gzs2] | ||
| 61 | |||
| 62 | ------------------------------------------------------------------------------- | ||
| 63 | |||
| 64 | tests :: [Test] | ||
| 65 | tests = [ppsTests, gzTests] | ||
| 66 | |||
| 67 | main = do | ||
| 68 | forM tests $ \test -> | ||
| 69 | runTestTT test | ||
