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

Backend Commit #110

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions car.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABC, abstractmethod


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

@abstractmethod
def needs_service(self):
pass
"""Check if the car needs servicing."""
pass
14 changes: 14 additions & 0 deletions engine/model/tire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Tire:
name = ""
service_criteria = None

def __init__(self, name):
self.name = name

def needs_service(self, tire_wear_array):
return self.service_criteria(tire_wear_array)
def service_criteria(tire_wear_array):
return any(tire_wear >= 0.9 for tire_wear in tire_wear_array)
def service_criteria(tire_wear_array):
return sum(tire_wear_array) >= 3

161 changes: 81 additions & 80 deletions test/test_car.py
Original file line number Diff line number Diff line change
@@ -1,188 +1,189 @@
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 CarTestCase(unittest.TestCase):
def setUp(self):
self.today = datetime.today().date()

def assertCarNeedsService(self, car, expected_result):
self.assertEqual(car.needs_service(), expected_result)

class TestCalliope(unittest.TestCase):
class TestCalliope(CarTestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, True)

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 1)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, False)

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

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

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

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


class TestGlissade(unittest.TestCase):
class TestGlissade(CarTestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, True)

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 1)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, False)

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

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

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

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


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

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

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

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

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

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

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

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

self.assertCarNeedsService(car, False)

class TestRorschach(unittest.TestCase):
class TestRorschach(CarTestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 5)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, True)

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, False)

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

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

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

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

self.assertCarNeedsService(car, False)

class TestThovex(unittest.TestCase):
class TestThovex(CarTestCase):
def test_battery_should_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 5)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, True)

def test_battery_should_not_be_serviced(self):
today = datetime.today().date()
last_service_date = today.replace(year=today.year - 3)
last_service_date = self.today.replace(year=self.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())
self.assertCarNeedsService(car, False)

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

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

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



# UNIT TEST

class TestThovex(CarTestCase):
def test_battery_should_be_serviced(self):
last_service_date = self.today.replace(year=self.today.year - 5)
current_mileage = 0
last_service_mileage = 0
car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertCarNeedsService(car, True)

def test_battery_should_not_be_serviced(self):
last_service_date = self.today.replace(year=self.today.year - 3)
current_mileage = 0
last_service_mileage = 0
car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertCarNeedsService(car, False)

def test_engine_should_be_serviced(self):
last_service_date = self.today
current_mileage = 30001
last_service_mileage = 0
car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertFalse(car.needs_service())
self.assertCarNeedsService(car, True)

def test_engine_should_not_be_serviced(self):
last_service_date = self.today
current_mileage = 30000
last_service_mileage = 0
car = Thovex(last_service_date, current_mileage, last_service_mileage)
self.assertCarNeedsService(car, False)

if __name__ == '__main__':
unittest.main()
unittest.main()