コード例 #1
0
ファイル: GridTests.cs プロジェクト: aistrate/SudokuSolver
        public void RepeatedGetAlternatives()
        {
            Grid grid = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 2, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 3, 0, 8, 1, 4, 2, 9, 6, 5 },
                new[] { 0, 0, 0, 5, 3, 0, 0, 0, 0 },
                new[] { 4, 5, 2, 9, 6, 8, 1, 7, 0 },
                new[] { 0, 0, 0, 0, 7, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 9, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 8, 0, 0, 0, 0 },
            });

            Grid step1 = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 2, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 3, 7, 8, 1, 4, 2, 9, 6, 5 },
                new[] { 0, 0, 0, 5, 3, 0, 0, 0, 0 },
                new[] { 4, 5, 2, 9, 6, 8, 1, 7, 0 },
                new[] { 0, 0, 0, 0, 7, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 9, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 8, 0, 0, 0, 0 },
            });

            Grid step2 = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 2, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 3, 7, 8, 1, 4, 2, 9, 6, 5 },
                new[] { 0, 0, 0, 5, 3, 0, 0, 0, 0 },
                new[] { 4, 5, 2, 9, 6, 8, 1, 7, 3 },
                new[] { 0, 0, 0, 0, 7, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 9, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 8, 0, 0, 0, 0 },
            });

            Grid step3 = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 2, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 5, 0, 0, 0, 0 },
                new[] { 3, 7, 8, 1, 4, 2, 9, 6, 5 },
                new[] { 0, 0, 0, 5, 3, 0, 0, 0, 0 },
                new[] { 4, 5, 2, 9, 6, 8, 1, 7, 3 },
                new[] { 0, 0, 0, 0, 7, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 9, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 8, 0, 0, 0, 0 },
            });

            Grid step4 = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 2, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 5, 0, 0, 0, 0 },
                new[] { 3, 7, 8, 1, 4, 2, 9, 6, 5 },
                new[] { 0, 0, 0, 5, 3, 7, 0, 0, 0 },
                new[] { 4, 5, 2, 9, 6, 8, 1, 7, 3 },
                new[] { 0, 0, 0, 0, 7, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 9, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 8, 0, 0, 0, 0 },
            });

            Grid[] alternatives = grid.GetAlternatives().ToArray();

            Assert.AreEqual(1, alternatives.Length, "Step 1 alternatives");
            Assert.AreEqual(step1, alternatives[0], "Step 1");

            alternatives = alternatives[0].GetAlternatives().ToArray();

            Assert.AreEqual(1, alternatives.Length, "Step 2 alternatives");
            Assert.AreEqual(step2, alternatives[0], "Step 2");

            alternatives = alternatives[0].GetAlternatives().ToArray();

            Assert.AreEqual(1, alternatives.Length, "Step 3 alternatives");
            Assert.AreEqual(step3, alternatives[0], "Step 3");

            alternatives = alternatives[0].GetAlternatives().ToArray();

            Assert.AreEqual(1, alternatives.Length, "Step 4 alternatives");
            Assert.AreEqual(step4, alternatives[0], "Step 4");
        }
コード例 #2
0
ファイル: GridTests.cs プロジェクト: aistrate/SudokuSolver
        public void GetAlternatives()
        {
            Grid grid = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 6, 0, 8, 0, 4, 2, 0, 3, 5 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 4, 5, 0, 9, 6, 8, 1, 7, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            });

            Grid alternative1 = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 6, 0, 8, 0, 4, 2, 0, 3, 5 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 4, 5, 2, 9, 6, 8, 1, 7, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            });

            Grid alternative2 = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 6, 0, 8, 0, 4, 2, 0, 3, 5 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 4, 5, 3, 9, 6, 8, 1, 7, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            });

            Grid[] alternatives = grid.GetAlternatives().ToArray();

            Assert.AreEqual(2, alternatives.Length, "Number of alternatives");

            Assert.AreEqual(alternative1, alternatives[0], "First alternative");
            Assert.AreEqual(alternative2, alternatives[1], "Second alternative");
        }
コード例 #3
0
ファイル: GridTests.cs プロジェクト: aistrate/SudokuSolver
        public void GetAlternativesFromEmpty()
        {
            Grid emptyGrid = new Grid(new[]
            {
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            });

            Grid alternative7 = new Grid(new[]
            {
                new[] { 7, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            });

            Grid[] alternatives = emptyGrid.GetAlternatives().ToArray();

            Assert.AreEqual(9, alternatives.Length, "Number of alternatives");

            Assert.AreEqual(alternative7, alternatives[6], "Alternative 7");
        }