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

Task4 #117

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Task4 #117

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
13 changes: 13 additions & 0 deletions .vscode/easycode.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules/
dist/
vendor/
cache/
.*/
*.min.*
*.test.*
*.spec.*
*.bundle.*
*.bundle-min.*
*.*.js
*.*.ts
*.log
File renamed without changes.
10 changes: 0 additions & 10 deletions car.py

This file was deleted.

56 changes: 56 additions & 0 deletions car_Factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#importing necessary libraries
from car_Module import Serviceable, Car
from car_Module.components.battery import Battery, NubbinBattery, SpindlerBattery
from car_Module.components.engine import Engine, CapuletEngine, SternmanEngine, WilloughbyEngine
from car_Module.components.tire import Tire, CarriganTire, OctoprimeTire
from typing import List
from datetime import date


#CarFactory class to create all available models
class CarFactory:
#create_calliope method
#calliope uses Capulet engine
#calliope uses Spindler battery
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)

#create_glissade method
#calliope uses Willoughby engine
#calliope uses Spindler battery
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)

#create_palindrome method
#calliope uses Sternman Engine
#calliope uses Spindler battery
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)

#create_rorschach method
#calliope uses Willoughby engine
#calliope uses Nubbin battery
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)

#create_thovex method
#calliope uses Capulet engine
#calliope uses Nubbin battery
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)

3 changes: 3 additions & 0 deletions car_Module/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import necessary libraries
from .serviceable_Interface import Serviceable
from .car import Car
13 changes: 13 additions & 0 deletions car_Module/car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import necessary libraries
from .serviceable_Interface import Serviceable
from .components.battery.battery_Interface import Battery
from .components.engine.engine_Interface import Engine

#Car class object with engine/battery and service status
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 SpindlerBattery
from .battery_Interface import Battery
6 changes: 6 additions & 0 deletions car_Module/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/components/battery/nubbin_Battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .battery_Interface import Battery
from datetime import date

#Nubbin battery class
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
12 changes: 12 additions & 0 deletions car_Module/components/battery/spindler_Battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .battery_Interface import Battery
from datetime import date

#Spindler battery class
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:
years = (self.current_date - self.last_service_date).days / 365.0
return years > 3
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 WilloughbyEngine
10 changes: 10 additions & 0 deletions car_Module/components/engine/capulet_Engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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
9 changes: 9 additions & 0 deletions car_Module/components/engine/sternman_Engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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
10 changes: 10 additions & 0 deletions car_Module/components/engine/willoughby_Engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .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/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/components/tire/carrigan_Tire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from car_Module.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 value >= 0.9:
return True
return False
9 changes: 9 additions & 0 deletions car_Module/components/tire/octoprime_Tire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from car_Module.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/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
8 changes: 8 additions & 0 deletions car_Module/serviceable_Interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import necessary libraries
from abc import ABC, abstractmethod

#Serviceable abstraction method
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.

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_needs_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 SpindlerBattery
from datetime import date

class TestSpindlerBattery(unittest.TestCase):
def test_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 test_check_needs_service_false_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())
Empty file added test/test_Engine/__init__.py
Empty file.
Loading