Example #1
0
def test_move_simple():
    """Test moving a car to another location."""
    manager = SuperDuperManager()
    manager.add_car('car1', 2)
    manager.add_car('car2', 10)
    manager.add_car('car3', 20)
    manager.move_car('car2', 2, 3)
    assert manager.get_car_position('car2') == (2, 3)
    assert manager.get_car_fuel('car2') == 5
Example #2
0
    def setUp(self):
        """This is a special method that's called at the beginning of each test.

        It is used to create a SuperDuperManager object with three cars;
        these will be the cars used in subsequent tests.
        """
        self.manager = SuperDuperManager()
        self.manager.add_car('car1', 2)
        self.manager.add_car('car2', 10)
        self.manager.add_car('car3', 20)
Example #3
0
def test_move_not_enough():
    """Test moving a car that doesn't have enough fuel."""
    manager = SuperDuperManager()
    manager.add_car('car1', 2)
    manager.add_car('car2', 10)
    manager.add_car('car3', 20)
    manager.move_car('car2', 2, 3)
    manager.move_car('car1', 3, 5)
    assert manager.get_car_position('car1') == (0, 0)
    assert manager.get_car_fuel('car1') == 2
Example #4
0
 def test_car_has_initial_position_set(self, id_, fuel):
     manager = SuperDuperManager()
     manager.add_car(id_, fuel)
     self.assertEqual((0, 0), manager.get_car_position(id_))
Example #5
0
 def test_car_has_initial_fuel_set(self, id_, fuel):
     """Check that a car's initial fuel is set properly.
     """
     manager = SuperDuperManager()
     manager.add_car(id_, fuel)  # Create new car
     self.assertEqual(fuel, manager.get_car_fuel(id_))  # Check new car fuel
Example #6
0
 def test_add_car_returns_none(self, id_, fuel):
     """Check that add_car always returns None."""
     manager = SuperDuperManager()
     return_value = manager.add_car(id_, fuel)
     self.assertIsNone(return_value)
Example #7
0
class TestCar(unittest.TestCase):
    """Sample unit tests for Exercise 1."""
    def setUp(self):
        """This is a special method that's called at the beginning of each test.

        It is used to create a SuperDuperManager object with three cars;
        these will be the cars used in subsequent tests.
        """
        self.manager = SuperDuperManager()
        self.manager.add_car('car1', 2)
        self.manager.add_car('car2', 10)
        self.manager.add_car('car3', 20)

    def test_move_simple(self):
        self.manager.move_car('car2', 2, 3)
        pos = self.manager.get_car_position('car2')
        self.assertEqual(pos, (2, 3))
        self.assertEqual(self.manager.get_car_fuel('car2'), 5)

    def test_move_not_enough(self):
        self.manager.move_car('car1', 3, 5)
        pos = self.manager.get_car_position('car1')
        self.assertEqual(pos, (0, 0))
        self.assertEqual(self.manager.get_car_fuel('car1'), 2)

    def test_move_negative(self):
        self.manager.move_car('car3', -2, -3)
        pos = self.manager.get_car_position('car3')
        self.assertEqual(pos, (-2, -3))
        self.assertEqual(self.manager.get_car_fuel('car3'), 15)
Example #8
0
def test_car_initial_position(id_, fuel):
    manager = SuperDuperManager()
    manager.add_car(id_, fuel)
    assert (0, 0) == manager.get_car_position(id_)
Example #9
0
def test_car_initial_fuel(id_, fuel):
    """Check that a car's initial fuel is set properly.
    """
    manager = SuperDuperManager()
    manager.add_car(id_, fuel)
    assert fuel == manager.get_car_fuel(id_)
Example #10
0
def test_add_car_returns_none(id_, fuel):
    """Check that add_car always returns None."""
    manager = SuperDuperManager()
    assert manager.add_car(id_, fuel) is None
Example #11
0
def test_move_negative():
    """Test moving a car to a position with negative coordinates."""
    manager = SuperDuperManager()
    manager.add_car('car1', 2)
    manager.add_car('car2', 10)
    manager.add_car('car3', 20)
    manager.move_car('car2', 2, 3)
    manager.move_car('car3', -2, -3)
    assert manager.get_car_position('car3') == (-2, -3)
    assert manager.get_car_fuel('car3') == 15
Example #12
0
def test_dispatch():
    """Test moving a car that doesn't have enough fuel."""
    manager = SuperDuperManager()
    manager.add_car('car1', 30)
    manager.add_car('car2', 30)
    manager.add_car('car3', 20)
    manager.move_car('car2', 6, 2)
    manager.move_car('car1', 3, 5)
    manager.dispatch(6, 6)
    assert manager.get_car_position('car1') == (6, 6)