コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void TestMethod1()
        {
            List <int> possibles = new List <int>();

            possibles.Add(10);
            possibles.RemoveAt(0);
            //var x = new SudokuLogic.Class1();
            //var y = x.HelloTest();
            //TestContext.WriteLine($"the value is {y}");
            ////Assert.Fail(y);
            SudokuLogic.sudokCell sudokCell = new SudokuLogic.sudokCell();
            sudokCell             newCell   = new sudokCell(0);

            newCell.RemoveAt(0);
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void CheckAllStoredLogic()
        {
            bool solvedAll = true;

            //1 to 23, inclusive
            for (int i = 1; i <= NumStoredSudokus; i++)
            {
                SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver();
                SudokuLogic.sudokCell    sudokCell    = new SudokuLogic.sudokCell();
                //inputted sudoku
                int[,] sudokuInputted = input(i);

                SudokuGrid mySudoku = new SudokuGrid();

                //my sudoku to be worked with
                for (int row = 0; row < 9; row++)
                {
                    for (int column = 0; column < 9; column++)
                    {
                        mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                    }
                }

                sudokuSolver.Solve(mySudoku, true);

                //bruteForceSolver(mySudoku);

                //if unsolved
                if (!sudokuSolver.IsSolved(mySudoku, false))
                {
                    solvedAll = false;
                    TestContext.WriteLine("More work on " + i);
                    TestContext.WriteLine("Num unsolved is " + sudokuSolver.numUnsolved(mySudoku));
                }
                //if there was a duplicate in row, column, or box
                if (sudokuSolver.InvalidMove(mySudoku))
                {
                    TestContext.WriteLine("Invalid move on " + i);
                }
            }
            if (solvedAll)
            {
                TestContext.WriteLine("All solved");
            }

            Assert.IsTrue(solvedAll, "Not all solved");
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void TestBruteForceChecker()
        {
            SudokuSolver sudokuSolver = new SudokuSolver();

            //need to check 5, 9, 12, 13
            SudokuGrid mySudoku = new SudokuGrid();

            int[,] sudokuInputted = input(5);
            //my sudoku to be worked with
            for (int row = 0; row < 9; row++)
            {
                for (int column = 0; column < 9; column++)
                {
                    mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                }
            }


            sudokuSolver.bruteForceSolver(ref mySudoku);
            Assert.IsTrue(sudokuSolver.IsSolved(mySudoku), "Brute force did not solve it");
        }
コード例 #4
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void CheckIsValidMethod()
        {
            //1 to 23, inclusive
            //23 broke
            for (int i = 1; i <= 23; i++)
            {
                SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver();
                SudokuLogic.sudokCell    sudokCell    = new SudokuLogic.sudokCell();
                //inputted sudoku
                int[,] sudokuInputted = input(i);

                SudokuGrid mySudoku = new SudokuGrid();

                //my sudoku to be worked with
                for (int row = 0; row < 9; row++)
                {
                    for (int column = 0; column < 9; column++)
                    {
                        mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                    }
                }

                Assert.IsTrue(mySudoku.IsValid(), $"{i} was said to be not valid");
            }

            SudokuGrid notValid1 = new SudokuGrid();

            //my sudoku to be worked with
            for (int row = 0; row < 9; row++)
            {
                for (int column = 0; column < 9; column++)
                {
                    notValid1[row, column] = new sudokCell();
                }
            }
            notValid1[1, 1].solve(2);
            Assert.IsFalse(notValid1.IsValid(), "IsValid said a nonValid Sudoku is validx");
        }
コード例 #5
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void TestRateDifficulty()
        {
            SudokuSolver sudokuSolver = new SudokuSolver();

            for (int i = 1; i <= NumStoredSudokus; i++)
            {
                SudokuLogic.sudokCell sudokCell = new SudokuLogic.sudokCell();
                //inputted sudoku
                int[,] sudokuInputted = input(i);

                SudokuGrid mySudoku = new SudokuGrid();

                //my sudoku to be worked with
                for (int row = 0; row < 9; row++)
                {
                    for (int column = 0; column < 9; column++)
                    {
                        mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                    }
                }

                TestContext.WriteLine($"the level of {i} is {sudokuSolver.RateDifficulty(mySudoku)}");
            }
        }