Пример #1
0
        public void TestSwapTile()
        {
            SlidingPuzzle puzzle = new SlidingPuzzle();

            int[] expected1 = { 1, 0, 2, 3, 4, 5, 6, 7, 8 };
            int[] expected2 = { 1, 4, 2, 3, 0, 5, 6, 7, 8 };
            int[] expected3 = { 1, 4, 2, 0, 3, 5, 6, 7, 8 };
            int[] expected4 = { 1, 4, 2, 6, 3, 5, 0, 7, 8 };
            int[] expected5 = { 1, 4, 2, 6, 3, 5, 7, 0, 8 };
            int[] expected6 = { 1, 4, 2, 6, 3, 5, 7, 8, 0 };
            int[] expected7 = { 1, 4, 2, 6, 3, 0, 7, 8, 5 };

            System.Console.WriteLine("Testing sequential swapping of tiles...");
            puzzle.SwapTile(0, 1);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected1));
            System.Console.WriteLine("\tSwapped 0,1");
            puzzle.SwapTile(1, 4);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected2));
            System.Console.WriteLine("\tSwapped 1,4");
            puzzle.SwapTile(4, 3);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected3));
            System.Console.WriteLine("\tSwapped 4,3");
            puzzle.SwapTile(3, 6);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected4));
            System.Console.WriteLine("\tSwapped 3,6");
            puzzle.SwapTile(6, 7);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected5));
            System.Console.WriteLine("\tSwapped 6,7");
            puzzle.SwapTile(7, 8);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected6));
            System.Console.WriteLine("\tSwapped 7,8");
            puzzle.SwapTile(8, 5);
            Assert.True(Enumerable.SequenceEqual(puzzle.Board, expected7));
            System.Console.WriteLine("\tSwapped 8,5");
        }