/** * 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); }
public void GetTimeStampStr() { //执行 act var testResult = DateTimeX.GetTimeStampStr(_oneDay); //断言 Assert.AreEqual(_timeStampStr, testResult); }
public void GetTimeStampLong() { //执行 var testResult = DateTimeX.GetTimeStampLong(_oneDay); //断言 Assert.AreEqual(_timeStampLong, testResult); }
/* * /// <summary> * /// Call to verify a user's email or phone * /// </summary> * /// <param name="transaction"></param> * /// <param name="userId"></param> * /// <param name="verifyCode"></param> * /// <param name="verifyCodeFieldName"></param> * /// <param name="verifiedAtFieldName"></param> * /// <returns></returns> * public async Task VerifyAsync(ITransaction transaction, string userId, int verifyCode, string verifyCodeFieldName, string verifiedAtFieldName) { * * Dict data = await this.database.SelectRowAsync($"SELECT verify_code, expires_at FROM {this.sendVerifyTableName}", new { * contact * }); * if (userVerifyCode != verifyCode) throw new Exception("Verify code is incorrect"); * * var values = new Dict { * { this.userTableIdFieldName, userId }, * { verifiedAtFieldName, DateTime.Now } * }; * await transaction.UpdateAsync(this.userTableName, values); * } */ protected async Task VerifyAsync(string contact, int code) { logger.Debug($"VerifyAsync():contact={contact},code={code}"); string scrubbedContact = Validate(contact); Dict result = await this.database.SelectRowAsync($"SELECT verify_code, expires_at FROM {this.sendVerifyTableName}", new { contact = scrubbedContact }); int verifyCode = result.GetAs("verify_code", -1); if (code == -1 || code != verifyCode) { throw new Exception("Invalid contact and/or verify code"); } int expiresAtUnix = result.GetAs("expires_at", -1); if (DateTimeX.FromUnixTimestamp(expiresAtUnix) < DateTime.Now) { throw new Exception("Expired verify code"); } }
/** * 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); }
/** * Message builder. * @param msg Message. */ private void addMessage(String msg, int msgType) { String vdt = "[" + SudokuStore.JANET_SUDOKU_NAME + "-v." + SudokuStore.JANET_SUDOKU_VERSION + ", " + DateTimeX.getCurrDateTimeStr() + "]"; String mt = "(msg)"; if (msgType == MSG_ERROR) { mt = "(error)"; lastErrorMessage = msg; } messages = messages + SudokuStore.NEW_LINE_SEPARATOR + vdt + mt + " " + msg; lastMessage = msg; }
/** * 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); }
/// <summary> /// 例子:获取时间戳 Long /// </summary> public static void GetTimeStampLong() { long result = DateTimeX.GetTimeStampLong(Dt); Console.WriteLine(result); }
/// <summary> /// 例子:获取时间戳 字符串 /// </summary> public static void GetTimeStampStr() { string result = DateTimeX.GetTimeStampStr(Dt); Console.WriteLine(result); }