-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_crawler.py
82 lines (65 loc) · 2.42 KB
/
test_crawler.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
import unittest
from crawler import Crawler
class CrawlerTests(unittest.TestCase):
def setUp(self):
maze_map = [
"000000",
"0 0 0 ",
"0 00 0",
" 0000"
]
start_x = 3
start_y = 2
self.crawler = Crawler(maze_map, start_x, start_y)
# Test 'perform' method
def test_turns_left_when_facing_wall(self):
self.crawler.perform()
self.assertEqual(self.crawler.x, 2)
self.assertEqual(self.crawler.y, 2)
"""Testing private methods"""
# Test '_movements_to_try' method
def test_list_rotator_lambda(self):
self.assertEqual(self.crawler._movements_to_try(), ["left", "up", "right", "down"])
self.crawler.pointing = "left"
self.assertEqual(self.crawler._movements_to_try(), ["down", "left", "up", "right"])
self.crawler.pointing = "down"
self.assertEqual(self.crawler._movements_to_try(), ["right", "down", "left", "up"])
self.crawler.pointing = "right"
self.assertEqual(self.crawler._movements_to_try(), ["up", "right", "down", "left"])
# Test '_move_in_order' method
def test_crawler_turns_180_degrees_when_facing_dead_end(self):
self.crawler.x = 5
self.crawler.y = 2
self.crawler._move_in_order(["left", "up", "right", "down"])
self.assertEqual(self.crawler.x, 5)
self.assertEqual(self.crawler.y, 3)
# Test '_shift' method
def test_shift_left_moves_in_right_direction(self):
self.crawler._shift("left")
self.assertEqual(self.crawler.x, 2)
self.assertEqual(self.crawler.y, 2)
self.assertEqual(self.crawler.pointing, 'left')
def test_shift_up_moves_in_right_direction(self):
self.crawler._shift("up")
self.assertEqual(self.crawler.x, 3)
self.assertEqual(self.crawler.y, 1)
self.assertEqual(self.crawler.pointing, 'up')
def test_shift_right_moves_in_right_direction(self):
self.crawler._shift("right")
self.assertEqual(self.crawler.x, 4)
self.assertEqual(self.crawler.y, 2)
self.assertEqual(self.crawler.pointing, 'right')
def test_shift_down_moves_in_right_direction(self):
self.crawler._shift("down")
self.assertEqual(self.crawler.x, 3)
self.assertEqual(self.crawler.y, 3)
self.assertEqual(self.crawler.pointing, 'down')
# Test '_is_space' method
def test_is_space_detects_space(self):
self.assertTrue(self.crawler._is_space("left"))
def test_is_space_detects_wall(self):
self.assertFalse(self.crawler._is_space("right"))
def test_is_space_detects_edge_of_maze(self):
self.crawler.x = 1
self.crawler.y = 4
self.assertFalse(self.crawler._is_space("left"))