コード例 #1
0
class EasyTestCase(unittest.TestCase):
    def setUp(self):
        self.car = Car()
        self.car.start_car()

    def test_easy_input(self):

        self.car.add_speed()
        self.car.add_speed()
        self.car.add_speed()
        self.car.add_speed()
        self.assertEqual(self.car.current_speed(), 20)

    def test_easy_input_two(self):

        self.car.add_speed()
        self.car.add_speed()
        self.car.stop()
        self.assertEqual(self.car.current_speed(), 0)

    def tearDown(self):

        self.car.stop()
        self.car.turn_off_car()
        self.car = None
コード例 #2
0
class HardTestCase(unittest.TestCase):

    def setUp(self):
        self.car = Car()
        self.car.start_car()

    def test_hard_input(self):
        with self.assertRaises(Exception):
            self.car.add_speed()
            self.car.add_speed()
            self.car.add_speed()
            self.car.add_speed()
            self.car.turn_off_car()

    def test_hard_input_two(self):
        self.car.add_speed()
        self.car.add_speed()
        self.car.stop()
        self.assertEqual(self.car.current_speed(), 0)

        self.car.stop()
        self.car.stop()
        self.assertEqual(self.car.current_speed(), 0)

    def tearDown(self):
        self.car.stop()
        self.car.turn_off_car()
        self.car = None
コード例 #3
0
class MediumTestCase(unittest.TestCase):
    def setUp(self):
        # Todo: create an object named car from the Car class
        # Todo: use the object car to start the car.
        self.car = Car()
        self.car._start_car = True

    def test_medium_input(self):
        # Todo: raise an exception if the user tried to start the car while it's already on.
        # My Notes: The function should have code to raise an exception,
        # The unit test should make sure function raises an exception when it should
        # in this case,
        self.car._start_car = True  # making sure car is on.
        with self.assertRaises(Exception):  #
            self.car.start_car()

    def test_medium_input_two(self):
        # Todo: use the object car to remove(my question?) speed 4 times.
        # Todo: raise an exception if the user tried to turn off the car in a speed greater than 0.
        for _ in range(0, 4):
            self.car.add_speed()  # speed is 20
        with self.assertRaises(Exception):
            self.car.turn_off_car()

    def tearDown(self):
        # Todo: stop the car.
        # Todo: turn off the car.
        # Todo: set the object car to None.
        pass
コード例 #4
0
class MediumTestCase(unittest.TestCase):
    def setUp(self):
        self.car = Car()
        self.car.start_car()

    def test_medium_input(self):
        self.car.start_car()
        #self.assertEqual(self.car.current_speed(), 20)

    def test_medium_input_two(self):
        # Todo: use the object car to remove speed 4 times.
        # Todo: raise an exception if the user tried to turn off the car in a speed greater than 0.
        pass

    def tearDown(self):
        self.car.stop()
        self.car.turn_off_car()
        self.car = None
コード例 #5
0
class MediumTestCase(unittest.TestCase):
    def setUp(self):
        self.car = Car()
        self.car.start_car()

    def test_medium_input(self):
        with self.assertRaises(Exception):
            self.car.start_car()

    def test_medium_input_two(self):
        self.car.add_speed()
        self.car.add_speed()
        self.car.add_speed()
        self.car.add_speed()
        with self.assertRaises(Exception):
            self.car.turn_off_car()

    def tearDown(self):
        self.car.stop()
        self.car.turn_off_car()
        self.car = None
コード例 #6
0
class HardTestCase(unittest.TestCase):
    def setUp(self):
        # Todo: create an object named car from the Car class
        # Todo: use the object car to start the car.
        self.car = Car()
        self.car.start_car()

    def test_hard_input(self):
        # Todo: use the object car to add speed 2 times.
        # Todo: use the object car to remove speed 4 times.
        # Todo: make sure that the current speed is 0.
        for _ in range(0, 2):
            self.car.add_speed()

        for _ in range(0, 4):
            self.car.remove_speed()  # need to update the remove method:done

        self.assertEqual(self.car._speed, 0)
        self.assertEqual(self.car.current_speed(), 0)

    def test_hard_input_two(self):
        # Todo: use the object car to add speed 2 times.
        # Todo: stop the car.
        # Todo: stop the car.
        # Todo: stop the car.
        # Todo: make sure that the current speed is 0.
        self.car.add_speed()
        self.car.add_speed()
        self.car.stop()
        self.assertEqual(self.car.current_speed(), 0)

    def tearDown(self):
        # Todo: stop the car.
        # Todo: turn off the car.
        # Todo: set the object car to None.
        self.car.stop()  # stops the car
        self.car.turn_off_car()  # turn off the car
        self.car = None