-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_light.py
67 lines (49 loc) · 2.36 KB
/
test_light.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
60
61
62
63
64
65
66
67
import unittest
from light import Light
from junction import Junction
class TestLight(unittest.TestCase):
sourceJunction = Junction()
destJunction = Junction()
prevJunction = Junction()
def test_eqMethod(self):
testLight1 = Light(sourceJunction=TestLight.sourceJunction, destJunction=TestLight.destJunction, prevJunction=TestLight.prevJunction)
testLight2 = Light(sourceJunction=TestLight.sourceJunction, destJunction=TestLight.destJunction, prevJunction=TestLight.prevJunction)
self.assertTrue(testLight1 == testLight2)
#test trafficLightStateChanges
def test_TrafficLightLeavingIdleMode(self):
testLight = Light(TestLight.sourceJunction, TestLight.destJunction, TestLight.prevJunction)
testLight.changeTrafficLightState()
expectedResult = "Red"
actualResult = testLight.getCurrentState()
self.assertEqual(actualResult, expectedResult)
def test_changeToGreen(self):
testLight = Light(TestLight.sourceJunction, TestLight.destJunction, TestLight.prevJunction)
for i in range(2):
testLight.changeTrafficLightState()
expectedResult = "Green"
actualResult = testLight.getCurrentState()
self.assertEqual(actualResult, expectedResult)
def test_changeToAmber(self):
testLight = Light(TestLight.sourceJunction, TestLight.destJunction, TestLight.prevJunction)
for i in range(3):
testLight.changeTrafficLightState()
expectedResult = "Amber"
actualResult = testLight.getCurrentState()
self.assertEqual(actualResult, expectedResult)
def test_changeToRed(self):
testLight = Light(TestLight.sourceJunction, TestLight.destJunction, TestLight.prevJunction)
for i in range(4):
testLight.changeTrafficLightState()
expectedResult = "Red"
actualResult = testLight.getCurrentState()
self.assertEqual(actualResult, expectedResult)
def test_enterIdleMode(self):
testLight = Light(TestLight.sourceJunction, TestLight.destJunction, TestLight.prevJunction)
for i in range(2):
testLight.changeTrafficLightState()
testLight.enterIdleMode()
expectedResult = "Idle"
actualResult = testLight.getCurrentState()
self.assertEqual(actualResult, expectedResult)
if __name__ == "__main__":
unittest.main()