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

Task 3 #128

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.
4 changes: 4 additions & 0 deletions battery/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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 test.util 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 test.util 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, 3)
if date_which_battery_should_be_serviced_by < self.current_date:
return True
else:
return False
10 changes: 0 additions & 10 deletions car.py

This file was deleted.

13 changes: 5 additions & 8 deletions engine/capulet_engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from abc import ABC
from engine.engine import Engine

from car import Car


class CapuletEngine(Car, ABC):
def __init__(self, last_service_date, current_mileage, last_service_mileage):
super().__init__(last_service_date)
class CapuletEngine(Engine):
def __init__(self, current_mileage, last_service_mileage):
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage

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

class Engine(ABC):
def needs_service(self):
pass
13 changes: 5 additions & 8 deletions engine/sternman_engine.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from abc import ABC
from engine.engine import Engine

from car import Car


class SternmanEngine(Car, ABC):
def __init__(self, last_service_date, warning_light_is_on):
super().__init__(last_service_date)
class SternmanEngine(Engine):
def __init__(self, warning_light_is_on):
self.warning_light_is_on = warning_light_is_on

def engine_should_be_serviced(self):
def needs_service(self):
if self.warning_light_is_on:
return True
else:
return False
return False
13 changes: 5 additions & 8 deletions engine/willoughby_engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from abc import ABC
from engine.engine import Engine

from car import Car


class WilloughbyEngine(Car, ABC):
def __init__(self, last_service_date, current_mileage, last_service_mileage):
super().__init__(last_service_date)
class WilloughbyEngine(Engine):
def __init__(self, current_mileage, last_service_mileage):
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage

def engine_should_be_serviced(self):
return self.current_mileage - self.last_service_mileage > 60000
def needs_service(self):
return self.current_mileage - self.last_service_mileage > 60000
10 changes: 10 additions & 0 deletions test/car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from serviceable import Serviceable


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

def needs_service(self):
return self.engine.needs_service() or self.battery.needs_service()
38 changes: 38 additions & 0 deletions test/car_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from battery.nubbin_battery import NubbinBattery
from battery.spindler_battery import SpindlerBattery
from engine.capulet_engine import CapuletEngine
from engine.sternman_engine import SternmanEngine
from engine.willoughby_engine import WilloughbyEngine
from test.car import Car


class CarFactory:
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

def create_palindrome(current_date, last_service_date, current_mileage, last_service_mileage):
engine = SternmanEngine(current_mileage, last_service_mileage)
battery = SpindlerBattery(current_date, last_service_date)
car = Car(engine, battery)
return car

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

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

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
7 changes: 7 additions & 0 deletions test/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
31 changes: 31 additions & 0 deletions test/test_batteries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
from datetime import date

from battery.nubbin_battery import NubbinBattery
from battery.spindler_battery import SpindlerBattery

class TestNubbinBattery(unittest.TestCase):
def test_needs_service(self):
current_date = date.fromisoformat("2023-11-04")
last_service_date = date.fromisoformat("2018-11-04")
battery = NubbinBattery(current_date, last_service_date)
self.assertTrue(battery.needs_service())

def test_does_not_needs_service(self):
current_date = date.fromisoformat("2023-11-04")
last_service_date = date.fromisoformat("2022-11-04")
battery = NubbinBattery(current_date, last_service_date)
self.assertFalse(battery.needs_service())

class TestSpindlerBattery(unittest.TestCase):
def test_needs_service(self):
current_date = date.fromisoformat("2023-11-04")
last_service_date = date.fromisoformat("2015-11-04")
battery = SpindlerBattery(current_date, last_service_date)
self.assertTrue(battery.needs_service())

def test_does_not_needs_service(self):
current_date = date.fromisoformat("2023-11-04")
last_service_date = date.fromisoformat("2022-11-04")
battery = SpindlerBattery(current_date, last_service_date)
self.assertFalse(battery.needs_service())
Loading