Added Aufgabe 4
This commit is contained in:
@ -1,66 +0,0 @@
|
||||
import Aufgabe1
|
||||
|
||||
import Test.Framework.Providers.HUnit (testCase)
|
||||
import Test.Framework.Runners.Console (defaultMain)
|
||||
import Test.HUnit
|
||||
|
||||
|
||||
{- TEST DATA -}
|
||||
|
||||
data1,data2,data3 :: [(String,String)]
|
||||
data1 = [("Phillip","(04165) 9876543"),("Phillip","(03548) 1234567"),("Paula","(035383) 567890")]
|
||||
data2 = [("Paula","(04165) 8765432"),("Michael","(03548) 2345678"),("Ariane","(035383) 678901")]
|
||||
data3 = [("Paula","(04165) 7654321"),("Hannelore","(03548) 3456789"),("Helmut","(035383) 789012")]
|
||||
|
||||
noData :: [(String,String)]
|
||||
noData = mempty
|
||||
|
||||
xPB :: PhoneBook
|
||||
xPB = PB $ \n -> [b|(a,b)<-data1, n==a]
|
||||
|
||||
yPB :: PhoneBook
|
||||
yPB = PB $ \n -> [b|(a,b)<-data2, n==a]
|
||||
|
||||
zPB :: PhoneBook
|
||||
zPB = PB $ \n -> [b|(a,b)<-data3, n==a]
|
||||
|
||||
examplePB = xPB
|
||||
|
||||
emptyPhoneBook :: PhoneBook
|
||||
emptyPhoneBook = PB $ \a -> [b|(a,b)<-noData]
|
||||
|
||||
{- TEST CASES -}
|
||||
|
||||
usePBTest = testCase "Benutze beispielhaftes PhoneBook"
|
||||
$ assertEqual "usePB examplePB \"Phillip\" sollte folgende zwei Nummern rausgeben" ["(04165) 9876543","(03548) 1234567"]
|
||||
$ usePB examplePB "Phillip"
|
||||
|
||||
mappendTest = testCase "Assoziativität von mappend"
|
||||
$ assertEqual "Assoziativität von mappend ist nicht erfüllt" (usePB (mappend (mappend xPB yPB) zPB) "Paula")
|
||||
$ usePB (mappend xPB $ mappend yPB zPB) "Paula"
|
||||
|
||||
memptyTest1 = testCase "Linksidentität von mempty"
|
||||
$ assertEqual "Linksidentität von mempty ist nicht erfüllt" (usePB xPB "Phillip")
|
||||
$ usePB (mappend xPB mempty) "Phillip"
|
||||
|
||||
memptyTest2 = testCase "Rechtsidentität von mempty"
|
||||
$ assertEqual "Rechtsidentität von mempty ist nicht erfüllt" (usePB xPB "Phillip")
|
||||
$ usePB (mappend mempty xPB) "Phillip"
|
||||
|
||||
addEntryTest = testCase "Füge Name-Nummer-Verknüpfung hinzu"
|
||||
$ assertEqual "Die hinzugefügte Nummer wird nicht gefunden" ["12345"]
|
||||
$ usePB (addEntry "NeuerName" "12345" emptyPhoneBook) "NeuerName"
|
||||
|
||||
delEntryTest = testCase "Lösche Name-Nummer-Verknüpfung"
|
||||
$ assertEqual "Die gelöschte Nummer wird weiterhin gefunden" []
|
||||
$ usePB (delEntry "Paula" xPB) "Paula"
|
||||
|
||||
findInMultTest = testCase "Suche in mehreren PhoneBooks"
|
||||
$ assertEqual "Es werden nicht alle drei Nummern von Paula gefunden" ["(035383) 567890","(04165) 8765432","(04165) 7654321"]
|
||||
$ findInMult [xPB,yPB,zPB] "Paula"
|
||||
|
||||
|
||||
tests = [usePBTest,mappendTest,memptyTest1,memptyTest2,addEntryTest,delEntryTest,findInMultTest]
|
||||
|
||||
main :: IO ()
|
||||
main = defaultMain tests
|
@ -1,7 +0,0 @@
|
||||
main :: IO ()
|
||||
main = putStrLn $ "Eine Testung von Aufgabe 2 mit HUnit ist nicht sinnvoll. \n"
|
||||
++ "Falls Sie feststecken und nicht weiterkommen: \n"
|
||||
++ "Welche Typklassen kennen Sie? \n"
|
||||
++ "Wie sehen deren Instanzen für die vorliegenden Datentypen aus? \n"
|
||||
++ "Welche Regeln/Gesetze implizieren diese Typklassen? \n"
|
||||
++ "Eventuell lassen sich Ausdrücke mehrfach verallgemeinern. \n"
|
@ -1,77 +0,0 @@
|
||||
import Aufgabe3
|
||||
import DataPB
|
||||
import FunPB
|
||||
import AreaCode
|
||||
|
||||
import Test.Framework.Providers.HUnit (testCase)
|
||||
import Test.Framework.Runners.Console (defaultMain)
|
||||
import Test.HUnit
|
||||
|
||||
|
||||
{- TEST DATA -}
|
||||
|
||||
funPBTest = dataToFunPB simpleData
|
||||
|
||||
vielleichtValues = [(Etwas 1234),Nichts]
|
||||
|
||||
entwederValues :: [Entweder String [[[Integer]]]]
|
||||
entwederValues = [(Jenes "just a string"),(Dieses [[[12344321]]])]
|
||||
|
||||
konstantValue = Konstant True
|
||||
|
||||
f = const 1
|
||||
g = const '0'
|
||||
|
||||
|
||||
{- TEST CASES-}
|
||||
|
||||
atleast5CharFalse = testCase "Teste Randbedingung (==False) für atleast5Char"
|
||||
$ assertEqual "Der Ausdruck >>> runPred atLeast5Char $ \"1234\" \nsollte zu False auswerten" False
|
||||
$ runPred atLeast5Char $ "1234"
|
||||
|
||||
atleast5CharTrue = testCase "Teste Randbedingung (==True) für atleast5Char"
|
||||
$ assertEqual "Der Ausdruck >>> runPred atLeast5Char $ \"12345\" \nsollte zu True auswerten" True
|
||||
$ runPred atLeast5Char $ "12345"
|
||||
|
||||
|
||||
|
||||
fmapVielleichtTestIdentity = testCase "Functor Vielleicht: Strukturerhaltung"
|
||||
$ assertEqual "Es sollte gelten: fmap id == id . " (id <$> vielleichtValues)
|
||||
$ ((fmap id) <$> vielleichtValues)
|
||||
|
||||
fmapVielleichtTestComposability = testCase "Functor Vielleicht: Komponierbarkeit"
|
||||
$ assertEqual "Es sollte gelten: fmap f . fmap g == fmap (f . g) . " ((fmap f . fmap g) <$> vielleichtValues)
|
||||
$ ((fmap (f . g)) <$> vielleichtValues)
|
||||
|
||||
|
||||
fmapEntwederTestIdentity = testCase "Functor (Entweder a): Strukturerhaltung"
|
||||
$ assertEqual "Es sollte gelten: fmap id == id . " (id <$> entwederValues)
|
||||
$ ((fmap id) <$> entwederValues)
|
||||
|
||||
fmapEntwederTestComposability = testCase "Functor (Entweder a): Komponierbarkeit"
|
||||
$ assertEqual "Es sollte gelten: fmap f . fmap g == fmap (f . g) . " ((fmap f . fmap g) <$> entwederValues)
|
||||
$ ((fmap (f . g)) <$> entwederValues)
|
||||
|
||||
|
||||
fmapKonstantTestIdentity = testCase "Functor (Konstant a): Strukturerhaltung"
|
||||
$ assertEqual "Es sollte gelten: fmap id == id . " (id konstantValue)
|
||||
$ ((fmap id) konstantValue)
|
||||
|
||||
fmapKonstantTestComposability = testCase "Functor (Konstant a): Komponierbarkeit"
|
||||
$ assertEqual "Es sollte gelten: fmap f . fmap g == fmap (f . g) . " ((fmap f . fmap g) konstantValue)
|
||||
$ ((fmap (f . g)) konstantValue)
|
||||
|
||||
|
||||
|
||||
fmapFunPBTestIdentity = testCase "Functor (FunPB a): Strukturerhaltung"
|
||||
$ assertEqual "Es sollte gelten: fmap id == id . " (runFunPB (id funPBTest) "Paula")
|
||||
$ (runFunPB ((fmap id) funPBTest) "Paula")
|
||||
|
||||
fmapFunPBTestComposability = testCase "Functor (FunPB a): Komponierbarkeit"
|
||||
$ assertEqual "Es sollte gelten: fmap f . fmap g == fmap (f . g) . " (runFunPB (fmap snd . fmap separateAreaCode $ funPBTest) "Paula")
|
||||
$ (runFunPB ((fmap (snd.separateAreaCode)) funPBTest) "Paula")
|
||||
|
||||
tests = [atleast5CharFalse,atleast5CharTrue,fmapVielleichtTestIdentity,fmapVielleichtTestComposability,fmapEntwederTestIdentity,fmapEntwederTestComposability,fmapKonstantTestIdentity,fmapKonstantTestComposability,fmapFunPBTestIdentity,fmapFunPBTestComposability]
|
||||
|
||||
main :: IO ()
|
||||
main = defaultMain tests
|
Reference in New Issue
Block a user