public void A_game_with_some_constraints_should_be_solved()
        {
            var game = new SudokuGame();

            game.SetConstrainedCell(new Coords(2, 2), 5);
            game.SetConstrainedCell(new Coords(5, 5), 5);
            game.SetConstrainedCell(new Coords(8, 8), 5);
            game.UnsetConstrainedCell(new Coords(8, 8));

            game.SetConstrainedCell(new Coords(1, 1), 1);
            game.SetConstrainedCell(new Coords(3, 1), 2);
            game.SetConstrainedCell(new Coords(5, 1), 3);
            game.SetConstrainedCell(new Coords(1, 3), 4);
            game.SetConstrainedCell(new Coords(3, 3), 6);
            game.SetConstrainedCell(new Coords(5, 3), 7);

            var iterator = game.GetLinearIterator();
            var solver   = new SudokuGameSolver(iterator, game);
            var result   = solver.Solve();

            Assert.AreEqual(SolveResults.Solved, result);
            Assert.AreEqual(5, game.GetCellAt(new Coords(2, 2)).CurrentValue);
            Assert.AreEqual(5, game.GetCellAt(new Coords(5, 5)).CurrentValue);
            Assert.AreNotEqual(5, game.GetCellAt(new Coords(8, 8)).CurrentValue);
        }
Esempio n. 2
0
        public void SolveMatrix9by9_1st()
        {
            int[,] matrix9by9 = new int[, ]
            {
                { 5, 3, 0, 0, 7, 0, 0, 0, 0 },
                { 6, 0, 0, 1, 9, 5, 0, 0, 0 },
                { 0, 9, 8, 0, 0, 0, 0, 6, 0 },
                { 8, 0, 0, 0, 6, 0, 0, 0, 3 },
                { 4, 0, 0, 8, 0, 3, 0, 0, 1 },
                { 7, 0, 0, 0, 2, 0, 0, 0, 6 },
                { 0, 6, 0, 0, 0, 0, 2, 8, 0 },
                { 0, 0, 0, 4, 1, 9, 0, 0, 5 },
                { 0, 0, 0, 0, 8, 0, 0, 7, 9 }
            };

            int[,] answerForMatrix9by9 = new int[, ]
            {
                { 5, 3, 4, 6, 7, 8, 9, 1, 2 },
                { 6, 7, 2, 1, 9, 5, 3, 4, 8 },
                { 1, 9, 8, 3, 4, 2, 5, 6, 7 },
                { 8, 5, 9, 7, 6, 1, 4, 2, 3 },
                { 4, 2, 6, 8, 5, 3, 7, 9, 1 },
                { 7, 1, 3, 9, 2, 4, 8, 5, 6 },
                { 9, 6, 1, 5, 3, 7, 2, 8, 4 },
                { 2, 8, 7, 4, 1, 9, 6, 3, 5 },
                { 3, 4, 5, 2, 8, 6, 1, 7, 9 }
            };

            SudokuGameSolver sgs = new SudokuGameSolver();

            CollectionAssert.AreEqual(answerForMatrix9by9, sgs.solve(matrix: ref matrix9by9, size: matrix9by9.GetLength(1)));
        }
        public void An_empty_game_should_be_solved()
        {
            var game     = new SudokuGame();
            var iterator = game.GetLinearIterator();
            var solver   = new SudokuGameSolver(iterator, game);
            var result   = solver.Solve();

            Assert.AreEqual(SolveResults.Solved, result);
        }
Esempio n. 4
0
        public void SolveMatrix3by3()
        {
            int[,] matrix3by3 = new int[, ]
            {
                { 3, 2, 0 },
                { 0, 0, 3 },
                { 1, 3, 0 }
            };

            int[,] answerForMatrix3by3 = new int[, ]
            {
                { 3, 2, 1 },
                { 2, 1, 3 },
                { 1, 3, 2 }
            };

            SudokuGameSolver sudokuGameSolver = new SudokuGameSolver();

            CollectionAssert.AreEqual(answerForMatrix3by3, sudokuGameSolver.solve(matrix: matrix3by3, size: matrix3by3.GetLength(1)));
        }
Esempio n. 5
0
        public void SolveMatrix3by3_3rd()
        {
            int[,] matrix3by3 = new int[, ]
            {
                { 1, 0, 0 },
                { 0, 0, 0 },
                { 0, 3, 0 }
            };

            int[,] answerForMatrix3by3 = new int[, ]
            {
                { 1, 2, 3 },
                { 3, 1, 2 },
                { 2, 3, 1 }
            };

            SudokuGameSolver sgs = new SudokuGameSolver();

            CollectionAssert.AreEqual(answerForMatrix3by3, sgs.solve(matrix: ref matrix3by3, size: matrix3by3.GetLength(1)));
        }
Esempio n. 6
0
 public void MakeInstance()
 {
     SudokuGameSolver sudokuSolver = new SudokuGameSolver();
 }