-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerator_test.py
44 lines (37 loc) · 1.19 KB
/
generator_test.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
import tour
import unittest
class GeneratorTest(unittest.TestCase):
def testMarksInitialLocationVisited(self):
knight = MockKnight(moves = 3)
generator = tour.Generator(knight = knight)
self.assertTrue(knight.location.visited)
def testWriteAndMove(self):
out = MockFile()
knight = MockKnight(moves = 3)
generator = tour.Generator(knight = knight)
generator.run(out = out)
self.assertEquals("3\n2\n1\n", out.s)
def testCountsSquaresVisited(self):
out = MockFile()
knight = MockKnight(moves = 3)
generator = tour.Generator(knight = knight)
self.assertEquals(3, generator.run(out = out))
class MockFile:
def __init__(self):
self.s = ""
def write(self, data):
self.s += data
class MockKnight:
def __init__(self, moves):
self.moves_left = moves
self.location = MockSquare()
def write_current_data(self, out):
out.write(str(self.moves_left))
def move(self):
self.moves_left -= 1
return (self.moves_left > 0)
class MockSquare:
def __init__(self):
self.visited = False
if __name__ == '__main__':
unittest.main()