示例#1
0
    def test_row_consistency_check(self):
        """
        Check that _consistency_check() raises when number 2 has no valid
        place in the fourth row.
        """
        squares = np.array([
            [2, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 3, 4, 5, 6, 7, 8, 9],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 2, 0, 0, 0, 0, 0, 0, 0],
        ])
        board = HB6DBoard.from_array(squares)
        # _num is 1, _row is 3, Nones are for 'no column'
        _expected_idx = (0, 1, 1, 0, None, None)

        with self.assertRaises(ConsistencyError) as exc_cm:
            board._check_consistency()

        self.assertEqual(exc_cm.exception._idx, _expected_idx)
示例#2
0
    def test_consistency_check_doesnt_mutate_board(self):
        # Invalid board without candidates in the three empty squares
        # Number 9 in square (1, 2) shouldn't be there (for example)
        squares = np.array([
            [4, 9, 3, None, 2, 1, 6, 5, 7],  # noqa: E241
            [None, 6, 7, 3, 4, 5, 8, 2, 1],  # noqa: E241
            [2, 5, 1, 8, 7, 6, 4, 9, 3],  # noqa: E241
            [5, 4, 8, 1, 3, 2, 9, 7, 6],  # noqa: E241
            [7, 2, 9, 5, 6, 4, 1, 3, 8],  # noqa: E241
            [1, 3, 6, 7, 9, 8, 2, 4, 5],  # noqa: E241
            [3, 7, 2, 6, 8, 9, 5, 1, 4],  # noqa: E241
            [8, 1, 4, 2, 5, 3, 7, 6, 9],  # noqa: E241
            [6, None, 5, 4, 1, 7, 3, 8, 2],  # noqa: E241
        ])
        board = HB6DBoard.from_array(squares)
        repr_before = repr(board)

        with self.assertRaises(ConsistencyError) as exc_cm:
            board._check_consistency()
        repr_after = repr(board)

        self.assertIn("Inconsistency found", str(exc_cm.exception))
        # Make sure the `_check_consistency()` method doesn't change the board
        self.assertEqual(repr_after, repr_before)
示例#3
0
    def test_square_consistency_check(self):
        """
        Check that _consistency_check() raises when there is no candidate
        number in the top left square.
        """
        squares = np.array([
            [0, 2, 3, 4, 5, 6, 7, 8, 0],
            [1, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0],
            [9, 0, 0, 0, 0, 0, 0, 0, 0],
        ])
        board = HB6DBoard.from_array(squares)
        # Nones are for 'no candidate', _row is 0, _col is 0
        _expected_idx = (None, None, 0, 0, 0, 0)

        with self.assertRaises(ConsistencyError) as exc_cm:
            board._check_consistency()

        self.assertEqual(exc_cm.exception._idx, _expected_idx)
示例#4
0
    def test_instantiation_from_array(self):
        squares = np.array([
            [7, None, None, None, None, None, None, None,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, None, None,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, None, None,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, None, 7,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, None, None,
             None],  # noqa: E241, E501
            [None, 3, None, None, None, None, None, None,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, 2, 1,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, None, None,
             None],  # noqa: E241, E501
            [None, None, None, None, None, None, None, None,
             None],  # noqa: E241, E501
        ])
        expected_str = ("7 . . | . . . | . . .\n"
                        ". . . | . . . | . . .\n"
                        ". . . | . . . | . . .\n"
                        "---------------------\n"
                        ". . . | . . . | . 7 .\n"
                        ". . . | . . . | . . .\n"
                        ". 3 . | . . . | . . .\n"
                        "---------------------\n"
                        ". . . | . . . | 2 1 .\n"
                        ". . . | . . . | . . .\n"
                        ". . . | . . . | . . .\n")

        board = HB6DBoard.from_array(squares)

        self.assertEqual(str(board), expected_str)
示例#5
0
 def test_init(self):
     HB6DBoard()