-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_trafficLightController.py
More file actions
54 lines (42 loc) · 1.75 KB
/
test_trafficLightController.py
File metadata and controls
54 lines (42 loc) · 1.75 KB
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
import unittest
from TrafficLightController import TrafficLightController
from junction import Junction
from light import Light
from setup import mainSetup
class TestTrafficLightController(unittest.TestCase):
def test_getCarsWaiting(self):
lights = testJunction.getTrafficLights()
lights[0].setCarsAtLight(8)
lights[1].setCarsAtLight(10)
expectedResult = 10
actualResult = TrafficLightController.getCarsWaiting(self, lights)
self.assertEqual(expectedResult, actualResult)
def test_getCarsWaitingIncreaseCycles(self):
lights = testJunction.getTrafficLights()
lights[0].setCarsAtLight(0)
TrafficLightController.getCarsWaiting(self, lights)
expectedResult = 1
actualResult = lights[0].getCyclesWithoutCar()
self.assertEqual(expectedResult, actualResult)
def test_getCarsWaitingResetCycles(self):
lights = testJunction.getTrafficLights()
lights[0].setCarsAtLight(0)
TrafficLightController.getCarsWaiting(self, lights)
lights[0].setCarsAtLight(5)
TrafficLightController.getCarsWaiting(self, lights)
expectedResult = 0
actualResult = lights[0].getCyclesWithoutCar()
self.assertEqual(expectedResult, actualResult)
def test_controller(self):
controller = TrafficLightController()
lights = testJunction.getTrafficLights()
lights[0].setCarsAtLight(0)
lights[1].setCarsAtLight(1)
TrafficLightController.controllerTest(controller, lights)
expectedResult = "Red"
actualResult = lights[0].getCurrentState()
self.assertEqual(expectedResult, actualResult)
if __name__ == "__main__":
mainSetup()
testJunction = Junction.junctions[0]
unittest.main()