Exemplo n.º 1
0
        public static void Y2015_Day06_LightGridDrawsCorrectly3By3()
        {
            // Arrange
            var target = new Day06.LightGrid(3, 3);

            target.TurnOn(new Point(0, 0));
            target.TurnOn(new Point(0, 2));
            target.TurnOn(new Point(1, 1));
            target.TurnOn(new Point(2, 0));
            target.TurnOn(new Point(2, 2));

            string expected = string.Format(CultureInfo.InvariantCulture, "101{0}010{0}101{0}", Environment.NewLine);

            // Act
            string actual = target.ToString();

            // Assert
            Assert.Equal(expected, actual);

            // Arrange
            target.TurnOff(new Rectangle(0, 0, 3, 3));
            target.TurnOn(new Rectangle(0, 0, 2, 2));

            expected = string.Format(CultureInfo.InvariantCulture, "110{0}110{0}000{0}", Environment.NewLine);

            // Act
            actual = target.ToString();

            // Assert
            Assert.Equal(expected, actual);

            // Arrange
            target.TurnOff(new Rectangle(0, 0, 3, 3));
            target.TurnOn(new Rectangle(1, 1, 2, 2));

            expected = string.Format(CultureInfo.InvariantCulture, "000{0}011{0}011{0}", Environment.NewLine);

            // Act
            actual = target.ToString();

            // Assert
            Assert.Equal(expected, actual);

            // Arrange
            target.IncrementBrightness(new Rectangle(1, 1, 2, 2), 2);

            expected = string.Format(CultureInfo.InvariantCulture, "000{0}033{0}033{0}", Environment.NewLine);

            // Act
            actual = target.ToString();

            // Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public static void Y2015_Day06_LightGridExhibitsCorrectBehavior(int width, int height)
        {
            var target = new Day06.LightGrid(width, height);

            Point minimum = new Point(0, 0);
            Point maximum = new Point(width - 1, height - 1);

            Assert.Equal(0, target.Brightness);
            Assert.Equal(0, target.Count);
            Assert.Equal(0, target[minimum]);
            Assert.Equal(0, target[maximum]);

            Assert.True(target.Toggle(minimum));
            Assert.Equal(1, target[minimum]);
            Assert.Equal(1, target.Brightness);
            Assert.Equal(1, target.Count);

            Assert.True(target.Toggle(maximum));
            Assert.Equal(1, target[maximum]);
            Assert.Equal(2, target.Brightness);
            Assert.Equal(2, target.Count);

            target.TurnOn(minimum);
            Assert.Equal(1, target[minimum]);
            Assert.Equal(2, target.Brightness);
            Assert.Equal(2, target.Count);

            target.TurnOff(minimum);
            Assert.Equal(0, target[minimum]);
            Assert.Equal(1, target.Brightness);
            Assert.Equal(1, target.Count);

            target.TurnOff(minimum);
            Assert.Equal(0, target[minimum]);
            Assert.Equal(1, target.Brightness);
            Assert.Equal(1, target.Count);

            target.TurnOff(maximum);
            Assert.Equal(0, target[maximum]);
            Assert.Equal(0, target.Brightness);
            Assert.Equal(0, target.Count);

            target.TurnOn(minimum);
            Assert.Equal(1, target[minimum]);
            Assert.Equal(1, target.Brightness);
            Assert.Equal(1, target.Count);

            Assert.False(target.Toggle(minimum));
            Assert.Equal(0, target[minimum]);
            Assert.Equal(0, target.Brightness);
            Assert.Equal(0, target.Count);

            Assert.True(target.Toggle(maximum));
            Assert.Equal(1, target[maximum]);
            Assert.Equal(1, target.Brightness);
            Assert.Equal(1, target.Count);

            Rectangle bounds = new Rectangle(0, 0, width, height);

            target.TurnOff(bounds);
            Assert.Equal(0, target[minimum]);
            Assert.Equal(0, target[maximum]);
            Assert.Equal(0, target.Brightness);
            Assert.Equal(0, target.Count);

            target.TurnOff(bounds);
            Assert.Equal(0, target[minimum]);
            Assert.Equal(0, target[maximum]);
            Assert.Equal(0, target.Brightness);
            Assert.Equal(0, target.Count);

            target.TurnOn(bounds);
            Assert.Equal(1, target[minimum]);
            Assert.Equal(1, target[maximum]);
            Assert.Equal(width * height, target.Brightness);
            Assert.Equal(width * height, target.Count);

            target.TurnOn(bounds);
            Assert.Equal(1, target[minimum]);
            Assert.Equal(1, target[maximum]);
            Assert.Equal(width * height, target.Brightness);
            Assert.Equal(width * height, target.Count);

            target.Toggle(bounds);
            Assert.Equal(0, target[minimum]);
            Assert.Equal(0, target[maximum]);
            Assert.Equal(0, target.Brightness);
            Assert.Equal(0, target.Count);

            target.IncrementBrightness(minimum, 1);
            target.IncrementBrightness(minimum, 2);
            target.IncrementBrightness(minimum, 3);
            target.IncrementBrightness(minimum, -4);

            Assert.Equal(2, target[minimum]);
            Assert.Equal(2, target.Brightness);
            Assert.Equal(1, target.Count);

            target.IncrementBrightness(maximum, 10);

            Assert.Equal(2, target[minimum]);
            Assert.Equal(10, target[maximum]);
            Assert.Equal(12, target.Brightness);
            Assert.Equal(2, target.Count);

            target.IncrementBrightness(minimum, -3);

            Assert.Equal(0, target[minimum]);
            Assert.Equal(10, target[maximum]);
            Assert.Equal(10, target.Brightness);
            Assert.Equal(1, target.Count);
        }