diff --git a/engine/__init__.py b/__init__.py similarity index 100% rename from engine/__init__.py rename to __init__.py diff --git a/battery/Battery.py b/battery/Battery.py new file mode 100644 index 000000000..fb34ead8c --- /dev/null +++ b/battery/Battery.py @@ -0,0 +1,7 @@ +from abc import ABC, abstractmethod + + +class Battery(ABC): + @abstractmethod + def needs_service(): + pass diff --git a/battery/NubbinBattery.py b/battery/NubbinBattery.py new file mode 100644 index 000000000..0799ed969 --- /dev/null +++ b/battery/NubbinBattery.py @@ -0,0 +1,23 @@ +from battery.Battery import Battery +from datetime import datetime + +class NubbinBattery(Battery): + def __init__(self, last_service_date): + self.last_service_date = last_service_date + self.current_data = datetime.today().date() + + 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(): + return True + else: + return False + + +if __name__ == "__main__": + today = datetime.today().date() + last_service_date = today.replace(year=today.year - 2) + print(last_service_date) + nb = NubbinBattery(last_service_date) + print(nb.needs_service()) diff --git a/battery/SpindlerBattery.py b/battery/SpindlerBattery.py new file mode 100644 index 000000000..bc450225d --- /dev/null +++ b/battery/SpindlerBattery.py @@ -0,0 +1,24 @@ +from battery.Battery import Battery +from datetime import datetime + + +class SpindlerBattery(Battery): + def __init__(self, last_service_date): + self.last_service_date = last_service_date + self.current_data = datetime.today().date() + + def needs_service(self): + service_threshold_date = self.last_service_date.replace( + year=self.last_service_date.year + 3) + if service_threshold_date < datetime.today().date(): + return True + else: + return False + + +if __name__ == "__main__": + today = datetime.today().date() + last_service_date = today.replace(year=today.year - 5) + print(last_service_date) + nb = SpindlerBattery(last_service_date) + print(nb.needs_service()) diff --git a/engine/model/__init__.py b/battery/__init__.py similarity index 100% rename from engine/model/__init__.py rename to battery/__init__.py diff --git a/car.py b/car.py index f7b980a1b..4876e0939 100644 --- a/car.py +++ b/car.py @@ -1,10 +1,20 @@ from abc import ABC, abstractmethod -class Car(ABC): - def __init__(self, last_service_date): - self.last_service_date = last_service_date - +class Serviceable(ABC): @abstractmethod def needs_service(self): pass + + +class Car(Serviceable): + def __init__(self, engine, battery, tire): + self.engine = engine + self.battery = battery + self.tire = tire + + def needs_service(self): + if self.engine.needs_service() or self.battery.needs_service() or self.tire.needs_service(): + return True + else: + return False diff --git a/carFactory.py b/carFactory.py new file mode 100644 index 000000000..7d3dca186 --- /dev/null +++ b/carFactory.py @@ -0,0 +1,45 @@ +from datetime import datetime + +from battery.NubbinBattery import NubbinBattery +from battery.SpindlerBattery import SpindlerBattery + +from engine.capulet_engine import CapuletEngine +from engine.sternman_engine import SternmanEngine +from engine.willoughby_engine import WilloughbyEngine + +from car import Car + + +class CarFactory(): + + def create_calliope(self, last_service_date, current_mileage, last_service_mileage): + ce = CapuletEngine(last_service_mileage, current_mileage) + sb = SpindlerBattery(last_service_date) + self.car = Car(ce, sb) + + def create_glissade(self, last_service_date, current_mileage, last_service_mileage): + we = WilloughbyEngine(last_service_mileage, current_mileage) + sb = SpindlerBattery(last_service_date) + self.car = Car(we, sb) + + def create_palindrome(self, last_service_date, warning_light_is_on): + se = SternmanEngine(warning_light_is_on) + sb = SpindlerBattery(last_service_date) + self.car = Car(se, sb) + + def create_rorschach(self, last_service_date, current_mileage, last_service_mileage): + we = WilloughbyEngine(last_service_mileage, current_mileage) + nb = NubbinBattery(last_service_date) + self.car = Car(we, nb) + + def create_thovex(self, last_service_date, current_mileage, last_service_mileage): + we = CapuletEngine(last_service_mileage, current_mileage) + nb = NubbinBattery(last_service_date) + self.car = Car(we, nb) + +if __name__ == "__main__": + + today = datetime.today().date() + cf = CarFactory() + cf.create_calliope(today,30001,0) + print(cf.car.needs_service()) diff --git a/engine/Engine.py b/engine/Engine.py new file mode 100644 index 000000000..98504e848 --- /dev/null +++ b/engine/Engine.py @@ -0,0 +1,7 @@ +from abc import ABC, abstractmethod + + +class Engine(ABC): + @abstractmethod + def needs_service(): + pass diff --git a/engine/capulet_engine.py b/engine/capulet_engine.py index 69a2f3319..32ea6e30c 100644 --- a/engine/capulet_engine.py +++ b/engine/capulet_engine.py @@ -1,13 +1,15 @@ -from abc import ABC +from engine.Engine import Engine -from car import Car - -class CapuletEngine(Car, ABC): - def __init__(self, last_service_date, current_mileage, last_service_mileage): - super().__init__(last_service_date) - self.current_mileage = current_mileage +class CapuletEngine(Engine): + def __init__(self, last_service_mileage, current_mileage): self.last_service_mileage = last_service_mileage + self.current_mileage = current_mileage - def engine_should_be_serviced(self): + def needs_service(self): return self.current_mileage - self.last_service_mileage > 30000 + + +if __name__ == "__main__": + ce = CapuletEngine(0, 30001) + print(ce.needs_service()) diff --git a/engine/model/calliope.py b/engine/model/calliope.py deleted file mode 100644 index 1dd3da56d..000000000 --- a/engine/model/calliope.py +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/engine/model/glissade.py b/engine/model/glissade.py deleted file mode 100644 index e1b16ad27..000000000 --- a/engine/model/glissade.py +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/engine/model/palindrome.py b/engine/model/palindrome.py deleted file mode 100644 index 590864bc8..000000000 --- a/engine/model/palindrome.py +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/engine/model/rorschach.py b/engine/model/rorschach.py deleted file mode 100644 index b9eedc91d..000000000 --- a/engine/model/rorschach.py +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/engine/model/thovex.py b/engine/model/thovex.py deleted file mode 100644 index eac5707f0..000000000 --- a/engine/model/thovex.py +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/engine/sternman_engine.py b/engine/sternman_engine.py index 72d8b5ab3..3d4448a9e 100644 --- a/engine/sternman_engine.py +++ b/engine/sternman_engine.py @@ -1,15 +1,16 @@ -from abc import ABC +from engine.Engine import Engine -from car import Car - -class SternmanEngine(Car, ABC): - def __init__(self, last_service_date, warning_light_is_on): - super().__init__(last_service_date) +class SternmanEngine(Engine): + def __init__(self, warning_light_is_on): self.warning_light_is_on = warning_light_is_on - def engine_should_be_serviced(self): + def needs_service(self): if self.warning_light_is_on: return True else: return False + +if __name__ == "__main__": + se = SternmanEngine(True) + print(se.needs_service()) diff --git a/engine/willoughby_engine.py b/engine/willoughby_engine.py index e5e0dc581..4360368fb 100644 --- a/engine/willoughby_engine.py +++ b/engine/willoughby_engine.py @@ -1,13 +1,15 @@ -from abc import ABC +from engine.Engine import Engine -from car import Car - -class WilloughbyEngine(Car, ABC): - def __init__(self, last_service_date, current_mileage, last_service_mileage): - super().__init__(last_service_date) - self.current_mileage = current_mileage +class WilloughbyEngine(Engine): + def __init__(self, last_service_mileage, current_mileage): self.last_service_mileage = last_service_mileage + self.current_mileage = current_mileage - def engine_should_be_serviced(self): + def needs_service(self): return self.current_mileage - self.last_service_mileage > 60000 + + +if __name__ == "__main__": + ce = WilloughbyEngine(0, 30001) + print(ce.needs_service()) diff --git a/test/test_car.py b/test_car.py similarity index 51% rename from test/test_car.py rename to test_car.py index f5994670d..9f7e6c602 100644 --- a/test/test_car.py +++ b/test_car.py @@ -1,11 +1,7 @@ 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 +from carFactory import CarFactory class TestCalliope(unittest.TestCase): @@ -14,34 +10,38 @@ def test_battery_should_be_serviced(self): 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()) + cf = CarFactory() + cf.create_calliope(last_service_date, + current_mileage, last_service_mileage) + self.assertTrue(cf.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()) + cf = CarFactory() + cf.create_calliope(last_service_date, + current_mileage, last_service_mileage) + self.assertFalse(cf.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()) + cf = CarFactory() + cf.create_calliope(last_service_date, + current_mileage, last_service_mileage) + self.assertTrue(cf.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()) + cf = CarFactory() + cf.create_calliope(last_service_date, + current_mileage, last_service_mileage) + self.assertFalse(cf.car.needs_service()) class TestGlissade(unittest.TestCase): @@ -51,8 +51,10 @@ def test_battery_should_be_serviced(self): current_mileage = 0 last_service_mileage = 0 - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + cf = CarFactory() + cf.create_glissade(last_service_date, + current_mileage, last_service_mileage) + self.assertTrue(cf.car.needs_service()) def test_battery_should_not_be_serviced(self): today = datetime.today().date() @@ -60,24 +62,30 @@ def test_battery_should_not_be_serviced(self): current_mileage = 0 last_service_mileage = 0 - car = Glissade(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + cf = CarFactory() + cf.create_glissade(last_service_date, + current_mileage, last_service_mileage) + self.assertFalse(cf.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()) + cf = CarFactory() + cf.create_glissade(last_service_date, + current_mileage, last_service_mileage) + self.assertTrue(cf.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()) + cf = CarFactory() + cf.create_glissade(last_service_date, + current_mileage, last_service_mileage) + self.assertFalse(cf.car.needs_service()) class TestPalindrome(unittest.TestCase): @@ -86,30 +94,34 @@ def test_battery_should_be_serviced(self): 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()) + cf = CarFactory() + cf.create_palindrome(last_service_date, warning_light_is_on) + self.assertTrue(cf.car.needs_service()) def test_battery_should_not_be_serviced(self): today = datetime.today().date() - last_service_date = today.replace(year=today.year - 3) + last_service_date = today.replace(year=today.year - 2) warning_light_is_on = False - car = Palindrome(last_service_date, warning_light_is_on) - self.assertFalse(car.needs_service()) + cf = CarFactory() + cf.create_palindrome(last_service_date, warning_light_is_on) + self.assertFalse(cf.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()) + cf = CarFactory() + cf.create_palindrome(last_service_date, warning_light_is_on) + self.assertTrue(cf.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()) + cf = CarFactory() + cf.create_palindrome(last_service_date, warning_light_is_on) + self.assertFalse(cf.car.needs_service()) class TestRorschach(unittest.TestCase): @@ -119,8 +131,10 @@ def test_battery_should_be_serviced(self): current_mileage = 0 last_service_mileage = 0 - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + cf = CarFactory() + cf.create_rorschach(last_service_date, + current_mileage, last_service_mileage) + self.assertTrue(cf.car.needs_service()) def test_battery_should_not_be_serviced(self): today = datetime.today().date() @@ -128,24 +142,30 @@ def test_battery_should_not_be_serviced(self): current_mileage = 0 last_service_mileage = 0 - car = Rorschach(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + cf = CarFactory() + cf.create_rorschach(last_service_date, + current_mileage, last_service_mileage) + self.assertFalse(cf.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()) + cf = CarFactory() + cf.create_rorschach(last_service_date, + current_mileage, last_service_mileage) + self.assertTrue(cf.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()) + cf = CarFactory() + cf.create_rorschach(last_service_date, + current_mileage, last_service_mileage) + self.assertFalse(cf.car.needs_service()) class TestThovex(unittest.TestCase): @@ -155,8 +175,10 @@ def test_battery_should_be_serviced(self): current_mileage = 0 last_service_mileage = 0 - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertTrue(car.needs_service()) + cf = CarFactory() + cf.create_thovex(last_service_date, current_mileage, + last_service_mileage) + self.assertTrue(cf.car.needs_service()) def test_battery_should_not_be_serviced(self): today = datetime.today().date() @@ -164,24 +186,30 @@ def test_battery_should_not_be_serviced(self): current_mileage = 0 last_service_mileage = 0 - car = Thovex(last_service_date, current_mileage, last_service_mileage) - self.assertFalse(car.needs_service()) + cf = CarFactory() + cf.create_thovex(last_service_date, current_mileage, + last_service_mileage) + self.assertFalse(cf.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()) + cf = CarFactory() + cf.create_thovex(last_service_date, current_mileage, + last_service_mileage) + self.assertTrue(cf.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()) + cf = CarFactory() + cf.create_thovex(last_service_date, current_mileage, + last_service_mileage) + self.assertFalse(cf.car.needs_service()) if __name__ == '__main__': diff --git a/tire/Tire.py b/tire/Tire.py new file mode 100644 index 000000000..958306290 --- /dev/null +++ b/tire/Tire.py @@ -0,0 +1,7 @@ +from abc import ABC, abstractmethod + + +class Tire(ABC): + @abstractmethod + def needs_service(): + pass diff --git a/test/__init__.py b/tire/__init__.py similarity index 100% rename from test/__init__.py rename to tire/__init__.py diff --git a/tire/carrigan.py b/tire/carrigan.py new file mode 100644 index 000000000..f1f187165 --- /dev/null +++ b/tire/carrigan.py @@ -0,0 +1,19 @@ +from tire.Tire import Tire + + +class Carrigan(Tire): + + def __init__(self, arr): + self.arr = arr + + def needs_service(self): + for wheel in self.arr: + if wheel >= 0.9: + return True + + return False + + +if __name__ == "__main__": + c = Carrigan([0.1, 0, 0.89, 1]) + print(c.needs_service()) \ No newline at end of file diff --git a/tire/octoprime.py b/tire/octoprime.py new file mode 100644 index 000000000..dd57728de --- /dev/null +++ b/tire/octoprime.py @@ -0,0 +1,22 @@ +from tire.Tire import Tire + + +class Octoprime(Tire): + + def __init__(self, arr): + self.arr = arr + + def needs_service(self): + sum = 0 + for wheel in self.arr: + sum += wheel + + if sum >= 3: + return True + else: + return False + + +if __name__ == "__main__": + c = Octoprime([1, 0, 1, 1]) + print(c.needs_service()) \ No newline at end of file