summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AufgabeFFP2.hs6
-rw-r--r--TestAufgabeFFP2.hs78
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)
71g :: Int -> Int -> (Integer -> Integer -> Float) -> Float 71g :: Int -> Int -> (Integer -> Integer -> Float) -> Float
72g z k h = sum $ map (h $ fromIntegral z) [1..(fromIntegral k)] 72g 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!)
75hMT :: Integer -> Integer -> Float 75hMT :: Integer -> Integer -> Float
76hMT z i = (fromInteger $ pofNs z !! (fromInteger i)) / (fromInteger $ facs !! (fromInteger i-1)) 76hMT 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
79h :: Integer -> Integer -> Float 79h :: Integer -> Integer -> Float
@@ -98,4 +98,4 @@ gz n
98 98
99-- goedel-number generator 99-- goedel-number generator
100gzs :: [Integer] 100gzs :: [Integer]
101gzs = map gz [1..] 101gzs = 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
4import Control.Monad 4import Control.Monad
5import AufgabeFFP2 5import AufgabeFFP2
6 6
7assertBoolF :: String -> Bool -> Assertion
8assertBoolF msg b = when b (assertFailure msg)
9 7
10------------------------------------------------------------------------------- 8cases1 = 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
13pps1 :: Test
14pps1 = 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
18pps2 :: Test 17cases2 = TestLabel "2.2" $ TestList [
19pps2 = 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)
23pps3 :: Test 22 ]
24pps3 = TestCase (assertEqual "pps"
25 (809,811)
26 (head (drop 30 pps)))
27 23
28ppsTests = TestList [pps1, pps2, pps3]
29 24
30------------------------------------------------------------------------------- 25cases3 = 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------------------------------------------------------------------------------- 32cases4 = 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
39gz1 :: Test
40gz1 = TestCase (assertEqual "gz"
41 144
42 (gz 42))
43 39
44gz2 :: Test
45gz2 = TestCase (assertEqual "gz"
46 400
47 (gz 402))
48 40
49gzs1 :: Test 41main = runTestTT $ TestList [cases1, cases2, cases3, cases4]
50gzs1 = TestCase (assertEqual "gzs"
51 144
52 (gzs!!41))
53
54gzs2 :: Test
55gzs2 = TestCase (assertEqual "gzs"
56 400
57 (gzs!!401))
58
59
60gzTests = TestList [gz1, gz2, gzs1, gzs2]
61
62-------------------------------------------------------------------------------
63
64tests :: [Test]
65tests = [ppsTests, gzTests]
66
67main = do
68 forM tests $ \test ->
69 runTestTT test