Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
10 changes: 0 additions & 10 deletions car.py

This file was deleted.

52 changes: 52 additions & 0 deletions car_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from car_module import Serviceable, Car
from car_module.car_components.battery import Battery, NubbinBattery, SpindlerBattery
from car_module.car_components.engine import Engine, CapuletEngine, SternmanEngine, WilloughbyEngine
from car_module.car_components.tire import Tire, CarriganTire, OctoprimeTire
from typing import List
from datetime import date


#Class to create a car of differnt models
class CarFactory:
#method to creta a calliope car model
@staticmethod
def create_calliope(current_date:date, last_service_date: date, current_mileage:int, last_service_mileage:int, tire_wear:List[float]) -> Car:
calliope_engine = CapuletEngine(current_mileage=current_mileage,last_service_mileage=last_service_mileage)
calliope_battery = SpindlerBattery(current_date=current_date,last_service_date=last_service_date)
tire = CarriganTire(tire_wear=tire_wear)
return Car(engine=calliope_engine,battery=calliope_battery,tire=tire)

#method to creta a glissade car model
@staticmethod
def create_glissade(current_date:date, last_service_date: date, current_mileage:int, last_service_mileage:int, tire_wear:List[float]) -> Car:
glissade_engine = WilloughbyEngine(current_mileage=current_mileage,last_service_mileage=last_service_mileage)
glissade_battery = SpindlerBattery(current_date=current_date,last_service_date=last_service_date)
tire = CarriganTire(tire_wear=tire_wear)
return Car(engine=glissade_engine,battery=glissade_battery,tire=tire)

#method to creta a palindrome car model
@staticmethod
def create_palindrome(current_date:date, last_service_date: date, warning_light_on:bool, tire_wear:List[float]) -> Car :
palindrome_engine = SternmanEngine(warning_light_is_on=warning_light_on)
palindrome_battery = SpindlerBattery(current_date=current_date,last_service_date=last_service_date)
tire = OctoprimeTire(tire_wear=tire_wear)
return Car(engine=palindrome_engine,battery=palindrome_battery,tire=tire)

#method to creta a rorschach car model
@staticmethod
def create_rorschach(current_date:date, last_service_date: date, current_mileage:int, last_service_mileage:int, tire_wear:List[float]) -> Car :
rorschach_engine = WilloughbyEngine(current_mileage=current_mileage,last_service_mileage=last_service_mileage)
rorschach_battery = NubbinBattery(current_date=current_date,last_service_date=last_service_date)
tire = CarriganTire(tire_wear=tire_wear)
return Car(engine=rorschach_engine,battery=rorschach_battery,tire=tire)

#method to creta a thovex car model
@staticmethod
def create_thovex(current_date:date, last_service_date: date, current_mileage:int, last_service_mileage:int, tire_wear:List[float]) -> Car :
thovex_engine = CapuletEngine(current_mileage=current_mileage,last_service_mileage=last_service_mileage)
thovex_battery = NubbinBattery(current_date=current_date,last_service_date=last_service_date)
tire = OctoprimeTire(tire_wear=tire_wear)
return Car(engine=thovex_engine,battery=thovex_battery)


#CarFactory.create_calliope()
2 changes: 2 additions & 0 deletions car_module/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .serviceable_interface import Serviceable
from .car import Car
14 changes: 14 additions & 0 deletions car_module/car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .serviceable_interface import Serviceable
from car_module.car_components.battery.battery_interface import Battery
from car_module.car_components.engine.engine_interface import Engine
from car_module.car_components.tire import Tire


class Car(Serviceable):
def __init__(self, engine:Engine, battery: Battery, tire:Tire):
self.engine = engine
self.battery = battery
self.tire = tire

def needs_service(self) ->bool:
return self.engine.needs_service() or self.battery.needs_service() or self.tire.needs_service()
File renamed without changes.
3 changes: 3 additions & 0 deletions car_module/car_components/battery/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .nubbin_battery import NubbinBattery
from .spindler_battery import SpindlerBattery
from .battery_interface import Battery
6 changes: 6 additions & 0 deletions car_module/car_components/battery/battery_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC, abstractmethod

class Battery(ABC):
@abstractmethod
def needs_service() -> bool:
pass
12 changes: 12 additions & 0 deletions car_module/car_components/battery/nubbin_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from car_module.car_components.battery.battery_interface import Battery
from datetime import date
from utils import add_years_to_date

class NubbinBattery(Battery):
def __init__(self, current_date :date, last_service_date:date ):
self.current_date = current_date
self.last_service_date = last_service_date

def needs_service(self) ->bool:
service_date = add_years_to_date(original_date=self.last_service_date,years_to_add=4)
return service_date < self.current_date
12 changes: 12 additions & 0 deletions car_module/car_components/battery/spindler_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from car_module.car_components.battery.battery_interface import Battery
from datetime import date
from utils import add_years_to_date

class SpindlerBattery(Battery):
def __init__(self, current_date :date, last_service_date:date ):
self.current_date = current_date
self.last_service_date = last_service_date

def needs_service(self) ->bool:
service_date = add_years_to_date(original_date=self.last_service_date,years_to_add=3)
return service_date < self.current_date
4 changes: 4 additions & 0 deletions car_module/car_components/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .engine_interface import Engine
from .capulet_engine import CapuletEngine
from .sternman_engine import SternmanEngine
from .willoughby_engine import WilloughbyEngine
9 changes: 9 additions & 0 deletions car_module/car_components/engine/capulet_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from car_module.car_components.engine.engine_interface import Engine

class CapuletEngine(Engine):
def __init__(self, current_mileage :int, last_service_mileage:int ):
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage

def needs_service(self) ->bool:
return self.current_mileage - self.last_service_mileage > 30000
6 changes: 6 additions & 0 deletions car_module/car_components/engine/engine_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC, abstractmethod

class Engine(ABC):
@abstractmethod
def needs_service() -> bool:
pass
8 changes: 8 additions & 0 deletions car_module/car_components/engine/sternman_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from car_module.car_components.engine.engine_interface import Engine

class SternmanEngine(Engine):
def __init__(self, warning_light_is_on :bool):
self.warning_light_is_on = warning_light_is_on

def needs_service(self) ->bool:
return self.warning_light_is_on
9 changes: 9 additions & 0 deletions car_module/car_components/engine/willoughby_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from car_module.car_components.engine.engine_interface import Engine

class WilloughbyEngine(Engine):
def __init__(self, current_mileage :int, last_service_mileage:int ):
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage

def needs_service(self) ->bool:
return self.current_mileage - self.last_service_mileage > 60000
3 changes: 3 additions & 0 deletions car_module/car_components/tire/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .tire_interface import Tire
from .carrigan_tire import CarriganTire
from .octoprime_tire import OctoprimeTire
12 changes: 12 additions & 0 deletions car_module/car_components/tire/carrigan_tire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from car_module.car_components.tire.tire_interface import Tire
from typing import List

class CarriganTire(Tire):
def __init__(self, tire_wear :List[float]):
self.tire_wear = tire_wear

def needs_service(self) ->bool:
for value in self.tire_wear :
if self.tire_wear >= 0.9:
return True
return False
9 changes: 9 additions & 0 deletions car_module/car_components/tire/octoprime_tire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from car_module.car_components.tire.tire_interface import Tire
from typing import List

class OctoprimeTire(Tire):
def __init__(self, tire_wear :List[float]):
self.tire_wear = tire_wear

def needs_service(self) ->bool:
return sum(self.tire_wear) >= 3
8 changes: 8 additions & 0 deletions car_module/car_components/tire/tire_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from abc import ABC, abstractmethod
from typing import List


class Tire(ABC):
@abstractmethod
def needs_service() -> bool:
pass
6 changes: 6 additions & 0 deletions car_module/serviceable_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC, abstractmethod

class Serviceable(ABC):
@abstractmethod
def needs_service() -> bool:
pass
13 changes: 0 additions & 13 deletions engine/capulet_engine.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/calliope.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/glissade.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/palindrome.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/rorschach.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/thovex.py

This file was deleted.

15 changes: 0 additions & 15 deletions engine/sternman_engine.py

This file was deleted.

13 changes: 0 additions & 13 deletions engine/willoughby_engine.py

This file was deleted.

Empty file added test/test_battery/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions test/test_battery/test_nubbbin_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from car_module.car_components.battery import NubbinBattery
from datetime import date

class TestNubbinBattery(unittest.TestCase):
def check_needs_service_true_case(self):
current_date = date.today()
last_service_date = current_date.replace(year=current_date.year-5)
nubbin = NubbinBattery(current_date,last_service_date)
self.assertTrue(nubbin.needs_service())

def check_needs_service_flase_case(self):
current_date = date.today()
last_service_date = current_date.replace(year=current_date.year-1)
nubbin = NubbinBattery(current_date,last_service_date)
self.assertFalse(nubbin.needs_service())
16 changes: 16 additions & 0 deletions test/test_battery/test_spindler_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from car_module.car_components.battery import SpindlerBattery
from datetime import date

class TestSpindlerBattery(unittest.TestCase):
def check_needs_service_true_case(self):
current_date = date.today()
last_service_date = current_date.replace(year=current_date.year-4)
nubbin = SpindlerBattery(current_date,last_service_date)
self.assertTrue(nubbin.needs_service())

def check_needs_service_flase_case(self):
current_date = date.today()
last_service_date = current_date.replace(year=current_date.year-1)
nubbin = SpindlerBattery(current_date,last_service_date)
self.assertFalse(nubbin.needs_service())
Loading