Пример #1
0
        public void Solve6x6Test()
        {
            var puzzle = @"100000
                        020000
                        003000
                        000400
                        000050
                        000000
                        ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);

            Assert.AreEqual(puzzle, sudoku.ToString());

            var solver = new SudokuSolver(sudoku);

            solver.Solve();

            var solution = @"134265
                            526134
                            243516
                            615423
                            461352
                            352641
                            ".Replace(" ", "");

            Assert.AreEqual(solution, sudoku.ToString());
            Assert.IsTrue(sudoku.IsSolved());
        }
Пример #2
0
        public void Solve3Test()
        {
            var puzzle = @"293040100
                        516230740
                        847156000
                        354002690
                        600415000
                        000900000
                        000394802
                        000600005
                        000521000
                        ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);

            Assert.AreEqual(puzzle, sudoku.ToString());

            var solver = new SudokuSolver(sudoku);

            solver.Solve();

            var solution = @"293748156
                            516239748
                            847156239
                            354872691
                            629415387
                            781963524
                            165394872
                            432687915
                            978521463
                            ".Replace(" ", "");

            Assert.AreEqual(solution, sudoku.ToString());
            Assert.IsTrue(sudoku.IsSolved());
        }
Пример #3
0
        public void SerializationCopyTest2()
        {
            // arrange
            var puzzle = @"100008400
                            020004900
                            903256000
                            600000571
                            410805062
                            532000004
                            000582709
                            001300040
                            008100005
                            ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);
            var solver = new SudokuSolver(sudoku);

            // act
            solver.Solve();
            var sudokuCopy = sudoku.DeepCopy();

            sudokuCopy.SetCellValue(0, 1, 0, "manual");
            sudokuCopy.UpdatePossibleValuesInAllRegions();

            // assert
            Assert.IsTrue(sudoku.IsSolved());
            Assert.IsFalse(sudokuCopy.IsSolved());
        }
Пример #4
0
        public void SolveEmpty4x4Test()
        {
            var puzzle = @"0000
                        0000
                        0000
                        0000
                        ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);
            var solver = new SudokuSolver(sudoku);

            solver.Solve();
            Assert.IsTrue(sudoku.IsSolved());
        }
Пример #5
0
        public void Solve12x12Test()
        {
            var puzzle = @"5, 0, 0,10, 0,12, 0, 0, 1, 7, 0,11
                             0, 3, 2, 0, 0, 0, 0, 6, 0,10, 4, 0
                             1, 6, 0, 0, 0, 0, 0, 0, 0, 0,12, 0
                             3, 0, 0, 0,11, 0, 6, 0, 0, 0, 0, 8
                             0, 4, 0, 0,12, 1, 0, 7,11, 0, 0, 0
                             0, 0, 0, 6, 0,10, 4, 8, 0, 0, 0,12
                             2, 0, 0, 0,10, 4, 8, 0, 6, 0, 0, 0
                             0, 0, 0, 4, 6, 0, 7,11, 0, 0, 1, 0
                            11, 0, 0, 0, 0, 3, 0, 2, 0, 0, 0,10
                             0,10, 0, 0, 0, 0, 0, 0, 0, 0, 8, 4
                             0, 7, 8, 0, 9, 0, 0, 0, 0, 2,11, 0
                             6, 0, 9, 5, 0, 0,11, 0,10, 0, 0, 7
                        ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);

            Assert.AreEqual(puzzle, sudoku.ToString().Replace(" ", ""));

            var solver = new SudokuSolver(sudoku);

            solver.Solve();
            Assert.IsTrue(sudoku.IsSolved());
        }
Пример #6
0
        public void Solve4x4Test()
        {
            var puzzle = @"1000
                        0200
                        0030
                        0004
                        ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);

            Assert.AreEqual(puzzle, sudoku.ToString());

            var solver = new SudokuSolver(sudoku);

            solver.Solve();

            var solution = @"1342
                            4213
                            2431
                            3124
                            ".Replace(" ", "");

            Assert.AreEqual(solution, sudoku.ToString());
            Assert.IsTrue(sudoku.IsSolved());
        }
Пример #7
0
        public void SerializationCopyTest()
        {
            // arrange
            var puzzle = @"100008400
                            020004900
                            903256000
                            600000571
                            410805062
                            532000004
                            000582709
                            001300040
                            008100005
                            ".Replace(" ", "");
            var sudoku = SudokuFactory.CreateFromString(puzzle);

            // act
            var sudokuCopy = sudoku.DeepCopy();

            sudoku.SetCellValue(0, 1, 7, "manual");

            // assert
            Assert.AreEqual(7, sudoku.GetCellValue(0, 1));
            Assert.AreEqual(0, sudokuCopy.GetCellValue(0, 1));
        }