コード例 #1
0
        /**
         * Start all regression tests.
         *
         * @param threadsNumber  Threads number.
         * @return               Number of tests with error result.
         */
        public static int Start(int threadsNumber)
        {
            SudokuStore.consolePrintln("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            SudokuStore.consolePrintln("All regression tests - starting.");
            SudokuStore.consolePrintln("  - RegTestsSolver.start()");
            SudokuStore.consolePrintln("  - RegTestsGenerator.start()");
            SudokuStore.consolePrintln("  - RegTestsStore.start()");
            SudokuStore.consolePrintln("  - RegTestsApi.start()");
            SudokuStore.consolePrintln("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            long   startTime       = DateTimeX.currentTimeMillis();
            int    solverErrors    = RegTestsSolver.Start(threadsNumber);
            int    generatorErrors = RegTestsGenerator.Start(threadsNumber);
            int    storeErrors     = RegTestsStore.Start(threadsNumber);
            int    apiErrors       = RegTestsApi.Start(threadsNumber);
            long   endTime         = DateTimeX.currentTimeMillis();
            double computingTime   = (endTime - startTime) / 1000.0;
            int    totalErrors     = solverErrors + generatorErrors + storeErrors + apiErrors;

            SudokuStore.consolePrintln("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            SudokuStore.consolePrintln("All regression tests - finished.");
            SudokuStore.consolePrintln("Errors: " + totalErrors);
            SudokuStore.consolePrintln("  - RegTestsSolver errors: " + solverErrors);
            SudokuStore.consolePrintln("  - RegTestsGenerator errors: " + generatorErrors);
            SudokuStore.consolePrintln("  - RegTestsStore errors: " + storeErrors);
            SudokuStore.consolePrintln("  - RegTestsApi errors: " + apiErrors);
            SudokuStore.consolePrintln("");
            SudokuStore.consolePrintln("Computing time: " + computingTime + " s.");
            SudokuStore.consolePrintln("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            return(totalErrors);
        }
コード例 #2
0
        /**
         * Runs SudokuSolver regression tests.
         * @param threadsNumber    Number of threads.
         * @return    Number of tests with errors.
         */
        public static int Start(int threadsNumber)
        {
            int         numberOfTests = SolverTests.NUMBER_OF_TESTS;
            int         resultsError  = 0;
            int         resultsOk     = 0;
            long        startTime     = DateTimeX.currentTimeMillis();
            SolverTests st            = new SolverTests(threadsNumber);

            st.start();
            bool[] testResults = st.testsResults;
            for (int t = 0; t < numberOfTests; t++)
            {
                if (testResults[t] == true)
                {
                    resultsOk++;
                }
                else
                {
                    resultsError++;
                }
            }
            long   endtTime      = DateTimeX.currentTimeMillis();
            double computingTime = (endtTime - startTime) / 1000.0;

            SudokuStore.consolePrintln("=============================================================");
            SudokuStore.consolePrintln("Number of SudokuSolver test: " + numberOfTests + ", OK: " + resultsOk + ", ERRORS: " + resultsError + ", computing time: " + computingTime);
            for (int t = 0; t < numberOfTests; t++)
            {
                if (testResults[t] == false)
                {
                    SudokuStore.consolePrintln("ERROR: " + t);
                }
            }
            SudokuStore.consolePrintln("=============================================================");
            return(resultsError);
        }
コード例 #3
0
        /**
         * Sudoku puzzle generator.
         *
         * @return   Sudoku puzzle if process finished correctly, otherwise null.
         */
        public int[,] generate()
        {
            if (generatorState != GENERATOR_INIT_FINISHED)
            {
                generatorState = GENERATOR_GEN_NOT_STARTED;
                addMessage("(SudokuGenerator) Generation process not started due to incorrect initialization.", MSG_ERROR);
                return(null);
            }
            long solvingStartTime = DateTimeX.currentTimeMillis();

            generatorState = GENERATOR_GEN_STARTED;
            addMessage("(SudokuGenerator) Generation process started.", MSG_INFO);
            if (randomizeFilledCells == true)
            {
                addMessage("(SudokuGenerator) >>> Will randomize filled cells within cells with the same impact.", MSG_INFO);
            }
            boardCells = new BoardCell[BOARD_CELLS_NUMBER];
            int cellIndex = 0;

            for (int i = 0; i < BOARD_SIZE; i++)
            {
                for (int j = 0; j < BOARD_SIZE; j++)
                {
                    int d = sudokuBoard[i, j];
                    if (d != CELL_EMPTY)
                    {
                        boardCells[cellIndex] = new BoardCell(i, j, d);
                        cellIndex++;
                    }
                }
            }
            int filledCells = cellIndex;

            for (int i = 0; i < BOARD_SIZE; i++)
            {
                for (int j = 0; j < BOARD_SIZE; j++)
                {
                    int d = sudokuBoard[i, j];
                    if (d == CELL_EMPTY)
                    {
                        boardCells[cellIndex] = new BoardCell(i, j, d);
                        cellIndex++;
                    }
                }
            }
            updateDigitsStillFreeCounts();
            sortBoardCells(0, filledCells - 1);
            do
            {
                int r = 0;
                int i = boardCells[r].rowIndex;
                int j = boardCells[r].colIndex;
                int d = sudokuBoard[i, j];
                sudokuBoard[i, j] = CELL_EMPTY;
                SudokuSolver s = new SudokuSolver(sudokuBoard);
                if (s.checkIfUniqueSolution() != SudokuSolver.SOLUTION_UNIQUE)
                {
                    sudokuBoard[i, j] = d;
                }
                int lastIndex = filledCells - 1;
                if (r < lastIndex)
                {
                    BoardCell b1 = boardCells[r];
                    BoardCell b2 = boardCells[lastIndex];
                    boardCells[lastIndex] = b1;
                    boardCells[r]         = b2;
                }
                filledCells--;
                updateDigitsStillFreeCounts();
                if (filledCells > 0)
                {
                    sortBoardCells(0, filledCells - 1);
                }
            } while (filledCells > 0);
            long solvingEndTime = DateTimeX.currentTimeMillis();

            computingTime  = (solvingEndTime - solvingStartTime) / 1000.0;
            generatorState = GENERATOR_GEN_FINISHED;
            addMessage("(SudokuGenerator) Generation process finished, computing time: " + computingTime + " s.", MSG_INFO);
            return(sudokuBoard);
        }