diff --git a/car.py b/car.py index f7b980a1b..6a06d3299 100644 --- a/car.py +++ b/car.py @@ -1,6 +1,5 @@ from abc import ABC, abstractmethod - class Car(ABC): def __init__(self, last_service_date): self.last_service_date = last_service_date diff --git a/engine/capulet_engine.py b/engine/capulet_engine.py index 69a2f3319..24edd45a3 100644 --- a/engine/capulet_engine.py +++ b/engine/capulet_engine.py @@ -1,8 +1,5 @@ from abc import ABC -from car import Car - - class CapuletEngine(Car, ABC): def __init__(self, last_service_date, current_mileage, last_service_mileage): super().__init__(last_service_date) diff --git a/engine/model/calliope.py b/engine/model/calliope.py index 1dd3da56d..ab684c5eb 100644 --- a/engine/model/calliope.py +++ b/engine/model/calliope.py @@ -1,12 +1,7 @@ from datetime import datetime - from engine.capulet_engine import CapuletEngine - class Calliope(CapuletEngine): def needs_service(self): service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 2) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False + return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced() diff --git a/engine/model/glissade.py b/engine/model/glissade.py index e1b16ad27..97667ae2a 100644 --- a/engine/model/glissade.py +++ b/engine/model/glissade.py @@ -1,12 +1,7 @@ from datetime import datetime - from engine.willoughby_engine import WilloughbyEngine - class Glissade(WilloughbyEngine): def needs_service(self): service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 2) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False + return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced() diff --git a/engine/model/palindrome.py b/engine/model/palindrome.py index 590864bc8..c4576476f 100644 --- a/engine/model/palindrome.py +++ b/engine/model/palindrome.py @@ -1,12 +1,7 @@ from datetime import datetime - from engine.sternman_engine import SternmanEngine - class Palindrome(SternmanEngine): def needs_service(self): service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False + return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced() diff --git a/engine/model/rorschach.py b/engine/model/rorschach.py index b9eedc91d..8b9aa0835 100644 --- a/engine/model/rorschach.py +++ b/engine/model/rorschach.py @@ -1,12 +1,7 @@ from datetime import datetime - from engine.willoughby_engine import WilloughbyEngine - class Rorschach(WilloughbyEngine): def needs_service(self): service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False + return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced() diff --git a/engine/model/thovex.py b/engine/model/thovex.py index eac5707f0..e8b1d9ec3 100644 --- a/engine/model/thovex.py +++ b/engine/model/thovex.py @@ -1,12 +1,7 @@ from datetime import datetime - from engine.capulet_engine import CapuletEngine - class Thovex(CapuletEngine): def needs_service(self): service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False + return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced() diff --git a/engine/sternman_engine.py b/engine/sternman_engine.py index 72d8b5ab3..5fb5ddcfa 100644 --- a/engine/sternman_engine.py +++ b/engine/sternman_engine.py @@ -1,15 +1,9 @@ from abc import ABC -from car import Car - - class SternmanEngine(Car, ABC): def __init__(self, last_service_date, warning_light_is_on): super().__init__(last_service_date) self.warning_light_is_on = warning_light_is_on def engine_should_be_serviced(self): - if self.warning_light_is_on: - return True - else: - return False + return self.warning_light_is_on diff --git a/engine/willoughby_engine.py b/engine/willoughby_engine.py index e5e0dc581..99a7f6494 100644 --- a/engine/willoughby_engine.py +++ b/engine/willoughby_engine.py @@ -1,8 +1,5 @@ from abc import ABC -from car import Car - - class WilloughbyEngine(Car, ABC): def __init__(self, last_service_date, current_mileage, last_service_mileage): super().__init__(last_service_date) diff --git a/test/batteries/SpindlerBattery.py b/test/batteries/SpindlerBattery.py new file mode 100644 index 000000000..62de9a5e2 --- /dev/null +++ b/test/batteries/SpindlerBattery.py @@ -0,0 +1,12 @@ +# battery/spindler_battery.py +from battery import Battery +from datetime import datetime + +class SpindlerBattery(Battery): + def __init__(self, last_service_date, current_date): + self.last_service_date = last_service_date + self.current_date = current_date + + def needs_service(self): + service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 3) + return service_threshold_date < self.current_date diff --git a/test/test_battery.py b/test/test_battery.py new file mode 100644 index 000000000..2a558c9bf --- /dev/null +++ b/test/test_battery.py @@ -0,0 +1,19 @@ +import unittest +from datetime import datetime +from battery.spindler_battery import SpindlerBattery + +class TestSpindlerBattery(unittest.TestCase): + def test_battery_should_be_serviced_after_three_years(self): + today = datetime.today().date() + last_service_date = today.replace(year=today.year - 3) + battery = SpindlerBattery(last_service_date, today) + self.assertTrue(battery.needs_service()) + + def test_battery_should_not_be_serviced_before_three_years(self): + today = datetime.today().date() + last_service_date = today.replace(year=today.year - 2) + battery = SpindlerBattery(last_service_date, today) + self.assertFalse(battery.needs_service()) + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_car.py b/test/test_car.py index f5994670d..646ed5206 100644 --- a/test/test_car.py +++ b/test/test_car.py @@ -1,188 +1,32 @@ 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 TestCalliope(unittest.TestCase): - def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 30001 - last_service_mileage = 0 - - car = Calliope(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) - - def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 30000 - last_service_mileage = 0 - - car = Calliope(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) - - -class TestGlissade(unittest.TestCase): - def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 60001 - last_service_mileage = 0 - - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) - - def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 60000 - last_service_mileage = 0 - - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) - - -class TestPalindrome(unittest.TestCase): - def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 5) - warning_light_is_on = False - - car = Palindrome(last_service_date, warning_light_is_on) - self.assertTrue(car.needs_service()) - - def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) - warning_light_is_on = False - - car = Palindrome(last_service_date, warning_light_is_on) - self.assertFalse(car.needs_service()) - - def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() - warning_light_is_on = True - - car = Palindrome(last_service_date, warning_light_is_on) - self.assertTrue(car.needs_service()) - - def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() - warning_light_is_on = False - - car = Palindrome(last_service_date, warning_light_is_on) - self.assertFalse(car.needs_service()) - - -class TestRorschach(unittest.TestCase): - def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 60001 - last_service_mileage = 0 - - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) - - def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 60000 - last_service_mileage = 0 - - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) - - -class TestThovex(unittest.TestCase): - def test_battery_should_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_battery_should_not_be_serviced(self): - today = datetime.today().date() - last_service_date = today.replace(year=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()) - - def test_engine_should_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 30001 - last_service_mileage = 0 - - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) - - def test_engine_should_not_be_serviced(self): - last_service_date = datetime.today().date() - current_mileage = 30000 - last_service_mileage = 0 - - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) - +from engine import Engine +from battery import Battery + +class TestEngine(unittest.TestCase): + def setUp(self): + # Create an instance of Engine to be used in tests + self.engine = Engine() + + def test_engine_start(self): + self.engine.start() + self.assertTrue(self.engine.is_running, "Engine should be running after start") + + def test_engine_stop(self): + self.engine.stop() + self.assertFalse(self.engine.is_running, "Engine should not be running after stop") + +class TestBattery(unittest.TestCase): + def setUp(self): + # Create an instance of Battery to be used in tests + self.battery = Battery() + + def test_battery_charge(self): + self.battery.charge() + self.assertGreater(self.battery.charge_level, 0, "Battery charge level should be greater than 0 after charging") + + def test_battery_discharge(self): + self.battery.discharge() + self.assertLess(self.battery.charge_level, 100, "Battery charge level should be less than 100 after discharging") if __name__ == '__main__': unittest.main() diff --git a/test/test_tires.py b/test/test_tires.py new file mode 100644 index 000000000..ac97e6f89 --- /dev/null +++ b/test/test_tires.py @@ -0,0 +1,27 @@ +import unittest +from tires.carrigan_tires import CarriganTires +from tires.octoprime_tires import OctoprimeTires + +class TestTires(unittest.TestCase): + def test_carrigan_tires_should_be_serviced(self): + tire_wear = [0.2, 0.9, 0.4, 0.3] + tires = CarriganTires(tire_wear) + self.assertTrue(tires.needs_service()) + + def test_carrigan_tires_should_not_be_serviced(self): + tire_wear = [0.2, 0.7, 0.4, 0.3] + tires = CarriganTires(tire_wear) + self.assertFalse(tires.needs_service()) + + def test_octoprime_tires_should_be_serviced(self): + tire_wear = [0.9, 0.8, 0.7, 0.6] + tires = OctoprimeTires(tire_wear) + self.assertTrue(tires.needs_service()) + + def test_octoprime_tires_should_not_be_serviced(self): + tire_wear = [0.5, 0.6, 0.7, 0.8] + tires = OctoprimeTires(tire_wear) + self.assertFalse(tires.needs_service()) + +if __name__ == '__main__': + unittest.main() diff --git a/tires/CarriganTires.py b/tires/CarriganTires.py new file mode 100644 index 000000000..f0c9ea00c --- /dev/null +++ b/tires/CarriganTires.py @@ -0,0 +1,7 @@ + +class CarriganTires: + def __init__(self, tire_wear): + self.tire_wear = tire_wear + + def needs_service(self): + return any(wear >= 0.9 for wear in self.tire_wear) diff --git a/tires/OctoprimeTires.py b/tires/OctoprimeTires.py new file mode 100644 index 000000000..584125beb --- /dev/null +++ b/tires/OctoprimeTires.py @@ -0,0 +1,7 @@ +# tires/octoprime_tires.py +class OctoprimeTires: + def __init__(self, tire_wear): + self.tire_wear = tire_wear + + def needs_service(self): + return sum(self.tire_wear) >= 3