Example #1
0
        public void ShouldStartTrafficLightCycle()
        {
            var configuration = new TrafficLightConfig();

            configuration.Add(TrafficLightState.Go, 4);
            configuration.Add(TrafficLightState.Stop, 4);
            SetTrafficLightConfiguration(configuration);

            var lights = new TrafficLights {
                _l1, _l2, _l3, _l4
            };
            var timer = new TrafficLightTimer();

            var tc1 = new TetheredTrafficLightCluster {
                _l1, _l2
            };

            tc1.Name = "TC-1";

            var pc1 = new PolarTrafficLightCluster(_l3)
            {
                { _l4 }
            };

            pc1.Name = "TC-2";

            Assert.IsTrue(lights.Add(tc1));
            Assert.IsTrue(lights.Add(pc1));

            var controller = new TrafficLightController(lights, timer);

            //Assert initial state is where expected
            Assert.AreEqual(TrafficLightState.StopThenGo, _l1.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l2.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l3.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l4.State);

            controller.Start();  //Will trigger traffic light state changes

            Thread.Sleep(2000);
            Assert.AreEqual(TrafficLightState.Go, _l1.State);
            Assert.AreEqual(TrafficLightState.Go, _l2.State);
            Assert.AreEqual(TrafficLightState.Go, _l3.State);
            Assert.AreEqual(TrafficLightState.Stop, _l4.State);

            Thread.Sleep(5000);
            Assert.AreEqual(TrafficLightState.Stop, _l1.State);
            Assert.AreEqual(TrafficLightState.Stop, _l2.State);
            Assert.AreEqual(TrafficLightState.Stop, _l3.State);
            Assert.AreEqual(TrafficLightState.Go, _l4.State);

            controller.Stop();
        }
Example #2
0
        public void ShouldSynchronizedAllPolarLights()
        {
            var lights = new TrafficLights {
                _l1, _l2, _l3, _l4
            };
            var timer = new TrafficLightTimer();

            var tc1 = new PolarTrafficLightCluster(_l3)
            {
                { _l1, _l2 }
            };

            tc1.Name = "TC-1";

            var tc2 = new PolarTrafficLightCluster(_l5)
            {
                { _l4 }
            };

            tc2.Name = "TC-2";

            Assert.IsTrue(lights.Add(tc1, tc2));

            var controller = new TrafficLightController(lights, timer);

            //Assert initial state is where expected
            Assert.AreEqual(TrafficLightState.StopThenGo, _l1.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l2.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l3.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l4.State);

            controller.Start();  //Will trigger traffic light state changes
            Thread.Sleep(2500);

            Assert.AreEqual(TrafficLightState.Go, _l3.State);
            Assert.AreEqual(TrafficLightState.Go, _l5.State);
            Assert.AreEqual(TrafficLightState.Stop, _l1.State);
            Assert.AreEqual(TrafficLightState.Stop, _l2.State);
            Assert.AreEqual(TrafficLightState.Stop, _l4.State);

            controller.Stop();
        }