Coverage for test/test_tire/test_tire.py: 98%
42 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"""Unittests for Tire objects.
3The tests cover creation of tire objects and the needs_service method.
4"""
6import unittest
7from abc import ABC
8from tire.base_tire import Tire
9from tire.carigan_tire import CariganTire
10from tire.octo_prime_tire import OctoprimeTire
13class TestTire(unittest.TestCase):
14 """Tests for the Tire Class.
16 The tests checks for the correct implementation of the Tire class.
17 """
18 def test_tire_is_subclass_of_abstract(self):
19 """Test that the Tire class is an instance of the ABC class."""
20 self.assertTrue(issubclass(Tire, ABC))
22 def test_tire_needs_service(self):
23 """Test that the Tire class has a needs_service method."""
24 self.assertTrue(hasattr(Tire, 'needs_service'))
27class TestCariganTire(unittest.TestCase):
28 """Tests for the CariganTire Class.
30 The tests checks for the correct implementation of the CariganTire class.
31 """
32 def test_carigan_tire_is_subclass_of_tire(self):
33 """Test that the CariganTire class is an instance of the Tire class"""
34 self.assertTrue(issubclass(CariganTire, Tire))
36 def test_carigan_tire_needs_service(self):
37 """Test that the CariganTire class has a needs_service method"""
38 self.assertTrue(hasattr(CariganTire, 'needs_service'))
40 def test_carigan_tire_has_tire_wear_sensor(self):
41 """Test that the CariganTire class has a tire_wear_sensor attribute"""
42 self.assertTrue(hasattr(CariganTire, 'tire_wear_sensor'))
44 def test_carigan_tire_wear_sensor_is_array(self):
45 """Test that the CariganTire tire wear sensor is implemented as an array attribute"""
46 self.assertTrue(isinstance(CariganTire.tire_wear_sensor, list))
48 def test_caringan_tire_needs_service_returns_bool(self):
49 """Test that the needs_service method returns a boolean"""
50 self.assertIsInstance(CariganTire([0.5, 0.8, 0.9]).needs_service(), bool)
52 def test_caringan_tire_needs_service_returns_true(self):
53 """Test that the needs_service method returns True
54 when one or more of the values in the tire wear sensor array is greater than or equal to 0.9
55 """
56 self.assertTrue(CariganTire([0.3, 0.9, 0.9]).needs_service())
58 def test_caringan_tire_needs_service_returns_false(self):
59 """Test that the needs_service method returns False.
60 when all the values in the tire wear sensor array is less than 0.9
61 """
62 self.assertFalse(CariganTire([0.3, 0.8, 0.8]).needs_service())
65class TestOctoprimeTire(unittest.TestCase):
66 """Tests for the OctoprimeTire Class.
68 The tests checks for the correct implementation of the OctoprimeTire class
69 """
70 def test_octoprime_tire_is_subclass_of_tire(self):
71 """Test that the OctoprimeTire class is an instance of the Tire class"""
72 self.assertTrue(issubclass(OctoprimeTire, Tire))
74 def test_octoprime_tire_needs_service(self):
75 """Test that the OctoprimeTire class has a needs_service method"""
76 self.assertTrue(hasattr(OctoprimeTire, 'needs_service'))
78 def test_octoprime_tire_has_tire_wear_sensor(self):
79 """Test that the OctoprimeTire class has a tire_wear_sensor attribute"""
80 self.assertTrue(hasattr(OctoprimeTire, 'tire_wear_sensor'))
82 def test_octoprime_tire_wear_sensor_is_array(self):
83 """Test that the OctoprimeTire tire wear sensor is implemented as an array attribute"""
84 self.assertTrue(isinstance(OctoprimeTire.tire_wear_sensor, list))
86 def test_octoprime_tire_needs_service_returns_bool(self):
87 """Test that the needs_service method returns a boolean"""
88 self.assertIsInstance(OctoprimeTire([0.5, 0.8, 0.9]).needs_service(), bool)
90 def test_octoprime_tire_needs_service_returns_true(self):
91 """Test that the needs_service method returns True
92 when the sum of all values in the tire wear array is greater than or equal to 3
93 """
94 self.assertTrue(OctoprimeTire([1.0, 1.0, 1.0]).needs_service())
96 def test_octoprime_tire_needs_service_returns_false(self):
97 """Test that the needs_service method returns False
98 when the sum of all values in the tire wear array is less than 3
99 """
100 self.assertFalse(OctoprimeTire([1.0, 1.0, 0.9]).needs_service())
103if __name__ == '__main__':
104 unittest.main()