Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Code #131

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nuxt.isNuxtApp": false
}
10 changes: 0 additions & 10 deletions car.py

This file was deleted.

32 changes: 32 additions & 0 deletions car_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from car_module import Car
from car_module.components.battery import NubbinBattery, SpliderBattery
from car_module.components.engine import CapuletEngine, SternmanEngine, WillounghbyEngine
from datetime import date

class CarFactory :
def create_calliope(current_date : date, last_sevice_date : date, current_mileage : int, last_service_mileage : int) -> Car:
calliope_engine = CapuletEngine(current_mileage=current_mileage, last_service_mileage=last_service_mileage)
calliope_battery = SpliderBattery(current_date=current_date, last_service_date=last_sevice_date)
return Car(engine=calliope_engine, battery=calliope_battery)


def create_glissade (current_date : date, last_service_date : date, current_mileage: int, last_service_mileage : int) -> Car :
glissad_engine = WillounghbyEngine(current_mileage=current_mileage, last_service_mileage=last_service_mileage)
glissad_battery = SpliderBattery(current_date=current_date, last_service_date=last_service_date)
return Car(engine=glissad_engine, battery=glissad_battery)

def create_palindrome (current_date : date, last_service_date : date, warning_light_on : bool) -> Car:
palindrome_engine = SternmanEngine(warning_light_is_on=warning_light_on)
palindrome_battery = SpliderBattery(current_date=current_date, last_service_date=last_service_date)
return Car(engine=palindrome_engine, battery=palindrome_battery)

def create_rorschach (current_date : date, last_service_date : date, current_mileage : int, last_service_mileage : int) -> Car:
rorschach_engine = WillounghbyEngine(current_mileage=current_mileage, last_service_mileage=last_service_mileage)
rorschach_battery = NubbinBattery(current_date=current_date, last_service_date=last_service_date)
return Car(engine=rorschach_engine, battery=rorschach_battery)

def create_thovex (current_date : date, last_service_date : date, current_mileage : int, last_service_mileage : int) -> 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)

return Car(engine=thovex_engine, battery=thovex_battery)
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
11 changes: 11 additions & 0 deletions car_module/car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .serviceable_Interface import Serviceable
from .components.battery.batter_Interface import Battery
from .components.engine.engine_Interface import Engine

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

def needs_service(self) -> bool:
return self.engine.needs_service() or self.battery.needs_service()
3 changes: 3 additions & 0 deletions car_module/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 SpliderBattery
from .batter_Interface import Battery
6 changes: 6 additions & 0 deletions car_module/components/battery/batter_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
11 changes: 11 additions & 0 deletions car_module/components/battery/nubbin_Battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .batter_Interface import Battery
from datetime import 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:
years = (self.current_date - self.last_service_date).days / 365.0
return years > 4
11 changes: 11 additions & 0 deletions car_module/components/battery/spindler_Battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .batter_Interface import Battery
from datetime import date

class SpliderBattery(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:
years = (self.current_date - self.last_service_date).days / 365.0
return years > 2
4 changes: 4 additions & 0 deletions car_module/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 WillounghbyEngine
9 changes: 9 additions & 0 deletions car_module/components/engine/capulet_Engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .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/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/components/engine/sternman_Engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .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/components/engine/willoughby_Engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .engine_Interface import Engine

class WillounghbyEngine(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
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.

Empty file removed engine/model/__init__.py
Empty file.
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 removed test/__init__.py
Empty file.
File renamed without changes.
16 changes: 16 additions & 0 deletions test/test_Battery/test_NubbinBattery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from car_module.components.battery import NubbinBattery
from datetime import date

class TestNubbinBattery(unittest.TestCase):
def test_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 test_need_service_false_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_SpindlerBattery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from car_module.components.battery import SpliderBattery
from datetime import date

class TestSplinderBattery (unittest.TestCase):
def test_check_needs_service_true_case(self):
current_date = date.today()
last_service_date = current_date.replace(year=current_date.year - 3)
nubbin = SpliderBattery(current_date,last_service_date)
self.assertTrue(nubbin.needs_service())

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