From cc9fb7c09a62e1811aef5c22e3633e3bd42e2662 Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 15 May 2012 03:52:27 +0200 Subject: =?UTF-8?q?Tests=20f=C3=BCr=20gtf=20und=20bt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AufgabeFFP6.hs | 4 ++++ TestAufgabeFFP6.hs | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AufgabeFFP6.hs b/AufgabeFFP6.hs index 1fde756..c60053d 100644 --- a/AufgabeFFP6.hs +++ b/AufgabeFFP6.hs @@ -91,22 +91,26 @@ yield_bt f w = map (\(_, _, _, g) -> listArray (1, length g) g) nodes yield_gtf :: F -> W -> [G] yield_gtf = filt . transform . generate +-- produce [G] by using get_combinations generate :: F -> W -> (F, W, [G]) generate f w = (f, w, [ array (1,n) entries | entries <- get_combinations n ] ) where n = (snd $ bounds f) - 1 +-- provide all selections of length n, work recursively and attach index for level (convenient for creating arrays) get_combinations :: Int -> [[(Int, Op)]] get_combinations 1 = [[(1,(+))], [(1, (-))], [(1, (*))], [(1,(./.))]] get_combinations n = [ (up i) ++ entr | entr <- get_combinations (n-1), i <- get_combinations 1 ] where up = map (\(num, x) -> ((num+n-1), x)) +-- attaches a list of results transform :: (W -> (F,W,[G])) -> W -> ((F, W, [G]), [W]) transform fun w = ((f, w, g), map (eval f) g ) where (f, w, g) = fun w +-- take those, where the entry in the result list corresponds to filt :: (W -> ((F,W,[G]),[W]) ) -> W -> [G] filt fun w = [ g!!i | i <- [0..n], res!!i == w ] where diff --git a/TestAufgabeFFP6.hs b/TestAufgabeFFP6.hs index 77cae92..c435045 100644 --- a/TestAufgabeFFP6.hs +++ b/TestAufgabeFFP6.hs @@ -22,8 +22,30 @@ cases1 = TestLabel "eval" $ TestList [ (eval (array (1,6) [(1,4), (2,2), (3,3), (4,-4), (5,5), (6,2)]) (array (1,5) [(1,(*)), (2,(-)), (3,(+)), (4,(./.)), (5,(+))])) ] +instance Eq (Integer -> Integer -> Integer) where + (==) op1 op2 = ((op1 3 3) - (op2 3 3)) == 0 +instance Eq (Int -> Int -> Int) where + (==) op1 op2 = ((op1 3 3) - (op2 3 3)) == 0 + +cases2 = TestLabel "yield_bt" $ TestList [ + TestCase $ assertEqual "yield_bt1" (yield_bt (array (1,3) [(1,1),(2,2),(3,3)] ) 6) + [array (1,2) [(1,(+)),(2,(+))],array (1,2) [(1,(*)),(2,(*))]], + TestCase $ assertEqual "yield_bt2" (yield_bt (array (1,3) [(1,1),(2,2),(3,3)] ) 4) [], + TestCase $ assertEqual "yield_bt3" (yield_bt (array (1,3) [(1,1),(2,2),(3,3)]) 0) + [(array (1,2) [(1,(+)),(2,(-))]),(array (1,2) [(1,(*)),(2,(./.))]),(array (1,2) [(1,(./.)),(2,(*))]),(array (1,2) [(1,(./.)),(2,(./.))])] + ] + + +cases3 = TestLabel "yield_gtf" $ TestList [ + TestCase $ assertEqual "yield_gtf1" (yield_gtf (array (1,3) [(1,1),(2,2),(3,3)] ) 6) + [array (1,2) [(1,(+)),(2,(+))],array (1,2) [(1,(*)),(2,(*))]], + TestCase $ assertEqual "yield_gtf2" (yield_gtf (array (1,3) [(1,1),(2,2),(3,3)] ) 4) [], + TestCase $ assertEqual "yield_gtf3" (yield_gtf (array (1,3) [(1,1),(2,2),(3,3)]) 0) + [(array (1,2) [(1,(+)),(2,(-))]),(array (1,2) [(1,(*)),(2,(./.))]),(array (1,2) [(1,(./.)),(2,(*))]),(array (1,2) [(1,(./.)),(2,(./.))])] + ] + tests :: [Test] -tests = [cases1] +tests = [cases1, cases2, cases3] main = do forM tests $ \test -> -- cgit v1.2.3