From 019b36815c16c44729f25db08395bc0663bb2653 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 14 May 2012 01:54:29 +0200 Subject: implementing part 1 (eval) of assignment 6 --- AufgabeFFP6.hs | 19 +++++++++++++++++++ TestAufgabeFFP6.hs | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 AufgabeFFP6.hs create mode 100644 TestAufgabeFFP6.hs diff --git a/AufgabeFFP6.hs b/AufgabeFFP6.hs new file mode 100644 index 0000000..ff16ba8 --- /dev/null +++ b/AufgabeFFP6.hs @@ -0,0 +1,19 @@ +module AufgabeFFP6 +where + +import Data.Array + +myfoldl :: [(a -> b -> a)] -> a -> [b] -> a +myfoldl _ z [] = z +myfoldl (f:fs) z (x:xs) = myfoldl fs (f z x) xs + +myfoldl' :: [(a -> a -> a)] -> [a] -> a +myfoldl' f (x:xs) = myfoldl f x xs + +eval :: Array Int Int -> Array Int (Int -> Int -> Int) -> Int +eval a b = myfoldl' (elems b) (elems a) + +-------------------------------------------------------------------------------- + +--yield :: Array Int Int -> Int -> [Array Int (Int -> Int -> Int)] + diff --git a/TestAufgabeFFP6.hs b/TestAufgabeFFP6.hs new file mode 100644 index 0000000..86bd75d --- /dev/null +++ b/TestAufgabeFFP6.hs @@ -0,0 +1,22 @@ +module Main where + +import Test.HUnit +import Control.Monad +import AufgabeFFP6 +import Data.Array + +cases1 = TestLabel "eval" $ TestList [ + TestCase $ assertEqual "eval1" (0) + (eval (array (1,3) [(1,1), (2,2), (3,3)]) (array (1,2) [(1,(+)), (2,(-))])), + TestCase $ assertEqual "eval2" (5) + (eval (array (1,3) [(1,1), (2,2), (3,3)]) (array (1,2) [(1,(*)), (2,(+))])), + TestCase $ assertEqual "eval3" (-3) + (eval (array (1,3) [(1,1), (2,2), (3,3)]) (array (1,2) [(1,(-)), (2,(*))])) + ] + +tests :: [Test] +tests = [cases1] + +main = do + forM tests $ \test -> + runTestTT test -- cgit v1.2.3