-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pentominoes.py
executable file
·88 lines (56 loc) · 1.74 KB
/
test_pentominoes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
import unittest
import pentominoes
class TestPentominoes(unittest.TestCase):
def test_print(self):
p = pentominoes.make_piece('f')
p = p.moveto(0, 0)
print p
def test_equal(self):
p = pentominoes.make_piece('f')
q = p.moveto(10, 10)
self.assertTrue(p == p)
self.assertFalse(p == q)
def test_generate(self):
b = pentominoes.Board()
p = pentominoes.make_piece('i')
for i in pentominoes.orientations(p):
print '=' * 33
print i
def test_transformations(self):
points = ((0, 0), (1, 0), (2, 0), (0, 1), (2, 1))
p = pentominoes.Piece(points)
p2 = p.moveto(20, 20)
print p
print p2
p3 = p.moveto(10, 10).flip_x().moveto(0, 0)
print p3
p4 = p.clockwise_90().moveto(0, 0)
print p4
p5 = p.counterclockwise_90().moveto(0, 0)
print p5
def test_translation(self):
p = pentominoes.make_piece('f')
x = y = 0
p = p.moveto(x, y)
while p._maxy < 8:
while p._maxx < 8:
print '[minx = %d, miny = %d, maxx = %d, maxy = %d]' % (p._minx, p._miny, p._maxx, p._maxy)
x += 1
p = p.moveto(x, y)
x = 0
y += 1
p = p.moveto(x, y)
def test_board(self):
b = pentominoes.Board(10, 5)
b.mark((1, 1))
b.mark((5, 1))
b.connect((9, 0), (9, 4))
b.connect((0, 4), (9, 4))
def test_place_piece(self):
b = pentominoes.Board(8, 8)
p = pentominoes.make_piece('f')
b.place_piece(p, 0, 0)
b.print_()
if __name__ == '__main__':
unittest.main()