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

Updated #154

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
1 change: 0 additions & 1 deletion car.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from abc import ABC, abstractmethod


class Car(ABC):
def __init__(self, last_service_date):
self.last_service_date = last_service_date
Expand Down
3 changes: 0 additions & 3 deletions engine/capulet_engine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from abc import ABC

from car import Car


class CapuletEngine(Car, ABC):
def __init__(self, last_service_date, current_mileage, last_service_mileage):
super().__init__(last_service_date)
Expand Down
7 changes: 1 addition & 6 deletions engine/model/calliope.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from datetime import datetime

from engine.capulet_engine import CapuletEngine


class Calliope(CapuletEngine):
def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 2)
if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced():
return True
else:
return False
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced()
7 changes: 1 addition & 6 deletions engine/model/glissade.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from datetime import datetime

from engine.willoughby_engine import WilloughbyEngine


class Glissade(WilloughbyEngine):
def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 2)
if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced():
return True
else:
return False
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced()
7 changes: 1 addition & 6 deletions engine/model/palindrome.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from datetime import datetime

from engine.sternman_engine import SternmanEngine


class Palindrome(SternmanEngine):
def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4)
if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced():
return True
else:
return False
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced()
7 changes: 1 addition & 6 deletions engine/model/rorschach.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from datetime import datetime

from engine.willoughby_engine import WilloughbyEngine


class Rorschach(WilloughbyEngine):
def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4)
if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced():
return True
else:
return False
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced()
7 changes: 1 addition & 6 deletions engine/model/thovex.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from datetime import datetime

from engine.capulet_engine import CapuletEngine


class Thovex(CapuletEngine):
def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4)
if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced():
return True
else:
return False
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced()
8 changes: 1 addition & 7 deletions engine/sternman_engine.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from abc import ABC

from car import Car


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

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

from car import Car


class WilloughbyEngine(Car, ABC):
def __init__(self, last_service_date, current_mileage, last_service_mileage):
super().__init__(last_service_date)
Expand Down
12 changes: 12 additions & 0 deletions test/batteries/SpindlerBattery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# battery/spindler_battery.py
from battery import Battery
from datetime import datetime

class SpindlerBattery(Battery):
def __init__(self, last_service_date, current_date):
self.last_service_date = last_service_date
self.current_date = current_date

def needs_service(self):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 3)
return service_threshold_date < self.current_date
19 changes: 19 additions & 0 deletions test/test_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest
from datetime import datetime
from battery.spindler_battery import SpindlerBattery

class TestSpindlerBattery(unittest.TestCase):
def test_battery_should_be_serviced_after_three_years(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
battery = SpindlerBattery(last_service_date, today)
self.assertTrue(battery.needs_service())

def test_battery_should_not_be_serviced_before_three_years(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 2)
battery = SpindlerBattery(last_service_date, today)
self.assertFalse(battery.needs_service())

if __name__ == '__main__':
unittest.main()
212 changes: 28 additions & 184 deletions test/test_car.py
Original file line number Diff line number Diff line change
@@ -1,188 +1,32 @@
import unittest
from datetime import datetime

from engine.model.calliope import Calliope
from engine.model.glissade import Glissade
from engine.model.palindrome import Palindrome
from engine.model.rorschach import Rorschach
from engine.model.thovex import Thovex


class TestCalliope(unittest.TestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
current_mileage = 0
last_service_mileage = 0

car = Calliope(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 1)
current_mileage = 0
last_service_mileage = 0

car = Calliope(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())

def test_engine_should_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 30001
last_service_mileage = 0

car = Calliope(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_engine_should_not_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 30000
last_service_mileage = 0

car = Calliope(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())


class TestGlissade(unittest.TestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
current_mileage = 0
last_service_mileage = 0

car = Glissade(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 1)
current_mileage = 0
last_service_mileage = 0

car = Glissade(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())

def test_engine_should_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 60001
last_service_mileage = 0

car = Glissade(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_engine_should_not_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 60000
last_service_mileage = 0

car = Glissade(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())


class TestPalindrome(unittest.TestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 5)
warning_light_is_on = False

car = Palindrome(last_service_date, warning_light_is_on)
self.assertTrue(car.needs_service())

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
warning_light_is_on = False

car = Palindrome(last_service_date, warning_light_is_on)
self.assertFalse(car.needs_service())

def test_engine_should_be_serviced(self):
last_service_date = datetime.today().date()
warning_light_is_on = True

car = Palindrome(last_service_date, warning_light_is_on)
self.assertTrue(car.needs_service())

def test_engine_should_not_be_serviced(self):
last_service_date = datetime.today().date()
warning_light_is_on = False

car = Palindrome(last_service_date, warning_light_is_on)
self.assertFalse(car.needs_service())


class TestRorschach(unittest.TestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 5)
current_mileage = 0
last_service_mileage = 0

car = Rorschach(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
current_mileage = 0
last_service_mileage = 0

car = Rorschach(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())

def test_engine_should_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 60001
last_service_mileage = 0

car = Rorschach(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_engine_should_not_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 60000
last_service_mileage = 0

car = Rorschach(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())


class TestThovex(unittest.TestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 5)
current_mileage = 0
last_service_mileage = 0

car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
current_mileage = 0
last_service_mileage = 0

car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())

def test_engine_should_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 30001
last_service_mileage = 0

car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertTrue(car.needs_service())

def test_engine_should_not_be_serviced(self):
last_service_date = datetime.today().date()
current_mileage = 30000
last_service_mileage = 0

car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())

from engine import Engine
from battery import Battery

class TestEngine(unittest.TestCase):
def setUp(self):
# Create an instance of Engine to be used in tests
self.engine = Engine()

def test_engine_start(self):
self.engine.start()
self.assertTrue(self.engine.is_running, "Engine should be running after start")

def test_engine_stop(self):
self.engine.stop()
self.assertFalse(self.engine.is_running, "Engine should not be running after stop")

class TestBattery(unittest.TestCase):
def setUp(self):
# Create an instance of Battery to be used in tests
self.battery = Battery()

def test_battery_charge(self):
self.battery.charge()
self.assertGreater(self.battery.charge_level, 0, "Battery charge level should be greater than 0 after charging")

def test_battery_discharge(self):
self.battery.discharge()
self.assertLess(self.battery.charge_level, 100, "Battery charge level should be less than 100 after discharging")

if __name__ == '__main__':
unittest.main()
27 changes: 27 additions & 0 deletions test/test_tires.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from tires.carrigan_tires import CarriganTires
from tires.octoprime_tires import OctoprimeTires

class TestTires(unittest.TestCase):
def test_carrigan_tires_should_be_serviced(self):
tire_wear = [0.2, 0.9, 0.4, 0.3]
tires = CarriganTires(tire_wear)
self.assertTrue(tires.needs_service())

def test_carrigan_tires_should_not_be_serviced(self):
tire_wear = [0.2, 0.7, 0.4, 0.3]
tires = CarriganTires(tire_wear)
self.assertFalse(tires.needs_service())

def test_octoprime_tires_should_be_serviced(self):
tire_wear = [0.9, 0.8, 0.7, 0.6]
tires = OctoprimeTires(tire_wear)
self.assertTrue(tires.needs_service())

def test_octoprime_tires_should_not_be_serviced(self):
tire_wear = [0.5, 0.6, 0.7, 0.8]
tires = OctoprimeTires(tire_wear)
self.assertFalse(tires.needs_service())

if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions tires/CarriganTires.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

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

def needs_service(self):
return any(wear >= 0.9 for wear in self.tire_wear)
Loading