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

1"""Unit Tests for the Base Engine and specialised Engines classes. 

2 

3This module contains unit tests for the Base Engine and specialised Engines.""" 

4 

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 

11 

12 

13class TestEngine(unittest.TestCase): 

14 """Tests for the Engine Class. 

15 

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)) 

21 

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')) 

25 

26 

27class TestCapuletEngine(unittest.TestCase): 

28 """Tests for the CapuletEngine Class. 

29 

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)) 

35 

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')) 

39 

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) 

43 

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()) 

47 

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()) 

51 

52 

53class TestSternmanEngine(unittest.TestCase): 

54 """Tests for the SternmanEngine Class. 

55 

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)) 

61 

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')) 

65 

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) 

69 

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()) 

73 

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()) 

77 

78 

79class TestWilloughbyEngine(unittest.TestCase): 

80 """Tests for the WilloughbyEngine Class. 

81 

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)) 

87 

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')) 

91 

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) 

95 

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()) 

99 

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()) 

103 

104 

105 

106if __name__ == '__main__': 

107 unittest.main()