ToString() static private method

static private ToString ( int sudoku ) : string
sudoku int
return string
コード例 #1
0
ファイル: UnitTest.cs プロジェクト: dixitsandeep/sudoku
        public void SolveAFile(string filePath)
        {
            string line;

            System.IO.StreamReader file =
                new System.IO.StreamReader(filePath);

            int currentLineIndex = 0;

            while ((line = file.ReadLine()) != null)
            {
                string[] sudokulineElements = line.Split(',');

                string inputProblem     = sudokulineElements[0];
                string expectedSolution = sudokulineElements[1];


                Sudoku.Sudoku sudoku = new Sudoku.Sudoku(inputProblem);



                //RenderNewEntries(sudoku, Color.Black);

                //MessageBox.Show($"Problem {counter} loaded from DB. Click to Solve ");

                bool   isSovled = sudoku.Solve();
                string solution = sudoku.ToString();

                if (isSovled)
                {
                    if (!solution.Equals(expectedSolution))
                    {
                        throw new Exception($"Sudoku solution does not match input solution excped: {expectedSolution}.\n Actual {solution}");
                    }
                    Console.WriteLine("Solved a Problem. Rating=" + sudoku.DifficultyRating);
                }
                else
                {
                    throw new Exception($"Sudoku could not be solved. Incompelete solution is {solution} expected solution was {expectedSolution}");
                }



                currentLineIndex++;
            }

            file.Close();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: pharring/Sudoku
        static void Go(string puzzle)
        {
            var sudoku = new Sudoku(puzzle);
            var sw     = Stopwatch.StartNew();
            var solved = sudoku.Solve();

            sw.Stop();
            if (solved)
            {
                Console.WriteLine("{0} solved in {1:f2}ms", puzzle, sw.Elapsed.TotalMilliseconds);
                Console.WriteLine(sudoku.ToString());
            }
            else
            {
                Console.WriteLine("No solution found.");
            }
        }