Created
November 28, 2009 19:25
-
-
Save domdorn/244610 to your computer and use it in GitHub Desktop.
Testfaelle fuer Aufgabe 6 der LVA 185.161 Funktionale Programmierung im WS09/10 an der TU Wien
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! runhugs | |
-- Testfaelle fuer Aufgabe 6 der LVA 185.161 Funktionale Programmierung im WS09/10 | |
-- an der Technischen Universitaet Wien | |
-- Aufgabenstellung: http://www.complang.tuwien.ac.at/knoop/fp185161_ws0910.html | |
-- Module ---------------------------------------------------------------------- | |
module Main where | |
-- Imports --------------------------------------------------------------------- | |
import Aufgabe6 | |
import IO (stderr, hPutStr) | |
-- Functions ------------------------------------------------------------------- | |
printTest :: Bool -> IO () | |
printTest False = putStr ("-----> FAILED\n") | |
printTest True = putStr (" PASSED\n") | |
main = | |
do | |
-- eigene Hilfsfunktionen: | |
-- wir haben in unserem Programm drei Hilfsfunktionen eingebaut: | |
-- equalExpr :: Expr -> Expr -> Bool ueberprueft zwei Expressions auf gleichheit (ohne summengleichheit) | |
-- subExpr :: Expr -> Expr -> Bool ueberprueft, ob eine Expression in der anderen enthalten ist | |
-- sumExpr :: Expr -> Int gibt den Wert der Expression zurueck | |
-- Bei einer normalen Aufgabenstellung koennte man sich equalExpr und subExpr sparen und diese einfach | |
-- mit den Ueberladenen (==) und (<) Operatoren abdecken. Da sich die Anforderungen an (==), (<), und (<=) | |
-- allerdings wiedersprechen, benoetigen wir leider solche Hilfsfunktionen. | |
-- putStr ("Expression ist gleich\n\n") | |
-- printTest( equalExpr (Opd 5) (Opd 3) == False ) | |
-- printTest( equalExpr (Add (Opd 3) (Opd 8)) (Add (Opd 3) (Opd 8)) == True ) | |
-- printTest( equalExpr (Add (Opd 3) (Opd 8)) (Add (Opd 8) (Opd 3)) == False ) | |
-- | |
-- printTest( equalExpr (Sub (Opd 3) (Opd 8)) (Sub (Opd 3) (Opd 8)) == True ) | |
-- printTest( equalExpr (Sub (Opd 3) (Opd 8)) (Sub (Opd 8) (Opd 3)) == False ) | |
-- | |
-- putStr ("teilExpression Tests \n\n") | |
-- printTest( subExpr (Opd 5) (Opd 5) == True) | |
-- printTest( subExpr (Add (Opd 5) (Opd 6)) (Add (Opd 5) (Opd 6)) == False) -- equals ergibt true, aber keine subexpr | |
-- printTest( subExpr (Opd 5) (Add (Opd 5) (Opd 6) ) == True) | |
putStr ("Testfaelle LVA-Leitung\n\n") | |
putStr ("Aufgabe 1\r\n") | |
printTest ( (==) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) == True ) | |
printTest ( (==) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) (Add (Neg (Opd 5)) (Opd 4)) == True ) | |
printTest ( (<) (Sub (Opd 7) (Opd 3)) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) == True ) | |
printTest ( (<) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) (Add (Neg (Opd 5)) (Opd 4)) == False ) | |
printTest ( (<=) (Sub (Opd 7) (Opd 3)) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) == True ) | |
printTest ( (<=) (Add (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) (Add (Neg (Opd 5)) (Opd 4)) == True ) | |
putStr ("Eigene Tests\r\n") | |
putStr ( "Equals Funktionen\r\n") | |
-- Struktur (und wert) stimmen ueberein | |
printTest( (==) (Add (Opd 3) (Opd 8)) (Add (Opd 3) (Opd 8) ) == True ) | |
-- Wert stimmt ueber ein, Struktur nicht | |
printTest( (==) (Add (Opd 3) (Opd 8)) (Add (Opd 8) (Opd 3) ) == True ) | |
printTest( (==) (Neg (Opd 5)) (Opd (-5) ) == True ) | |
--printTest( equalExpr ( (Add (Opd 3) (Opd 8)) (Add (Opd 3) (Opd 8) ) == True ) | |
-- printTest( equalExpr ( (Add (Opd 3) (Opd 8)) (Add (Opd 8) (Opd 3) ) == False ) | |
printTest( (==) (Opd 5) (Add (Opd 3) (Opd 2) ) == True ) | |
printTest( (==) (Add (Opd 5) (Opd 3) ) (Opd 8) == True ) | |
printTest( (==) (Sub (Opd 5) (Opd 3) ) (Opd 2) == True ) | |
printTest( (==) (Neg (Opd 5)) (Sub (Opd 5) (Opd 10) ) == True ) | |
putStr ("Kleiner Funktionen\r\n") | |
printTest( (<) (Opd 5) (Opd 3) == False ) | |
printTest( (>) (Opd 5) (Opd 3) == True ) | |
printTest( (>) (Opd 5) (Opd 5) == False ) | |
printTest( (>) (Opd 4) (Opd (-1)) == True ) | |
printTest( (<) (Opd 4) (Opd (-1)) == False ) | |
printTest( (<) (Opd (-4) ) (Opd (-1)) == True ) | |
printTest( (<) (Add (Opd 5) (Opd 3)) (Add (Opd 5) (Opd 3)) == False ) -- kein _echter_ teilausdruck | |
printTest( (<) (Add (Opd 4) (Opd 3)) (Add (Opd 5) (Opd 3)) == True ) -- echt kleiner | |
-- kein Teilausdruck und linker teil (-9) nicht echt kleiner als rechter teil (-9) | |
printTest ( (<) (Sub (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) (Sub (Neg (Opd 5)) (Opd 4)) == False ) | |
-- kein Teilausdruck und linker teil (-9) echt kleiner als rechter teil (-8) | |
printTest ( (<) (Sub (Neg (Opd 5)) (Sub (Opd 7) (Opd 3))) (Sub (Neg (Opd 5)) (Opd 3)) == True ) | |
putStr( "KleinerGleich Funktionen\r\n") | |
printTest( (<=) (Opd 5) (Opd 3) == False ) | |
printTest( (>=) (Opd 5) (Opd 3) == True ) | |
printTest( (>=) (Opd 5) (Opd 5) == True ) | |
printTest( (>=) (Opd 4) (Opd (-1)) == True ) | |
printTest( (<=) (Opd 4) (Opd (-1)) == False ) | |
printTest( (<=) (Opd (-4) ) (Opd (-1)) == True ) | |
putStr ("Aufgabe 2\r\n") | |
putStr ("Testfaelle LVA-Leitung\n\n") | |
printTest( eval (VSub (VVar 'a') (VAdd (VOpd 17) (VOpd 4))) == (VSub (VVar 'a') (VOpd 21)) ) | |
printTest( eval (VSub (VVar 'a') (VAdd (VVar 'b') (VOpd 4))) == (VSub (VVar 'a') (VAdd (VVar 'b') (VOpd 4))) ) | |
printTest( evalInState (VSub (VVar 'a') (VAdd (VOpd 17) (VOpd 4))) (State [('a',30),('b',2),('a',5)]) == (VOpd 9) ) | |
printTest( evalInState (VSub (VVar 'a') (VAdd (VVar 'b') (VOpd 4))) (State [('b',2)]) == (VSub (VVar 'a') (VOpd 6)) ) | |
printTest( (==) (VSub (VVar 'a') (VAdd (VOpd 17) (VOpd 4))) (VSub (VVar 'b') (VAdd (VOpd 17) (VOpd 4))) == True ) | |
printTest( (==) (VSub (VVar 'a') (VAdd (VOpd 4) (VOpd 17))) (VSub (VVar 'a') (VAdd (VOpd 17) (VOpd 4))) == False ) | |
putStr ("Eigene Testfaelle\n\n") | |
printTest( eval (VNeg (VVar 'a') ) == (VNeg (VVar 'a') ) ) | |
printTest( eval (VSub (VAdd ( VOpd 3) ( VAdd (VOpd 5) (VVar 'a'))) ( VAdd (VOpd 6) (VVar 'b') )) == (VSub (VAdd ( VOpd 3) ( VAdd (VOpd 5) (VVar 'a'))) ( VAdd (VOpd 6) (VVar 'b') )) ) | |
printTest( eval (VNeg (VOpd 5)) == (VOpd (-5) ) ) | |
-- die folgenden testfaelle betrachten ein "optimiertes eval", siehe Thread http://www.informatik-forum.at/showthread.php?p=617980&posted=1#post617980 | |
-- | |
-- printTest( eval ( | |
-- VAdd | |
-- ( | |
-- VAdd | |
-- ( | |
-- VNeg | |
-- ( | |
-- VAdd ( VOpd 3) (VOpd 7) | |
-- ) | |
-- ) | |
-- ( | |
-- VAdd (VOpd 8) (VVar 'a') | |
-- ) | |
-- ) | |
-- | |
-- ( VSub | |
-- (VOpd 5) | |
-- (VAdd (VOpd 5) (VVar 'b')) | |
-- ) | |
-- ) == | |
-- ( | |
-- VAdd ( VAdd ( VOpd (-2) ) (VVar 'a')) ( VVar 'b') | |
-- ) | |
-- ) | |
-- | |
-- optimierendes eval... notwendig? | |
-- printTest( eval (VSub (VAdd ( VOpd 3) ( VAdd (VOpd 5) (VVar 'a'))) ( VAdd (VOpd 6) (VVar 'b') )) == ( VSub ( VAdd( VOpd 8) (VVar 'a')) (VAdd (VOpd 6) (VVar 'b')) ) ) | |
-- printTest( eval ( VAdd ( VAdd ( VNeg (VAdd ( VOpd 3) (VOpd 7))) (VAdd (VOpd 8) (VVar 'a')))( VSub (VOpd 5) (VAdd (VOpd 5) (VVar 'b')))) == (VAdd ( VAdd ( VOpd (-2) ) (VVar 'a')) ( VVar 'b'))) | |
-- dieser Testfall ist richtig, wenn nach der einfachen substitution noch einmal eval aufgerufen wird | |
printTest( evalInState (VAdd (VVar 'b') (VVar 'a') ) (State [('a',30), ('b',20)]) == VOpd 50 ) | |
printTest( evalInState (VAdd (VVar 'b') (VVar 'a') ) (State [('a',30)]) == VAdd (VVar 'b') (VOpd 30) ) | |
printTest( (==) (VAdd (VVar 'b') (VVar 'a') ) (VAdd (VVar 'b') (VVar 'a') ) == True) | |
printTest( (==) (VAdd (VVar 'b') (VVar 'a') ) (VAdd (VVar 'a') (VVar 'b') ) == True) -- Struktur gleich, unterscheiden sich aber in den variablen (auch wenns bei (+) egal ist) | |
printTest( (==) (VSub (VVar 'a') (VAdd (VOpd 4) (VOpd 17))) (VSub (VVar 'a') (VOpd 21)) == False ) | |
printTest( (==) (eval (VSub (VVar 'a') (VAdd (VOpd 4) (VOpd 17)))) (VSub (VVar 'a') (VOpd 21)) == True ) | |
printTest( (==) (evalInState (VSub (VVar 'a') (VAdd (VOpd 4) (VOpd 17))) (State [('a',22)])) (VOpd 1) == True ) | |
putStr("Fertig!\n\n\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment