Exemplo n.º 1
0
 def test_controllerAttr(self):
     """
     Test the attributes are set correctly
     """
     controller = TrafficLightController("WEST")
     self.assertEqual(controller.getName(), "WEST")
     self.assertTrue(controller.getTL() != None)
Exemplo n.º 2
0
 def test_otherInitWait(self):
     """
     Makes sure waits are set right on init
     """
     controller = TrafficLightController("TEST")
     self.assertEqual(controller.GetRightWait(), 0, msg="Right wait")
     self.assertEqual(controller.GetOtherWait(), 0, msg="Other wait")
Exemplo n.º 3
0
 def test_phaseStop(self):
     """
     test the phase stop function
     """
     controller = TrafficLightController("TEST")
     tl = controller.getTL()
     controller.phaseStop()
     self.assertEqual(tl.whatsOn(), [True, True, False, False, False, False])
Exemplo n.º 4
0
 def test_dualWaitIncrement(self):
     """
     Test the method handling incrementing both waits
     """
     controller = TrafficLightController("TEST")
     controller.IncrementBothWaits()
     self.assertEqual(controller.GetRightWait(), 1, msg="Right wait")
     self.assertEqual(controller.GetOtherWait(), 1, msg="Other wait")
Exemplo n.º 5
0
 def test_countAllCars(self):
     """
     Used to test the counnt all cars method
     """
     controller = TrafficLightController("TEST")
     car1 = Car("Car1", "EAST", "STRAIGHT")
     car2 = Car("Car2", "EAST", "RIGHT")
     car3 = Car("Car3", "EAST", "LEFT")
     lane = [car1, car2, car3, car3]
     self.assertEqual(simulator.CountAllCars(lane), (1, 3))
Exemplo n.º 6
0
 def test_partialOtherCycleTwo(self):
     """
     Test the other part of our other cycle
     """
     controller = TrafficLightController("TEST")
     tl = controller.getTL()
     controller.trafficLight.switchOff()
     controller.trafficLight.orangeOn()
     controller.trafficLight.tredOn()
     self.assertEqual(tl.whatsOn(), [False, True, True, False, False, False])
Exemplo n.º 7
0
 def test_partialRightCycle(self):
     """
     Test a part of our right cycle
     """
     controller = TrafficLightController("TEST")
     tl = controller.getTL()
     controller.trafficLight.switchOff()
     controller.trafficLight.redOn()
     controller.trafficLight.tgreenOn()
     self.assertEqual(tl.whatsOn(), [True, False, False, False, False, True])
Exemplo n.º 8
0
 def test_wait(self):
     """
     Tests our wait increment functions
     """
     controller = TrafficLightController("TEST")
     self.assertEqual(controller.GetRightWait(), 0)
     controller.IncrementRightWait()
     controller.IncrementRightWait()
     self.assertEqual(controller.GetRightWait(), 2)
     controller.ResetRightWait()
     self.assertEqual(controller.GetRightWait(), 0)
Exemplo n.º 9
0
    def test_dualWaitReset(self):
        """
        Test wait functions which do both at once
        """
        controller = TrafficLightController("TEST")
        controller.IncrementBothWaits()
        self.assertEqual(controller.GetRightWait(), 1, msg="Right wait")
        self.assertEqual(controller.GetOtherWait(), 1, msg="Other wait")

        controller.ResetBothWaits()
        self.assertEqual(controller.GetRightWait(), 0, msg="Right wait")
        self.assertEqual(controller.GetOtherWait(), 0, msg="Other wait")
Exemplo n.º 10
0
    def test_partialBrokenCycle(self):
        """
        Test the broken cycle logic, minus timings
        """
        controller = TrafficLightController("TEST")
        tl = controller.getTL()
        controller.trafficLight.switchOff()
        self.assertEqual(tl.whatsOn(), [False, False, False, False, False, False])

        controller.trafficLight.orangeOn()
        controller.trafficLight.torangeOn()
        self.assertEqual(tl.whatsOn(), [False, False, True, True, False, False])
Exemplo n.º 11
0
 def test_sensorAllGo(self):
     controller = TrafficLightController("MOCK")
     tl = controller.getTL()
     tl.switchOff()
     tl.greenOn()
     tl.tgreenOn()
     car1 = Car("Car1", "EAST", "STRAIGHT")
     car2 = Car("Car2", "EAST", "RIGHT")
     car3 = Car("Car3", "EAST", "LEFT")
     lane = [car1, car2, car3, car3]
     simulator.sensor(controller, lane)
     self.assertEqual(lane, [car2, car3, car3])
Exemplo n.º 12
0
 def test_sensorStraightOrange(self):
     """
     Test straight orange lights
     """
     controller = TrafficLightController("MOCK")
     tl = controller.getTL()
     tl.switchOff()
     tl.tredOn()
     tl.orangeOn()
     car1 = Car("Car1", "EAST", "STRAIGHT")
     car2 = Car("Car2", "EAST", "RIGHT")
     car3 = Car("Car3", "EAST", "LEFT")
     lane = [car1, car2, car3, car3]
     simulator.sensor(controller, lane)
     self.assertEqual(lane, [car2, car3])
Exemplo n.º 13
0
    def test_lightsBrokenLogic(self):
        """
        Tests lightsAreBroken works as intended
        """
        simulator.lightsAreBroken = True
        controller = TrafficLightController("TEST")
        tl = controller.getTL()
        tl.switchOff()
        tl.greenOn()
        tl.tgreenOn()
        car1 = Car("Car1", "EAST", "STRAIGHT")
        car2 = Car("Car2", "EAST", "RIGHT")
        car3 = Car("Car3", "EAST", "LEFT")
        lane = [car1, car2, car3, car3]
        simulator.sensor(controller, lane)
        self.assertEqual(lane, [car1, car2, car3, car3])

        # Reset the variable so as not to break anything
        simulator.lightsAreBroken = False
Exemplo n.º 14
0
    def test_waitReset(self):
        """
        Tests our wait reset functions
        """
        controller = TrafficLightController("TEST")
        self.assertEqual(controller.GetRightWait(), 0, msg="Right wait")
        controller.IncrementRightWait()
        controller.ResetRightWait()
        self.assertNotEqual(controller.GetRightWait(), 1, msg="Right wait")
        controller.ResetRightWait()
        controller.ResetRightWait()
        self.assertEqual(controller.GetRightWait(), 0, msg="Right wait")

        self.assertEqual(controller.GetOtherWait(), 0, msg="Other wait")
        controller.IncrementOtherWait()
        controller.ResetOtherWait()
        self.assertNotEqual(controller.GetOtherWait(), 1, msg="Other wait")
        controller.ResetOtherWait()
        controller.ResetOtherWait()
        self.assertEqual(controller.GetOtherWait(), 0, msg="Other wait")
Exemplo n.º 15
0
from controllers import Controller as TrafficLightController
import os
from termcolor import colored
import threading
import time
from cars import Car
import random
import sys

#Get the starting time to determine time elapsed
start = time.perf_counter()
#Store the number of cars generated
all_cars = 0

#Initialise each controller, one for each direction
northController = TrafficLightController("NORTH")
eastController = TrafficLightController("EAST")
southController = TrafficLightController("SOUTH")
westController = TrafficLightController("WEST")

#Create a lane as a list to store cars for each direction
northLane = []
eastLane = []
southLane = []
westLane = []

"""
    A function which generates a random set of cars depending on the number provided.
"""
def generateCars(number):
    global all_cars
Exemplo n.º 16
0
 def test_controllerAttr(self):
     controller = TrafficLightController("WEST")
     self.assertEqual(controller.getName(), "WEST")
     self.assertTrue(controller.getTL() != None)