Beispiel #1
0
    def test_place_rover(self):
        mars = Mars("5 5")

        rover = Rover("1 1 N")
        mars.place_rover(rover)

        self.assertEqual([rover], mars.get_rovers())

        rover2 = Rover("6 1 N")
        mars.place_rover(rover2)

        self.assertEqual([rover], mars.get_rovers())
Beispiel #2
0
class MarsScentingTest(unittest.TestCase):
    def setUp(self):
        self.mars = Mars(5, 5)

    def test_unscented_locations_return_false(self):
        self.assertFalse(self.mars.location_is_scented(1, 2))
        self.assertFalse(self.mars.location_is_scented(-1, 4))
        self.assertFalse(self.mars.location_is_scented(7, 6))

    def test_adding_scented_locations(self):
        self.mars.add_scented_location(2, 2)
        self.assertEqual(self.mars.scented_locations, [[2, 2], ])

    def test_scented_locations_return_true(self):
        self.mars.scented_locations = [[2, 2], ]
        self.assertTrue(self.mars.location_is_scented(2, 2))

        self.mars.add_scented_location(1, 3)
        self.assertTrue(self.mars.location_is_scented(1, 3))
Beispiel #3
0
class MarsScentingTest(unittest.TestCase):
    def setUp(self):
        self.mars = Mars(5, 5)

    def test_unscented_locations_return_false(self):
        self.assertFalse(self.mars.location_is_scented(1, 2))
        self.assertFalse(self.mars.location_is_scented(-1, 4))
        self.assertFalse(self.mars.location_is_scented(7, 6))

    def test_adding_scented_locations(self):
        self.mars.add_scented_location(2, 2)
        self.assertEqual(self.mars.scented_locations, [
            [2, 2],
        ])

    def test_scented_locations_return_true(self):
        self.mars.scented_locations = [
            [2, 2],
        ]
        self.assertTrue(self.mars.location_is_scented(2, 2))

        self.mars.add_scented_location(1, 3)
        self.assertTrue(self.mars.location_is_scented(1, 3))
Beispiel #4
0
from redcode import BattleProgram
from mars import Mars

programA = BattleProgram("DWARF", 1, "battle-programs/dwarf.rc")
programB = BattleProgram("IMP", 0, "battle-programs/imp.rc")

N = 20

mars = Mars(programA, programB, N, num_it=20)
mars.execute_core_war()
Beispiel #5
0
def test_init():
    mars = Mars('file1.json', 'file2.json')
    assert mars
Beispiel #6
0
def test_receive():
    mars = Mars('file.json', 'file2.json')
    data = mars.receive()
    assert data['name'] == 'Walter'
    cars = Mars('Renault', 'Fiat')
    assert cars.receive() is None
Beispiel #7
0
def test_send():
    mars = Mars('file.json', 'file2.json')
    json_dict = {'name': 'Walter', 'age': '38', 'place': 'Milan'}
    assert mars.send(json_dict) == 1
    assert mars.send('Renault') is None
Beispiel #8
0
 def test_locations_too_great_off_map(self):
     mars = Mars(6, 2)
     self.assertFalse(mars.location_exists(7, 1))
     self.assertFalse(mars.location_exists(6, 3))
Beispiel #9
0
 def test_negative_locations_off_map(self):
     mars = Mars(3, 5)
     self.assertFalse(mars.location_exists(3, -2))
Beispiel #10
0
 def setUp(self):
     self.mars = Mars(5, 5)
Beispiel #11
0
 def test_valid_locations_recognised(self):
     mars = Mars(2, 1)
     self.assertTrue(mars.location_exists(1, 1))
     self.assertTrue(mars.location_exists(0, 1))
Beispiel #12
0
        robot.is_lost = True
        return robot, mars

    robot.move_forward()
    return robot, mars


def _display_results(robots):
    """
    A utility method that nicely formats and prints state of robots
    :param robots - The robots we want to display
    """
    for robot in robots:
        result = "{0} {1} {2} {3}".format(
            robot.current_x,
            robot.current_y,
            robot.current_orientation,
            "LOST" if robot.is_lost else '',
        )

        print result


if __name__ == '__main__':
    max_coordinates, robots_config = ingest_from_file('instructions.txt')
    mars = Mars(**max_coordinates)
    robots = [Robot(**robot_config) for robot_config in robots_config]

    deployed_robots = deploy_robots(mars=mars, robots=robots)
    _display_results(robots=deployed_robots)
Beispiel #13
0
 def test_locations_too_great_off_map(self):
     mars = Mars(6, 2)
     self.assertFalse(mars.location_exists(7, 1))
     self.assertFalse(mars.location_exists(6, 3))
Beispiel #14
0
 def test_negative_locations_off_map(self):
     mars = Mars(3, 5)
     self.assertFalse(mars.location_exists(3, -2))
Beispiel #15
0
 def setUp(self):
     self.mars = Mars(5, 5)
Beispiel #16
0
 def test_valid_locations_recognised(self):
     mars = Mars(2, 1)
     self.assertTrue(mars.location_exists(1, 1))
     self.assertTrue(mars.location_exists(0, 1))