-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_car.py
59 lines (50 loc) · 2.23 KB
/
test_car.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
Created on Apr 20, 2016
@author: Brian Borowski
CS115 - Car Test Script
'''
import unittest
from car import Car
from car import HybridCar
class Test(unittest.TestCase):
def test01(self):
c = Car('Honda', 'Accord', 21.5, 18)
self.assertTrue(isinstance(c, Car))
self.assertFalse(isinstance(c, HybridCar))
self.assertAlmostEqual(c.mpg, 21.5)
self.assertAlmostEqual(c.tank_capacity, 18)
c.mpg = 22.5
self.assertAlmostEqual(c.mpg, 22.5)
c.tank_capacity = 19.3
self.assertAlmostEqual(c.tank_capacity, 19.3)
self.assertEqual(str(c), 'Honda Accord, MPG: 22.5, tank capacity: 19.3')
def test02(self):
c = Car('Honda', 'Civic', 29.5, 13)
self.assertTrue(isinstance(c, Car))
self.assertFalse(isinstance(c, HybridCar))
self.assertAlmostEqual(c.get_total_range(), 383.5)
self.assertEqual(str(c), 'Honda Civic, MPG: 29.5, tank capacity: 13') #getting an error here because my tank_capacity is 13.0
c.mpg = 30.5
c.tank_capacity = 14.2
self.assertAlmostEqual(c.get_total_range(), 433.10)
self.assertEqual(str(c), 'Honda Civic, MPG: 30.5, tank capacity: 14.2')
def test03(self):
hc = HybridCar('Toyota', 'Prius', 50.2, 8.8, 4.4, 25.8)
self.assertTrue(isinstance(hc, Car))
self.assertTrue(isinstance(hc, HybridCar))
self.assertAlmostEqual(hc.mpg, 50.2)
self.assertAlmostEqual(hc.tank_capacity, 8.8)
hc.mpg = 48
hc.tank_capacity = 9.1
self.assertAlmostEqual(hc.mpg, 48)
self.assertAlmostEqual(hc.tank_capacity, 9.1)
self.assertEqual(str(hc), 'Toyota Prius, MPG: 48, tank capacity: 9.1, battery kWh: 4.4, miles/kWh: 25.8')
def test04(self):
hc = HybridCar('Toyota', 'Prius', 51.2, 7.8, 4.4, 25.8)
self.assertTrue(isinstance(hc, Car))
self.assertTrue(isinstance(hc, HybridCar))
self.assertAlmostEqual(hc.get_battery_range(), 113.52)
self.assertAlmostEqual(hc.get_total_range(), 512.88)
self.assertEqual(str(hc), 'Toyota Prius, MPG: 51.2, tank capacity: 7.8, battery kWh: 4.4, miles/kWh: 25.8')
if __name__ == '__main__':
unittest.main()