test_rover.py 1.3 KB
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()