public static void ExecuteTests() { Console.WriteLine("Executing Tests\n============================================="); var factory = new TestDataFactory(); var testsToRun = new List <int[, ]> { factory.SolvableTest1, factory.SolvableTest2, factory.SolvableTest3, factory.NotSolvableTest1, factory.NotSolvableTest2, factory.InvalidBoardTest1, factory.InvalidBoardTest2 }; foreach (var testBoard in testsToRun) { Console.WriteLine($"============Start Test============"); if (SudokuValidator.Validate(testBoard)) { if (SudokuSolver.Solve(testBoard, 0, 0)) { SudokuSolver.Print(testBoard); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to solve"); Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Invalid Board"); Console.ResetColor(); } Console.WriteLine($"============End Test============"); } }
/// <summary> /// Execute Live Board /// </summary> private static void ExecuteLive() { Console.WriteLine("Enter each line of the board as prompted.\nEnter a value for each square separated by a comma, using 0 for empty squares"); for (int line = 0; line < 9; line++) { Console.WriteLine($"Please enter line ({line + 1}) of the board:"); var currentUserLine = Array.ConvertAll(Console.ReadLine().Split(','), p => p.Trim()); for (int column = 0; column < 9; column++) { board[line, column] = Convert.ToInt32(currentUserLine[column]); } } if (SudokuValidator.Validate(board)) { if (SudokuSolver.Solve(board, 0, 0)) { SudokuSolver.Print(board); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to solve"); Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Invalid Board"); Console.ResetColor(); } }