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

forage-lyft-task #139

Open
wants to merge 1 commit 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
Binary file added UML-Diagram.pdf
Binary file not shown.
File renamed without changes.
Empty file added battery/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions battery/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC


class Battery(ABC):
def needs_service(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_years_to_date


class NubbinBattery(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):
date_which_battery_should_be_serviced_by = add_years_to_date(self.last_service_date, 4)
if date_which_battery_should_be_serviced_by < self.current_date:
return True
else:
return False
15 changes: 15 additions & 0 deletions battery/spindler_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_years_to_date


class SpindlerBattery(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):
date_which_battery_should_be_serviced_by = add_years_to_date(self.last_service_date, 2)
if date_which_battery_should_be_serviced_by < 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.nubbin_battery import NubbinBattery
from battery.spindler_battery import SpindlerBattery
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 engine/engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from abc import ABC


class Engine(ABC):
def needs_service(self):
pass
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.

7 changes: 7 additions & 0 deletions serviceable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from abc import ABC, abstractmethod


class Serviceable(ABC):
@abstractmethod
def needs_service(self):
pass
Empty file added test/test_battery/__init__.py
Empty file.
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.spindler_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())
188 changes: 0 additions & 188 deletions test/test_car.py

This file was deleted.

Empty file added test/test_engine/__init__.py
Empty file.
Loading