diff --git a/car.py b/car.py index f7b980a1b..c45e6500b 100644 --- a/car.py +++ b/car.py @@ -1,10 +1,10 @@ from abc import ABC, abstractmethod - class Car(ABC): def __init__(self, last_service_date): self.last_service_date = last_service_date @abstractmethod def needs_service(self): - pass + """Check if the car needs servicing.""" + pass \ No newline at end of file diff --git a/engine/model/tire.py b/engine/model/tire.py new file mode 100644 index 000000000..82d1150e0 --- /dev/null +++ b/engine/model/tire.py @@ -0,0 +1,14 @@ +class Tire: + name = "" + service_criteria = None + + def __init__(self, name): + self.name = name + + def needs_service(self, tire_wear_array): + return self.service_criteria(tire_wear_array) + def service_criteria(tire_wear_array): + return any(tire_wear >= 0.9 for tire_wear in tire_wear_array) + def service_criteria(tire_wear_array): + return sum(tire_wear_array) >= 3 + diff --git a/test/test_car.py b/test/test_car.py index f5994670d..33ee298f8 100644 --- a/test/test_car.py +++ b/test/test_car.py @@ -1,188 +1,189 @@ import unittest from datetime import datetime - from engine.model.calliope import Calliope from engine.model.glissade import Glissade from engine.model.palindrome import Palindrome from engine.model.rorschach import Rorschach from engine.model.thovex import Thovex +class CarTestCase(unittest.TestCase): + def setUp(self): + self.today = datetime.today().date() + + def assertCarNeedsService(self, car, expected_result): + self.assertEqual(car.needs_service(), expected_result) -class TestCalliope(unittest.TestCase): +class TestCalliope(CarTestCase): def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) + last_service_date = self.today.replace(year=self.today.year - 3) current_mileage = 0 last_service_mileage = 0 - car = Calliope(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 1) + last_service_date = self.today.replace(year=self.today.year - 1) current_mileage = 0 last_service_mileage = 0 - car = Calliope(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 30001 last_service_mileage = 0 - car = Calliope(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 30000 last_service_mileage = 0 - car = Calliope(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) - -class TestGlissade(unittest.TestCase): +class TestGlissade(CarTestCase): def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) + last_service_date = self.today.replace(year=self.today.year - 3) current_mileage = 0 last_service_mileage = 0 - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 1) + last_service_date = self.today.replace(year=self.today.year - 1) current_mileage = 0 last_service_mileage = 0 - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 60001 last_service_mileage = 0 - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 60000 last_service_mileage = 0 - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) - -class TestPalindrome(unittest.TestCase): +class TestPalindrome(CarTestCase): def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 5) + last_service_date = self.today.replace(year=self.today.year - 5) warning_light_is_on = False - car = Palindrome(last_service_date, warning_light_is_on) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) + last_service_date = self.today.replace(year=self.today.year - 3) warning_light_is_on = False - car = Palindrome(last_service_date, warning_light_is_on) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today warning_light_is_on = True - car = Palindrome(last_service_date, warning_light_is_on) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today warning_light_is_on = False - car = Palindrome(last_service_date, warning_light_is_on) - self.assertFalse(car.needs_service()) - + self.assertCarNeedsService(car, False) -class TestRorschach(unittest.TestCase): +class TestRorschach(CarTestCase): def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 5) + last_service_date = self.today.replace(year=self.today.year - 5) current_mileage = 0 last_service_mileage = 0 - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) + last_service_date = self.today.replace(year=self.today.year - 3) current_mileage = 0 last_service_mileage = 0 - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 60001 last_service_mileage = 0 - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 60000 last_service_mileage = 0 - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) - + self.assertCarNeedsService(car, False) -class TestThovex(unittest.TestCase): +class TestThovex(CarTestCase): def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 5) + last_service_date = self.today.replace(year=self.today.year - 5) current_mileage = 0 last_service_mileage = 0 - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) + last_service_date = self.today.replace(year=self.today.year - 3) current_mileage = 0 last_service_mileage = 0 - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, False) def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 30001 last_service_mileage = 0 - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + self.assertCarNeedsService(car, True) def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() + last_service_date = self.today current_mileage = 30000 + last_service_mileage = + + + +# UNIT TEST + +class TestThovex(CarTestCase): + def test_battery_should_be_serviced(self): + last_service_date = self.today.replace(year=self.today.year - 5) + current_mileage = 0 + last_service_mileage = 0 + car = Thovex(last_service_date, current_mileage, last_service_mileage) + self.assertCarNeedsService(car, True) + + def test_battery_should_not_be_serviced(self): + last_service_date = self.today.replace(year=self.today.year - 3) + current_mileage = 0 last_service_mileage = 0 + car = Thovex(last_service_date, current_mileage, last_service_mileage) + self.assertCarNeedsService(car, False) + def test_engine_should_be_serviced(self): + last_service_date = self.today + current_mileage = 30001 + last_service_mileage = 0 car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + self.assertCarNeedsService(car, True) + def test_engine_should_not_be_serviced(self): + last_service_date = self.today + current_mileage = 30000 + last_service_mileage = 0 + car = Thovex(last_service_date, current_mileage, last_service_mileage) + self.assertCarNeedsService(car, False) if __name__ == '__main__': - unittest.main() + unittest.main() \ No newline at end of file