Skip to content

Commit 5f8cf35

Browse files
committed
sp
1 parent e8f00a2 commit 5f8cf35

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

tests/review_schuifpuzzelTest.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import checkpy.tests as t
2+
import checkpy.lib as lib
3+
import checkpy.assertlib as asserts
4+
from checkpy.entities import exception
5+
6+
# from _extensions import *
7+
8+
@t.test(0)
9+
def checks_set_board(test):
10+
def testMethod():
11+
set_board = lib.getFunction("create_board", test.fileName)
12+
if set_board() == [
13+
[15, 14, 13, 12],
14+
[11, 10, 9, 8],
15+
[7, 6, 5, 4],
16+
[3, 1, 2, 0],
17+
]:
18+
return True
19+
else:
20+
return False
21+
22+
test.test = testMethod
23+
test.description = lambda: "'create_board' werkt correct"
24+
25+
26+
@t.test(1)
27+
def checks_is_won(test):
28+
def testMethod():
29+
is_won = lib.getFunction("is_won", test.fileName)
30+
if (
31+
is_won([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]])
32+
and not is_won(
33+
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 0, 15]]
34+
)
35+
):
36+
return True
37+
else:
38+
return False
39+
40+
test.test = testMethod
41+
test.description = lambda: "'is_won' werkt correct"
42+
43+
44+
@t.test(2)
45+
def checks_move_tile(test):
46+
def testMethod():
47+
move_tile = lib.getFunction("move_tile", test.fileName)
48+
if not (
49+
move_tile([
50+
[15, 14, 13, 12],
51+
[11, 10, 9, 8],
52+
[7, 6, 5, 4],
53+
[3, 1, 2, 0],
54+
], 2) == True
55+
and move_tile([
56+
[15, 14, 13, 12],
57+
[11, 10, 9, 8],
58+
[7, 6, 5, 4],
59+
[3, 1, 2, 0],
60+
], 14) == False
61+
):
62+
return False, "geeft de verkeerde return als een move wel/niet mogelijk is"
63+
64+
board = [
65+
[15, 14, 13, 12],
66+
[11, 10, 9, 8],
67+
[7, 6, 5, 4],
68+
[3, 1, 2, 0],
69+
]
70+
move_tile(board, 2)
71+
if not board == [
72+
[15, 14, 13, 12],
73+
[11, 10, 9, 8],
74+
[7, 6, 5, 4],
75+
[3, 1, 0, 2],
76+
]:
77+
return False, "het bord wordt niet correct bijgewerkt na een move"
78+
79+
return True
80+
81+
test.test = testMethod
82+
test.description = lambda: "'move_tile' werkt correct"
83+
84+
@t.test(10)
85+
def check_win(test):
86+
def testMethod():
87+
steps = ["4","5","6","1","2","4","5","6",
88+
"1","2","3","7","11","10","9","1",
89+
"2","3","4","5","6","8","1","2",
90+
"3","4","7","11","10","9","14",
91+
"13","12","1","2","3","4","14",
92+
"13","12","1","2","3","4","14",
93+
"13","12","1","2","3","4","12",
94+
"9","15","1","2","3","4","12","9",
95+
"13","14","9","13","14","7","5",
96+
"9","13","14","15","10","11","5",
97+
"9","13","7","11","5","9","13",
98+
"7","11","15","10","5","9","13",
99+
"15","11","8","6","7","8","14",
100+
"12","6","7","8","14","12","6",
101+
"7","8","14","15","11","10","6",
102+
"7","8","12","15","11","10","15",
103+
"11","14","12","11","15","10",
104+
"14","15","11","12"]
105+
106+
try:
107+
output = lib.outputOf(test.fileName, stdinArgs=steps, overwriteAttributes=[("__name__", "__main__")]).splitlines()
108+
except exception.InputError:
109+
return False, "je programma lijkt niet te werken met de juiste oplossing voor het 4x4-board"
110+
111+
return asserts.contains(output[-1], 'Gefeliciteerd') or asserts.contains(output[-1], 'Congratulations')
112+
113+
test.test = testMethod
114+
test.description = lambda: "spel werkt en is uit te spelen"

0 commit comments

Comments
 (0)