Skip to content

Instantly share code, notes, and snippets.

@domdorn
Created December 3, 2009 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domdorn/248285 to your computer and use it in GitHub Desktop.
Save domdorn/248285 to your computer and use it in GitHub Desktop.
-- Testfaelle fuer Aufgabe 7 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
#! runhugs
-- Testfaelle fuer Aufgabe 7 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 Prelude hiding(repeat)
import Aufgabe7
import IO (stderr, hPutStr)
-- Functions -------------------------------------------------------------------
printTest :: Bool -> IO ()
printTest False = putStr ("-----> FAILED\n")
printTest True = putStr (" PASSED\n")
main =
do
putStr ("Testfaelle LVA-Leitung\n\n")
putStr ("Aufgabe 1\r\n")
printTest ( for (\n -> n*3) 5 2 == 486 )
printTest ( for (\n -> n*3) (-5) 2 == 2 ) -- fehlerfall wenn n negativ
-- angabe laut lva-leitung:
-- printTest ( while (<5) (*2) 1 == 4 )
-- 1. Durchlauf: 1 < 5 = True => 1 x 2 = 2
-- 2. Durchlauf: 2 < 5 = True => 2 x 2 = 4
-- 3. Durchlauf: 4 < 5 = True => 4 x 2 = 8
-- 4. Durchlauf: 8 < 5 = False => 8
-- d.h. => while (<5) (*2) 1 == 8 waere richtig
printTest ( while (<5) (*2) 1 == 8 )
printTest ( while (<5) (*2) 15 == 15 )
-- angabe laut lva-leitung
-- printTest ( repeat (*2) (<5) 1 == 2 )
-- 1. Durchlauf: 1 * 2 < 5 = True => not True = False => rekursion mit 2
-- 2. Durchlauf: 2 * 2 < 5 = True => not True = False => rekursion mit 4
-- 3. Durchlauf: 4 * 2 < 5 = False => not False = True => return 8
-- aenderung angabe: repeat (*2) (<5) 1 == 2
printTest ( repeat (*2) (<5) 1 == 2 )
-- angabe laut lva-leitung
-- printTest ( repeat (*2) (>5) 1 == 8 )
-- 1. Durchlauf: 1 * 2 < 5 = False => not False = True => return 2
-- aenderung angabe repeat (*2) (>5) 1 == 8
printTest ( repeat (*2) (>5) 1 == 8 )
putStr ("Eigene Testfaelle \n\n")
printTest ( for(\n -> n*3) 0 2 == 2 )
-- printTest ( show 2 'A' == "AA" )
putStr ("Testfaelle LVA-Leitung\n\n")
putStr ("Aufgabe 2\r\n")
printTest ( quickExp (2,5) == 32 )
printTest ( quickExp (3,4) == 81 )
putStr ("Eigene Testfaelle \n\n")
printTest ( quickExp (15,6) == 11390625 )
printTest ( quickExp (7,5) == 16807 )
printTest ( quickExp (7,15) == 4747561509943 )
printTest ( quickExp (7,9) == 40353607 )
putStr ("TOH 1:")
printTest ( towOfHanoi (2,'C','B','A') == [('C','B'),('C','A'),('B','A')] )
putStr ("TOH 2:")
printTest ( towOfHanoi ((-2),'A','B','C') == [] )
putStr ("TOH 3:")
printTest ( [n|n<-[1..16],length(towOfHanoi (n,'A','B','C'))+1/=2^n] == [] ) -- muss unter 5 Sekunden durchlaufen!!!!
putStr ("TOH 4:")
printTest ( towOfHanoi (0,'A','B','C') == [] )
putStr ("TOH 5:")
printTest ( (take 5$drop 100$towOfHanoi(10000,'A','B','C')) == [('C','A'),('C','B'),('A','B'),('A','C'),('B','C')] )
putStr ("TOH 6:")
printTest ( (take 5 (towOfHanoi (10000,'A','B','C'))) == [('A','B'),('A','C'),('B','C'),('A','B'),('C','A')] )
putStr ("Testfaelle LVA-Leitung")
printTest ( quickExp (2,5) == 32 )
printTest ( quickExp (3,4) == 81 )
printTest ( towOfHanoi (2,'C','B','A') == [('C','B'),('C','A'),('B','A')] )
printTest ( towOfHanoi ((-2),'A','B','C') == [] )
printTest ( let towOfHanoi = divAndConquer indHan solveHan divideHan combineHan in towOfHanoi ((-2),'A','B','C') == [] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment