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

Initial commit #143

Open
wants to merge 3 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
Empty file added battery/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions battery/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC

class battery(ABC):
def serviceNeed(self):
pass
15 changes: 15 additions & 0 deletions battery/nubbin_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from battery.battery import battery
from utils import add_yearTodate


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

def serviceNeed(self):
serviceDate = add_yearTodate(self.last_service_date, 4)
if serviceDate < self.current_date:
return True
else:
return False
15 changes: 15 additions & 0 deletions battery/splinder_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from battery.battery import battery
from utils import add_yearTodate


class SplinderBattery(battery):
def __init__(self, current_date, last_service_date):
self.current_date = current_date
self.last_service_date = last_service_date

def needs_service(self):
serviceDate = add_yearTodate(self.last_service_date, 3)
if serviceDate < self.current_date:
return True
else:
return False
43 changes: 43 additions & 0 deletions car_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from battery.splinder_battery import SpindlerBattery
from battery.nubbin_battery import NubbinBattery
from car import Car
from engine.capulet_engine import CapuletEngine
from engine.sternman_engine import SternmanEngine
from engine.willoughby_engine import WilloughbyEngine


class CarFactory:
@staticmethod
def create_calliope(current_date, last_service_date, current_mileage, last_service_mileage):
engine = CapuletEngine(current_mileage, last_service_mileage)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_glissade(current_date, last_service_date, current_mileage, last_service_mileage):
engine = WilloughbyEngine(current_mileage, last_service_mileage)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_palindrome(current_date, last_service_date, warning_light_is_on):
engine = SternmanEngine(warning_light_is_on)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_rorschach(current_date, last_service_date, current_mileage, last_service_mileage):
engine = WilloughbyEngine(current_mileage, last_service_mileage)
battery = NubbinBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

@staticmethod
def create_thovex(current_date, last_service_date, current_mileage, last_service_mileage):
engine = CapuletEngine(current_mileage, last_service_mileage)
battery = NubbinBattery(current_date, last_service_date)
car = Car(engine, battery)
return car
6 changes: 6 additions & 0 deletions serviceable.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 serviceNeed(self):
pass
18 changes: 18 additions & 0 deletions test/test_battery/test_nubbin_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest
from datetime import date

from battery.nubbin_battery import NubbinBattery


class TestNubbinBattery(unittest.TestCase):
def test_needs_service_true(self):
current_date = date.fromisoformat("2024-01-06")
last_service_date = date.fromisoformat("2020-01-25")
battery = NubbinBattery(current_date, last_service_date)
self.assertTrue(battery.needs_service())

def test_needs_service_false(self):
current_date = date.fromisoformat("2023-01-06")
last_service_date = date.fromisoformat("2020-01-10")
battery = NubbinBattery(current_date, last_service_date)
self.assertFalse(battery.needs_service())
18 changes: 18 additions & 0 deletions test/test_battery/test_spindler_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest
from datetime import date

from battery.splinder_battery import SpindlerBattery


class TestSpindlerBattery(unittest.TestCase):
def test_needs_service_true(self):
current_date = date.fromisoformat("2020-05-15")
last_service_date = date.fromisoformat("2018-01-25")
battery = SpindlerBattery(current_date, last_service_date)
self.assertTrue(battery.needs_service())

def test_needs_service_false(self):
current_date = date.fromisoformat("2020-05-15")
last_service_date = date.fromisoformat("2019-01-10")
battery = SpindlerBattery(current_date, last_service_date)
self.assertFalse(battery.needs_service())
17 changes: 17 additions & 0 deletions test/test_engine/test_capulet_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

from engine.capulet_engine import CapuletEngine


class TestCapuletEngine(unittest.TestCase):
def test_needs_service_true(self):
current_mileage = 30001
last_service_mileage = 0
engine = CapuletEngine(current_mileage, last_service_mileage)
self.assertTrue(engine.needs_service())

def test_needs_service_false(self):
current_mileage = 30000
last_service_mileage = 0
engine = CapuletEngine(current_mileage, last_service_mileage)
self.assertFalse(engine.needs_service())
15 changes: 15 additions & 0 deletions test/test_engine/test_sternman_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from engine.sternman_engine import SternmanEngine


class TestSternmanEngine(unittest.TestCase):
def test_needs_service_true(self):
warning_light_is_on = True
engine = SternmanEngine(warning_light_is_on)
self.assertTrue(engine.needs_service())

def test_needs_service_false(self):
warning_light_is_on = False
engine = SternmanEngine(warning_light_is_on)
self.assertFalse(engine.needs_service())
17 changes: 17 additions & 0 deletions test/test_engine/test_willoughby_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

from engine.willoughby_engine import WilloughbyEngine


class TestWilloughbyEngine(unittest.TestCase):
def test_needs_service_true(self):
current_mileage = 60001
last_service_mileage = 0
engine = WilloughbyEngine(current_mileage, last_service_mileage)
self.assertTrue(engine.needs_service())

def test_needs_service_false(self):
current_mileage = 60000
last_service_mileage = 0
engine = WilloughbyEngine(current_mileage, last_service_mileage)
self.assertFalse(engine.needs_service())
12 changes: 12 additions & 0 deletions tires/carrigan_tires.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from tires.tires import Tires


class CarriganTires(Tires):
def __init__(self, tire_wear):
self.tire_wear = tire_wear

def needs_service(self):
for tire in self.tire_wear:
if tire >= 0.9:
return True
return False
Empty file added tires/octoprime_tires.py
Empty file.
6 changes: 6 additions & 0 deletions tires/tires.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC


class Tires(ABC):
def needs_service(self):
pass
3 changes: 3 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def add_yearTodate(original_date, years_to_add):
result = original_date.replace(year=original_date.year + years_to_add)
return result