Exemple #1
0
        public void TrafficLight()
        {
            TrafficLight light = new TrafficLight(new RedColour());

            light.Change();
            Assert.AreEqual(light.Colour, new YellowToGreen().Colour);
            light.Change();
            Assert.AreEqual(light.Colour, new GreenColour().Colour);
            light.Change();
            Assert.AreEqual(light.Colour, new YellowToRed().Colour);
            light.Change();
            Assert.AreEqual(light.Colour, new RedColour().Colour);
        }
        public void TestState()
        {
            var trafficLight = new TrafficLight {
                State = new RedLight()
            };

            trafficLight.ReportState();

            for (var i = 0; i < 8; i++)
            {
                trafficLight.Change();
                trafficLight.ReportState();
            }

            // OUTPUT: Red light.

            // OUTPUT: Red and yellow light.

            // OUTPUT: Green light.

            // OUTPUT: Yellow light.

            // OUTPUT: Red light.

            // OUTPUT: Red and yellow light.

            // OUTPUT: Green light.

            // OUTPUT: Yellow light.

            // OUTPUT: Red light.
        }
Exemple #3
0
        public void WhenColorIsRedMustChangeToGreen()
        {
            TrafficLight.Color expectedColor = TrafficLight.Color.Green;
            TrafficLight.Color actualColor;
            TrafficLight       trafficLight = new TrafficLight();

            trafficLight.Change();
            actualColor = trafficLight.CurrentColor;

            Assert.Equal(expectedColor, actualColor);
        }
Exemple #4
0
        public void WhenColorIsYellowMustChangeToRed()
        {
            TrafficLight.Color expectedColor = TrafficLight.Color.Red;
            TrafficLight.Color actualColor;
            TrafficLight       trafficLight = new TrafficLight();

            trafficLight.CurrentColor = TrafficLight.Color.Yellow;

            trafficLight.Change();
            actualColor = trafficLight.CurrentColor;

            Assert.Equal(expectedColor, actualColor);
        }