Exemple #1
0
        public void GetNonViewAndNonDuplicateViolatingSizesTest(int row, int col, params int[] expectedClues)
        {
            //arrange
            var clues = new[]
            {
                3, 2, 2, 3, 2, 1,
                1, 2, 3, 3, 2, 2,
                5, 1, 2, 2, 4, 3,
                3, 2, 1, 2, 2, 4
            };

            int[,] grid =
            {
                //clues:3, 2, 2, 3, 2, 1
                /*4*/ { 0, 1, 4, 3, 5, 6 }, //1
                /*2*/ { 1, 0, 3, 2, 4, 5 }, //2
                /*2*/ { 4, 3, 0, 5, 1, 2 }, //3
                /*1*/ { 6, 5, 2, 0, 3, 4 }, //3
                /*2*/ { 5, 4, 1, 6, 0, 3 }, //2
                /*3*/ { 3, 2, 5, 4, 6, 0 } //2
                //clues:3, 4, 2, 2, 1, 5,
            };

            //act
            var actual = SkyscrapersPuzzle6By6.GetNonViewAndNonDuplicateViolatingSizes(grid, clues, row, col).ToArray();

            //assert
            CollectionAssert.AreEqual(expectedClues, actual);
        }
Exemple #2
0
        [Test] //6X6 down for col 3 (index 2)
        public void IsValidViewTest()
        {
            //arrange
            var correctClues = new[]
            {
                3, 2, 2, 2, 2, 1,
                1,
                2,
                3,
                3,
                2,
                6,
                3, 2, 2, 2, 2, 1,
                1, 3, 2, 4, 2, 6
            };

            var incorrectClues = new[]
            {
                4, 1, 3, 5, 6, 2,
                2,
                1,
                1,
                6,
                5,
                1,
                4, 5, 6, 3, 1, 2,
                2, 4, 3, 5, 6, 1
            };

            //not a valid grid, but for testing visibility it provides many cases
            int[,] grid =
            {
                { 1, 2, 3, 4, 5, 6 },
                { 5, 6, 1, 2, 3, 4 },
                { 3, 4, 5, 6, 2, 1 },
                { 5, 6, 3, 2, 4, 1 },
                { 2, 1, 4, 3, 6, 5 },
                { 6, 5, 4, 3, 2, 1 }
            };

            //act
            bool actual;

            //assert
            for (int i = 0; i < correctClues.Length; i++)
            {
                actual = SkyscrapersPuzzle6By6.IsValidView(grid, correctClues, i);
                Assert.AreEqual(true, actual,
                                $"Visible buildings don't match clue at index {i} for correct clues (clue says {correctClues[i]} should be visible)");
                actual = SkyscrapersPuzzle6By6.IsValidView(grid, incorrectClues, i);
                Assert.AreEqual(false, actual,
                                $"Visible buildings match clue at index {i} for incorrect clues (clue says {incorrectClues[i]} should be visible)");
            }
        }
Exemple #3
0
        [TestCase(0, 2, 5, 2, 2, 6 * 4)] //6X6 down for col 3 (index 2)
        public void GetViewingDirectionTest(int expectedRowStart, int expectedColumnStart, int expectedRowEnd,
                                            int expectedColumnEnd, int targetIndex, int totalClues)
        {
            //arrange
            //For this test only clue dimensions matter, not their content, hence the blank declaration
            var clues = new int[totalClues];

            //act
            var sut = SkyscrapersPuzzle6By6.GetViewingDirection(clues, targetIndex);

            //assert
            Assert.AreEqual(expectedRowStart, sut.Item1, "for row start index");
            Assert.AreEqual(expectedColumnStart, sut.Item2, "for col start index");

            Assert.AreEqual(expectedRowEnd, sut.Item3, "for row end index");
            Assert.AreEqual(expectedColumnEnd, sut.Item4, "for col end index");
        }