From c9e70808546f2a6b58e1729d64e7ae8bbc17a98e Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 23 Mar 2012 19:02:47 +0100 Subject: implement fibdiags (+ some indention stuff) --- AufgabeFFP1.hs | 5 +++++ TestAufgabeFFP1.hs | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/AufgabeFFP1.hs b/AufgabeFFP1.hs index 88d46b4..b393fc2 100644 --- a/AufgabeFFP1.hs +++ b/AufgabeFFP1.hs @@ -38,3 +38,8 @@ fibdiag (n) | otherwise = map (\x -> pd !! (fromInteger n - x) !! (x - 1)) [1..count] where count = (fromInteger n + 1) `div` 2 + +------------------------------------------------------------------------------- + +fibdiags :: [[Integer]] +fibdiags = map (fibdiag) [1,2..] diff --git a/TestAufgabeFFP1.hs b/TestAufgabeFFP1.hs index 7cbc2c2..1fa5c35 100644 --- a/TestAufgabeFFP1.hs +++ b/TestAufgabeFFP1.hs @@ -10,17 +10,20 @@ assertBoolF msg b = when b (assertFailure msg) ------------------------------------------------------------------------------- pof2s1 :: Test -pof2s1 = TestCase (assertEqual "pof2s" [1,2,4,8,16,32,64,128,256,512] (take 10 pof2s)) +pof2s1 = TestCase (assertEqual "pof2s" + [1,2,4,8,16,32,64,128,256,512] + (take 10 pof2s)) pof2sTests = TestList [pof2s1] ------------------------------------------------------------------------------- pd1 :: Test -pd1 = TestCase (assertEqual "pd" [[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1], - [1,5,10,10,5,1], [1,6,15,20,15,6,1], [1,7,21,35,35,21,7,1], - [1,8,28,56,70,56,28,8,1], [1,9,36,84,126,126,84,36,9,1], - [1,10,45,120,210,252,210,120,45,10,1]] (take 11 pd)) +pd1 = TestCase (assertEqual "pd" + [[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1], [1,5,10,10,5,1], + [1,6,15,20,15,6,1], [1,7,21,35,35,21,7,1], [1,8,28,56,70,56,28,8,1], + [1,9,36,84,126,126,84,36,9,1], [1,10,45,120,210,252,210,120,45,10,1]] + (take 11 pd)) pdTests = TestList [pd1] @@ -55,8 +58,17 @@ fibdiagTests = TestList [fibdiag1, fibdiag2, fibdiag3, fibdiag4, fibdiag5, ------------------------------------------------------------------------------- +fibdiags1 :: Test +fibdiags1 = TestCase (assertEqual "fibdiags" + [[1], [1], [1,1], [1,2], [1,3,1], [1,4,3], [1,5,6,1], [1,6,10,4]] + (take 8 fibdiags)) + +fibdiagsTests = TestList [fibdiags1] + +------------------------------------------------------------------------------- + tests :: [Test] -tests = [pof2s1, pdTests, fibdiagTests] +tests = [pof2s1, pdTests, fibdiagTests, fibdiagsTests] main = do forM tests $ \test -> -- cgit v1.2.3