Created
December 12, 2009 17:54
-
-
Save domdorn/254982 to your computer and use it in GitHub Desktop.
Testfaelle fuer Aufgabe 8 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
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 8 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 Aufgabe8 | |
import IO (stderr, hPutStr) | |
-- Functions ------------------------------------------------------------------- | |
printTest :: Bool -> IO () | |
printTest False = putStr ("-----> FAILED\n") | |
printTest True = putStr (" PASSED\n") | |
cb1 :: Chessboard | |
cb1 = [[' ','B',' ',' ',' ','B','B',' '], | |
['B',' ',' ',' ',' ','B',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ','B',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ','B',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ','B',' ',' ',' ',' ',' ']] | |
cb2 :: Chessboard | |
cb2 = [[' ','B',' ',' ',' ','B','B',' '], | |
['B',' ',' ',' ',' ','B',' ',' '], | |
[' ',' ','c',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ','b'], | |
[' ','B',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ','a',' ','B',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ','B',' ',' ',' ',' ',' ']] | |
cb3 :: Chessboard | |
cb3 = [[' ',' ','B',' ',' ',' ',' ',' '], -- (1,3) | |
[' ',' ',' ',' ','B',' ',' ',' '], -- (2,5) | |
[' ',' ',' ',' ',' ',' ','B',' '], -- (3,7) | |
['B',' ',' ',' ',' ',' ',' ',' '], -- (4,1) | |
[' ',' ',' ','B',' ',' ',' ',' '], -- (5,4) | |
[' ','B',' ',' ',' ',' ',' ',' '], -- (6,2) | |
[' ',' ',' ',' ',' ',' ',' ','B'], -- (7,8) | |
[' ',' ',' ',' ',' ','B',' ',' ']] -- (8,6) | |
cb8 :: Chessboard | |
cb8 = [[' ',' ','B',' ',' ',' ',' ',' '], -- (1,3) | |
['B',' ',' ',' ',' ',' ',' ',' '], -- (2,1) | |
[' ',' ',' ',' ',' ',' ','B',' '], -- (3,7) | |
[' ',' ',' ',' ','B',' ',' ',' '], -- (4,5) | |
[' ',' ',' ',' ',' ',' ',' ','B'], -- (5,8) | |
[' ','B',' ',' ',' ',' ',' ',' '], -- (6,2) | |
[' ',' ',' ','B',' ',' ',' ',' '], -- (7,4) | |
[' ',' ',' ',' ',' ','B',' ',' ']] -- (8,6) | |
cb4 :: Chessboard | |
cb4 = [[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' ']] | |
cb5 :: Chessboard | |
cb5 = [['B',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ','B',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ','B',' '], | |
[' ',' ',' ','B',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ','B'], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ','B',' ',' ',' ',' ',' ',' ']] | |
cb6 :: Chessboard | |
cb6 = [['B',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ','B',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ','B',' ',' ',' '], -- 3,5 wird von 6,8 bedroht! | |
[' ',' ',' ',' ',' ',' ','B',' '], | |
[' ',' ',' ','B',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ','B'], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ','B',' ',' ',' ',' ',' ',' ']] | |
cb7 :: Chessboard | |
cb7 = [ " B", | |
" B ", | |
"B ", | |
" B ", | |
" B ", | |
" B ", | |
" B ", | |
" B "] | |
cbEmpty :: Chessboard | |
cbEmpty = [[]] | |
cbIncorrectRows1 :: Chessboard | |
cbIncorrectRows1 = [[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' ', ' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' ']] | |
cbIncorrectRows2 :: Chessboard | |
cbIncorrectRows2 = [[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ', ' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' ']] | |
cbIncorrectRows3 :: Chessboard | |
cbIncorrectRows3 = [[' ',' ',' ',' ',' ',' ',' ',' '], -- just 7 rows! | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' '], | |
[' ',' ',' ',' ',' ',' ',' ',' ']] | |
sdk1 :: Sudoku | |
sdk1 = [ [1,3,2,4], -- 2x2 sudoku | |
[2,0,3,0], | |
[3,1,0,2], | |
[0,2,0,3] ] | |
sdk2 :: Sudoku | |
sdk2 = [ [1,5,2,4], | |
[2,0,3,0], | |
[3,1,0,9], | |
[0,2,0,3] ] | |
sdk3 :: Sudoku | |
sdk3 = [ [1,3,2,4], | |
[2,4,3,1], | |
[3,1,4,2], | |
[4,2,1,3] ] | |
sdk4 :: Sudoku | |
sdk4 = [ [0,0,0,0], | |
[0,0,0,0], | |
[0,0,0,0], | |
[0,0,0,0] ] | |
main = | |
do | |
putStr ( "Testfaelle Aufgabe 8: Chessboard + Sudoku\n\n") | |
putStr ("Aufgabe 1\r\n") | |
putStr ("isValidChessboard:\t Testfaelle LVA-Leitung\n\n"); | |
printTest( isValidChessboard cb1 == True ) | |
printTest( isValidChessboard cb2 == False ) | |
-- eigene tests | |
putStr ("isValidChessboard:\t Testfaelle domdorn\n\n"); | |
printTest( isValidChessboard cbEmpty == False ) | |
printTest( isValidChessboard cbIncorrectRows1 == False ) | |
printTest( isValidChessboard cbIncorrectRows2 == False ) | |
printTest( isValidChessboard cbIncorrectRows3 == False ) | |
printTest( isValidChessboard cb5 == True ) | |
putStr ("threatens:\t Testfaelle LVA-Leitung\n\n") | |
printTest( threatens cb1 (1,1) == [(1,2),(2,1)] ) | |
printTest( threatens cb1 (0,5) == [] ) | |
putStr ("threatens:\t Testfaelle domdorn\n\n") | |
printTest( threatens cb1 (2,2) == [(1,2),(2,1),(2,6), (5,2) ] ) | |
printTest( threatens cb1 (1,3) == [(1,2),(1,6),(8,3)] ) | |
putStr("threatens: figuren duerfen sich nicht selbst bedrohen\n") | |
printTest( threatens cb5 (1,1) == [] ) | |
printTest( threatens cb5 (2,3) == [] ) | |
printTest( threatens cb5 (4,7) == [] ) | |
printTest( threatens cb5 (5,4) == [] ) | |
printTest( threatens cb5 (6,8) == [] ) | |
printTest( threatens cb5 (8,2) == [] ) | |
putStr("threatens: p/q ausserhalb des spielfeldes\n") | |
printTest( threatens cb1 (3,0) == [] ) | |
printTest( threatens cb1 (3,9) == [] ) | |
printTest( threatens cb1 (9,5) == [] ) | |
-- threatens alle dimensionne | |
putStr("threatens: links oben diagonal\n") | |
printTest ( threatens (ibwb emptyBoard [(1,1)] ) (2,2) == [(1,1)] ) | |
putStr("threatens: rechts oben diagonal\n") | |
printTest ( threatens (ibwb emptyBoard [(1,3)] ) (2,2) == [(1,3)] ) | |
putStr("threatens: links unten diagonal\n") | |
printTest ( threatens (ibwb emptyBoard [(3,1)] ) (2,2) == [(3,1)] ) | |
putStr("threatens: rechts unten diagonal\n") | |
printTest ( threatens (ibwb emptyBoard [(4,4)] ) (2,2) == [(4,4)] ) | |
putStr("threatens: unten\n") | |
printTest ( threatens (ibwb emptyBoard [(3,2)] ) (2,2) == [(3,2)] ) | |
putStr("threatens: oben\n") | |
printTest ( threatens (ibwb emptyBoard [(1,2)] ) (2,2) == [(1,2)] ) | |
putStr("threatens: links \n") | |
printTest ( threatens (ibwb emptyBoard [(2,1)] ) (2,2) == [(2,1)] ) | |
putStr("threatens: rechts \n") | |
printTest ( threatens (ibwb emptyBoard [(2,3)] ) (2,2) == [(2,3)] ) | |
putStr("threatens: self\n") | |
printTest ( threatens (ibwb emptyBoard [(2,2)] ) (2,2) == [] ) | |
putStr("threatens: ungueltige boards\n") | |
printTest ( threatens (ibwb emptyBoard [(2,2),(2,3)] ) (2,2) == [] ) -- ungueltig | |
printTest( threatens cbEmpty (1,1) == [] ) | |
printTest( threatens cbIncorrectRows1 (1,1) == [] ) | |
printTest( threatens cbIncorrectRows2 (1,1) == [] ) | |
printTest( threatens cbIncorrectRows3 (1,1) == [] ) | |
putStr ("noThreats:\t Testfaelle LVA-Leitung\n\n") | |
printTest( noThreats cb1 == False ) | |
printTest( noThreats cb2 == False ) | |
putStr ("noThreats:\t Testfaelle domdorn\n\n") | |
printTest( noThreats cb5 == True ) | |
printTest( noThreats cb6 == False ) -- 3,5 wird von 6,8 bedroht | |
printTest( noThreats cb7 == True ) | |
putStr ("fullBoard:\t Testfaelle LVA-Leitung\n\n") | |
printTest( fullBoard [(1,1),(2,1)] == cb4 ) | |
putStr ("fullBoard [(1,3),(6,2)] 1./2. Loesung\n") | |
printTest( fullBoard [(1,3),(6,2)] == cb3 || fullBoard [(1,3),(6,2)] == cb8 ) | |
-- putStr ("fullBoard:\t domdorn\n\n") | |
-- putStr ("fullBoard [(1,3),(6,2)] 2. Loesung ") | |
-- printTest( fullBoard [(1,3),(6,2)] == cb8 ) | |
putStr ("fullBoard:\t Foxtur\n") | |
printTest( fullBoard [(1,8),(2,4),(3,1),(4,3),(5,6),(6,2),(7,7),(8,5)] == cb7 ) | |
putStr ("\n\n=================================\n") | |
putStr ("Aufgabe 2\n\n") | |
putStr ("isValidStart:\t Testfaelle LVA-Leitung\n\n") | |
printTest( isValidStart 2 sdk1 == True ) | |
printTest( isValidStart 2 sdk2 == False ) | |
printTest( isValidStart 2 sdk3 == True ) | |
printTest( isValidStart 3 sdk3 == False ) | |
putStr ("isValidStart:\t Testfaelle domdorn\n\n") | |
putStr("isValid:\t Testfaelle LVA-Leitung\n\n") | |
putStr("isValid:\t Testfaelle domdorn\n\n") | |
putStr("solve:\t Testfaelle LVA-Leitung\n\n") | |
printTest( solve 2 sdk2 == sdk3 ) | |
printTest( solve 3 sdk2 == sdk4 ) | |
putStr("solve:\t Testfaelle domdorn\n\n") | |
-- hilfsmethoden | |
ibwb :: Chessboard -> [(Int, Int)] -> Chessboard | |
ibwb b [] = b | |
ibwb b (x:xs) | |
| threatens b x == [] = ibwb (sb b x) xs | |
| otherwise = [] | |
sb :: Chessboard -> (Int, Int) -> Chessboard | |
sb b (p,q) | |
| p < 1 || p > 8 || q < 1 || q > 8 = b | |
| otherwise = [ b!!(r-1) | r <- [1..(p-1)] ] ++ [ [ b!!(p-1)!!(c-1) | c <- [1..(q-1)] ] ++ "B" ++ [ b!!(p-1)!!(c-1) | c <- [(q+1)..8] ] ] ++ [ b!!(r-1) | r <- [(p+1)..8] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment