Coverage for test/test_engine/test_engine.py: 98%
46 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-09 21:08 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-09 21:08 +0000
1"""Unit Tests for the Base Engine and specialised Engines classes.
3This module contains unit tests for the Base Engine and specialised Engines."""
5import unittest
6from abc import ABC
7from engine.base_engine import Engine
8from engine.capulet_engine import CapuletEngine
9from engine.sternman_engine import SternmanEngine
10from engine.willoughby_engine import WilloughbyEngine
13class TestEngine(unittest.TestCase):
14 """Tests for the Engine Class.
16 This tests that the Engine base class is correctly implemented according to specification.
17 """
18 def test_engine_is_subclass_of_abstract_base_class(self):
19 """Test that the Engine class is an instance of the ABC class."""
20 self.assertTrue(issubclass(Engine, ABC))
22 def test_engine_needs_service(self):
23 """Test that the Engine class has a needs_service method."""
24 self.assertTrue(hasattr(Engine, 'needs_service'))
27class TestCapuletEngine(unittest.TestCase):
28 """Tests for the CapuletEngine Class.
30 This tests that the CapuletEngine class is correctly implemented.
31 """
32 def test_capulet_engine_is_subclass_of_engine(self):
33 """Test that the CapuletEngine class is an instance of the Engine class."""
34 self.assertTrue(issubclass(CapuletEngine, Engine))
36 def test_capulet_engine_needs_service(self):
37 """Test that the CapuletEngine class has a needs_service method"""
38 self.assertTrue(hasattr(CapuletEngine, 'needs_service'))
40 def test_capulet_engine_needs_service_returns_bool(self):
41 """Test that the needs_service method returns a boolean"""
42 self.assertIsInstance(CapuletEngine(0, 0).needs_service(), bool)
44 def test_capulet_engine_needs_service_returns_true(self):
45 """Test that the needs_service method returns True when the engine needs service"""
46 self.assertTrue(CapuletEngine(30001, 0).needs_service())
48 def test_capulet_engine_needs_service_returns_false(self):
49 """Test that the needs_service method returns False when the engine does not need service"""
50 self.assertFalse(CapuletEngine(30000, 0).needs_service())
53class TestSternmanEngine(unittest.TestCase):
54 """Tests for the SternmanEngine Class.
56 This tests that the SternmanEngine class is correctly implemented.
57 """
58 def test_sternman_engine_is_subclass_of_engine(self):
59 """Test that the SternmanEngine class is an instance of the Engine class."""
60 self.assertTrue(issubclass(SternmanEngine, Engine))
62 def test_sternman_engine_needs_service(self):
63 """Test that the SternmanEngine class has a needs_service method."""
64 self.assertTrue(hasattr(SternmanEngine, 'needs_service'))
66 def test_sternman_engine_needs_service_returns_bool(self):
67 """Test that the needs_service method returns a boolean"""
68 self.assertIsInstance(SternmanEngine(True).needs_service(), bool)
70 def test_sternman_engine_needs_service_returns_true(self):
71 """Test that the needs_service method returns True when the engine needs service."""
72 self.assertTrue(SternmanEngine(True).needs_service())
74 def test_sternman_engine_needs_service_returns_false(self):
75 """Test that the needs_service method returns False when the engine does not need service."""
76 self.assertFalse(SternmanEngine(False).needs_service())
79class TestWilloughbyEngine(unittest.TestCase):
80 """Tests for the WilloughbyEngine Class.
82 This tests that the WilloughbyEngine class is correctly implemented.
83 """
84 def test_willoughby_engine_is_subclass_of_engine(self):
85 """Test that the WilloughbyEngine class is an instance of the Engine class."""
86 self.assertTrue(issubclass(WilloughbyEngine, Engine))
88 def test_willoughby_engine_needs_service(self):
89 """Test that the WilloughbyEngine class has a needs_service method."""
90 self.assertTrue(hasattr(WilloughbyEngine, 'needs_service'))
92 def test_willoughby_engine_needs_service_returns_bool(self):
93 """Test that the needs_service method returns a boolean."""
94 self.assertIsInstance(WilloughbyEngine(0, 0).needs_service(), bool)
96 def test_willoughby_engine_needs_service_returns_true(self):
97 """Test that the needs_service method returns True when the engine needs service."""
98 self.assertTrue(WilloughbyEngine(60001, 0).needs_service())
100 def test_willoughby_engine_needs_service_returns_false(self):
101 """Test that the needs_service method returns False when the engine does not need service."""
102 self.assertFalse(WilloughbyEngine(60000, 0).needs_service())
106if __name__ == '__main__':
107 unittest.main()