Пример #1
0
        public void should_get_81_cells_for_sudoku_board()
        {
            var sudokuBoard = new SudokuBoard();
            var cells = sudokuBoard.Cells;

            Assert.Equal(81, cells.Count);
            sudokuBoard.Cells.ForEach(cell => Assert.Equal(0, cell.Value));
            cells[0].Value = 1;
            Assert.Equal(1, cells[0].Value);
        }
Пример #2
0
        public void should_get_candidates_for_unlocked_cell()
        {
            var sudokuBoard = new SudokuBoard();
            var position = new Position(0,0);
            var candidates = new GeneralCandidateRule(sudokuBoard).GetCandidates(position);
            Assert.Equal(9, candidates.Count);

            sudokuBoard.Set(new Position(0, 1), 2, false);
            sudokuBoard.Set(new Position(0, 2), 3, false);
            sudokuBoard.Set(new Position(0, 3), 4, false);
            sudokuBoard.Set(new Position(0, 4), 5, false);
            sudokuBoard.Set(new Position(0, 5), 6, false);
            sudokuBoard.Set(new Position(0, 6), 7, false);
            sudokuBoard.Set(new Position(0, 7), 8, false);
            sudokuBoard.Set(new Position(0, 8), 9, false);
            candidates = new GeneralCandidateRule(sudokuBoard).GetCandidates(position);
            Assert.Equal(1, candidates.Count);
            Assert.Equal(1, candidates.First());
        }
Пример #3
0
 public GeneralCandidateRule(SudokuBoard sudokuBoard)
 {
     _sudokuBoard = sudokuBoard;
 }
Пример #4
0
        public void should_get_empty_candidates_for_locked_cell()
        {
            var sudokuBoard = new SudokuBoard();
            var position = new Position(0, 0);
            sudokuBoard.Set(position, 2, true);

            var candidates = new GeneralCandidateRule(sudokuBoard).GetCandidates(position);
            Assert.Equal(0, candidates.Count);
        }
Пример #5
0
        private static void CheckAnswer(SudokuBoard sudokuBoard, string problem, string answer)
        {
            var dataList = new VerticalBarStyleTokenizer().Generate(problem);
            sudokuBoard.Make(dataList);
            sudokuBoard.Solve();

            var expected = answer.Replace(Environment.NewLine, string.Empty).Replace(" ", string.Empty);
            var replace = sudokuBoard.Answer.Replace(Environment.NewLine, string.Empty);
            Assert.Equal(expected, replace);
        }
Пример #6
0
 public void should_sovle_sudoku()
 {
     var sudokuBoard = new SudokuBoard();
     CheckAnswer(sudokuBoard, Problem, Answer);
     CheckAnswer(sudokuBoard, Expert, ExpertAnswer);
 }
Пример #7
0
        public void should_set_the_cell_value_for()
        {
            var sudokuBoard = new SudokuBoard();
            var position = new Position(0, 0);
            sudokuBoard.Set(position, 9, false);
            Assert.Equal(9, sudokuBoard.Get(position).Value);

            position = new Position(8, 8);
            sudokuBoard.Set(position, 1, true);
            Assert.Equal(1, sudokuBoard.Get(position).Value);
            Assert.Equal(true, sudokuBoard.Get(position).Locked);
        }
Пример #8
0
        public void should_not_break_the_unique_rule()
        {
            var sudokuBoard = new SudokuBoard();
            var position = new Position(0, 0);
            sudokuBoard.Set(position, 1, false);
            Assert.Equal(1,sudokuBoard.Get(position).Value);

            position = new Position(0, 1);
            sudokuBoard.Set(position, 1, false);
            Assert.NotEqual(1, sudokuBoard.Get(position).Value);
        }
Пример #9
0
 public GeneralCandidateRule(SudokuBoard sudokuBoard)
 {
     _sudokuBoard = sudokuBoard;
 }