コード例 #1
0
    def test_set_cell_5(self):
        sb = SudokuBoard()

        start_state = copy.deepcopy(sb.__dict__)

        sb.set_cell(1, 2, 6)

        try:
            sb.set_cell(sb._max_row_value + 1, 2, 3)

        except ValueError as exception:
            self.assertEqual(
                str(exception),
                "The 'row' value %s is not an int in the range [%s, %s]" %
                (str(sb._max_row_value + 1), str(
                    sb._min_row_value), str(sb._max_row_value)))

        else:
            self.fail("A ValueError was expected.")

        self.assertDictEqual(sb.__dict__, {
            **start_state,
            "_cells": {
                (1, 2): 6,
            },
        })
コード例 #2
0
    def test_get_cell_1(self):
        sb = SudokuBoard()

        sb.set_cell(1, 2, 3)

        start_state = copy.deepcopy(sb.__dict__)

        self.assertEqual(sb.get_cell(1, 2), 3)

        self.assertDictEqual(sb.__dict__, start_state)
コード例 #3
0
    def test_remove_all_cells_1(self):
        sb = SudokuBoard()

        sb.set_cell(1, 2, 3)

        start_state = copy.deepcopy(sb.__dict__)

        self.assertIsNone(sb.remove_all_cells())

        self.assertDictEqual(sb.__dict__, {**start_state, "_cells": {}})
コード例 #4
0
    def test_remove_cell_2(self):
        sb = SudokuBoard()

        sb.set_cell(1, 2, 3)

        start_state = copy.deepcopy(sb.__dict__)

        self.assertIsNone(sb.remove_cell(1, 3))

        self.assertDictEqual(sb.__dict__, start_state)
コード例 #5
0
    def test_get_cell_3(self):
        sb = SudokuBoard()

        sb.set_cell(1, 2, 3)
        sb.set_cell(1, 2, 4)
        sb.set_cell(1, 1, 5)

        start_state = copy.deepcopy(sb.__dict__)

        self.assertIsNone(sb.get_cell(1, 6))

        self.assertDictEqual(sb.__dict__, start_state)
コード例 #6
0
    def test_get_cell_6(self):
        sb = SudokuBoard()

        sb.set_cell(sb._min_row_value, sb._min_col_value, sb._min_val_value)
        sb.set_cell(1, 2, 4)
        sb.set_cell(1, 3, 5)

        start_state = copy.deepcopy(sb.__dict__)

        self.assertEqual(sb.get_cell(sb._min_row_value, sb._min_col_value),
                         sb._min_val_value)

        self.assertDictEqual(sb.__dict__, start_state)
コード例 #7
0
    def test_set_cell_1(self):
        sb = SudokuBoard()

        start_state = copy.deepcopy(sb.__dict__)

        sb.set_cell(1, 2, 3)

        self.assertDictEqual(sb.__dict__, {
            **start_state,
            "_cells": {
                (1, 2): 3,
            },
        })
コード例 #8
0
    def test_get_cells_2(self):
        sb = SudokuBoard()

        sb.set_cell(1, 2, 3)

        start_state = copy.deepcopy(sb.__dict__)

        cells = sb.get_cells()

        self.assertDictEqual(cells, sb._cells)

        self.assertIsNot(cells, sb._cells)

        self.assertDictEqual(sb.__dict__, start_state)
コード例 #9
0
    def test_get_cells_3(self):
        sb = SudokuBoard()

        sb.set_cell(1, 2, 3)
        sb.set_cell(sb._min_row_value, sb._min_col_value, sb._min_val_value)
        sb.set_cell(sb._max_row_value, sb._max_col_value, sb._max_val_value)

        start_state = copy.deepcopy(sb.__dict__)

        cells = sb.get_cells()

        self.assertDictEqual(cells, sb._cells)

        self.assertIsNot(cells, sb._cells)

        self.assertDictEqual(sb.__dict__, start_state)
コード例 #10
0
    def test_set_cell_10(self):
        sb = SudokuBoard()

        start_state = copy.deepcopy(sb.__dict__)

        sb.set_cell(sb._min_row_value, sb._min_col_value, sb._min_val_value)
        sb.set_cell(sb._max_row_value, sb._max_col_value, sb._max_val_value)

        self.assertDictEqual(
            sb.__dict__, {
                **start_state,
                "_cells": {
                    (sb._min_row_value, sb._min_col_value): sb._min_val_value,
                    (sb._max_row_value, sb._max_col_value): sb._max_val_value,
                },
            })
コード例 #11
0
    def test_set_cell_15(self):
        sb = SudokuBoard()

        start_state = copy.deepcopy(sb.__dict__)

        try:
            sb.set_cell(1, 2, 3.3)

        except ValueError as exception:
            self.assertEqual(
                str(exception),
                "The 'value' value %s is not an int in the range [%s, %s]" %
                (str(3.3), str(sb._min_val_value), str(sb._max_val_value)))

        else:
            self.fail("A ValueError was expected.")

        self.assertDictEqual(sb.__dict__, start_state)