-
-
Save lewurm/244995 to your computer and use it in GitHub Desktop.
This file contains hidden or 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( 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 ("Testfaelle LVA-Leitung\n\n") | |
-- putStr ("Aufgabe 2\r\n") | |
--eval (VSub (VCar 'a') (VAdd (VOpd 17) (VOpd 4))) == (VSub (VCar 'a') (VOpd 21)) | |
--eval (VSub (VCar 'a') (VAdd (VVar 'b') (VOpd 4))) == (VSub (VCar 'a') (VAdd (VVar 'b') (VOpd 4))) | |
-- | |
--evalInState (VSub (VCar 'a') (VAdd (VOpd 17) (VOpd 4))) (State [('a',30),('b',2),('a',5)]) == (VOpd 9) | |
--evalInState (VSub (VCar 'a') (VAdd (VVar 'b') (VOpd 4))) (State [('b',2)]) == (VSub (VCar 'a') (VOpd 6)) | |
-- | |
--(==) (VSub (VCar 'a') (VAdd (VOpd 17) (VOpd 4))) (VSub (VCar 'b') (VAdd (VOpd 17) (VOpd 4))) == True | |
--(==) (VSub (VCar 'a') (VAdd (VOpd 4) (VOpd 17))) (VSub (VCar 'a') (VAdd (VOpd 17) (VOpd 4))) == False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment