Exemplo n.º 1
0
        public void Test_4_VeryHard()
        {
            int index = 1;

            int[]   clues1    = { 0, 0, 0, 5, 0, 0, 3, 0, 6, 3, 4, 0, 0, 0, 3, 0, 0, 0, 2, 4, 0, 2, 6, 2, 2, 2, 0, 0 };
            int[][] expected1 =
            {
                new[] { 3, 5, 6, 1, 7, 2, 4 },
                new[] { 7, 6, 5, 2, 4, 3, 1 },
                new[] { 2, 7, 1, 3, 6, 4, 5 },
                new[] { 4, 3, 7, 6, 1, 5, 2 },
                new[] { 6, 4, 2, 5, 3, 1, 7 },
                new[] { 1, 2, 3, 4, 5, 7, 6 },
                new[] { 5, 1, 4, 7, 2, 6, 3 }
            };
            Stack <int> orderedClues = new Stack <int>(Enumerable.Range(0, 4 * Skyscrapers.Size)
                                                       .Select(clueIndex => new Tuple <int, int[]>(clueIndex, SkyscrapersTests4by4.GetLaneIndices2(clueIndex))).OrderBy(t => t.Item2[0])
                                                       .ThenBy(t => t.Item2[1]).Select(t => clues1[t.Item1]).Reverse());

            Skyscrapers.Expected = expected1;
            var actual = Skyscrapers.SolvePuzzle(clues1);

            CollectionAssert.AreEqual(expected1, actual,
                                      SkyscrapersTests4by4.ErrorMessage(expected1, actual, orderedClues));
        }
Exemplo n.º 2
0
        public void SolveSkyscrapers6()
        {
            var clues = new[] {
                2, 2, 3, 1,
                1, 2, 2, 3,
                3, 2, 1, 3,
                2, 2, 1, 3
            };

            var expected = new[] {
                new [] { 2, 3, 1, 4 },
                new [] { 4, 1, 2, 3 },
                new [] { 3, 2, 4, 1 },
                new [] { 1, 4, 3, 2 }
            };


            Stack <int> orderedClues = new Stack <int>(Enumerable.Range(0, 4 * Skyscrapers.Size)
                                                       .Select(clueIndex => new Tuple <int, int[]>(clueIndex, GetLaneIndices2(clueIndex))).OrderBy(t => t.Item2[0])
                                                       .ThenBy(t => t.Item2[1]).Select(t => clues[t.Item1]).Reverse());

            var actual = Skyscrapers.SolvePuzzle(clues);

            CollectionAssert.AreEqual(expected, actual,
                                      ErrorMessage(expected, actual, orderedClues)
                                      );
        }
Exemplo n.º 3
0
 public static string ErrorMessage(int[][] expected, int[][] actual, Stack <int> orderedClues)
 {
     return(Environment.NewLine
            + String.Join(Environment.NewLine, expected.Select(r => String.Join("|", r)))
            + Environment.NewLine + Environment.NewLine
            + "   " + String.Join("  ", Enumerable.Range(0, Size).Select(i => orderedClues.Pop())) + Environment.NewLine
            + String.Join(Environment.NewLine, Skyscrapers.AllCells.Select(r => orderedClues.Pop() + " |" + String.Join("|", r.Select(c => c.PossibleValues.Count == 1  ? c.PossibleValues.First() == expected[c.X][c.Y] ? c.PossibleValues.First() + " " : c.PossibleValues.First() + "*" : " *")) + "| " + orderedClues.Pop())) + Environment.NewLine
            + "   " + String.Join("  ", Enumerable.Range(0, Size).Select(i => orderedClues.Pop())) + Environment.NewLine
            + Environment.NewLine + Skyscrapers.PrintValues()
            + Environment.NewLine + "Difference index: " + DifferenceIndex(expected, actual)
            + Environment.NewLine);
 }
Exemplo n.º 4
0
        public void Test_2_VeryHard()
        {
            int index = 1;

            int[]       clues1       = clues[index];
            int[][]     expected1    = expected[index];
            Stack <int> orderedClues = new Stack <int>(Enumerable.Range(0, 4 * Skyscrapers.Size)
                                                       .Select(clueIndex => new Tuple <int, int[]>(clueIndex, SkyscrapersTests4by4.GetLaneIndices2(clueIndex))).OrderBy(t => t.Item2[0])
                                                       .ThenBy(t => t.Item2[1]).Select(t => clues1[t.Item1]).Reverse());

            var actual = Skyscrapers.SolvePuzzle(clues1);

            CollectionAssert.AreEqual(expected1, actual,
                                      SkyscrapersTests4by4.ErrorMessage(expected1, actual, orderedClues));
        }