test_rover.py
1.3 KB
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
import os.path
import unittest
from rover import Rover
class RoversTestCase(unittest.TestCase):
def setUp(self):
self.assertTrue(os.path.exists('input.txt'), msg='Inputfile "input.txt"'
' does not exist')
self.instructions = []
self.rovers = []
with open('input.txt', 'r') as f:
self.boundaries = f.readline()
for line in f:
line = line.strip()
if line:
self.instructions.append(line)
it = iter(self.instructions)
for start, route in zip(it, it):
self.rovers.append(Rover(start=start, route=route,
boundaries=self.boundaries))
def test_instructions(self):
# There should be instructions
self.assertNotEqual(len(self.instructions), 0, msg='No instructions '
'found')
# The number of instructions should be even (i.e. every Rover should
# have a starting position and some movement instructions)
self.assertEqual(len(self.instructions) % 2, 0, msg='Missing some '
'instructions')
if __name__ == '__main__':
unittest.main()