예제 #1
0
    def test_target(self):
        """Test metody is_target."""
        puzzle = SudokuPuzzle()

        self.assertTrue(
            puzzle.is_target(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))

        # wpisane zero
        self.assertFalse(
            puzzle.is_target(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 0, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))

        self.assertFalse(
            puzzle.is_target(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 7, 8, 1, 9, 5, 3, 4, 8),
                 (1, 9, 2, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))
예제 #2
0
    def test_transition(self):
        """Test metody transition."""
        puzzle = SudokuPuzzle()

        # końcowy stan, nie ma przejść
        self.assertItemsEqual(
            puzzle.transition(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))),
            [])

        self.assertItemsEqual(
            puzzle.transition(
                ((5, 0, 4, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))),
            [((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
              (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
              (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5, 6),
              (9, 6, 1, 5, 3, 7, 2, 8, 4), (2, 8, 7, 4, 1, 9, 6, 3, 5),
              (3, 4, 5, 2, 8, 6, 1, 7, 9))])

        self.assertItemsEqual(
            puzzle.transition(
                ((0, 3, 0, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (0, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))),
            [((4, 3, 0, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
              (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
              (0, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5, 6),
              (9, 6, 1, 5, 3, 7, 2, 8, 4), (2, 8, 7, 4, 1, 9, 6, 3, 5),
              (3, 4, 5, 2, 8, 6, 1, 7, 9)),
             ((5, 3, 0, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
              (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
              (0, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5, 6),
              (9, 6, 1, 5, 3, 7, 2, 8, 4), (2, 8, 7, 4, 1, 9, 6, 3, 5),
              (3, 4, 5, 2, 8, 6, 1, 7, 9)),
             ((0, 3, 4, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
              (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
              (0, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5, 6),
              (9, 6, 1, 5, 3, 7, 2, 8, 4), (2, 8, 7, 4, 1, 9, 6, 3, 5),
              (3, 4, 5, 2, 8, 6, 1, 7, 9)),
             ((0, 3, 0, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
              (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
              (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5, 6),
              (9, 6, 1, 5, 3, 7, 2, 8, 4), (2, 8, 7, 4, 1, 9, 6, 3, 5),
              (3, 4, 5, 2, 8, 6, 1, 7, 9))])
예제 #3
0
파일: Task107Test.py 프로젝트: nmapx/uam
    def test_target(self):
        """Test metody is_target."""
        puzzle = SudokuPuzzle()

        self.assertTrue(
            puzzle.is_target(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )

        # wpisane zero
        self.assertFalse(
            puzzle.is_target(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 0, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )

        self.assertFalse(
            puzzle.is_target(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 8, 1, 9, 5, 3, 4, 8),
                    (1, 9, 2, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )
예제 #4
0
    def test_is_valid_state(self):
        """Test metody is_valid_state."""
        puzzle = SudokuPuzzle()

        self.assertTrue(
            puzzle.is_valid_state(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 7, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))

        self.assertTrue(
            puzzle.is_valid_state(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 0, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))

        self.assertFalse(
            puzzle.is_valid_state(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 0, 2, 1, 9, 5, 0, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 0, 3, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 2, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))

        self.assertFalse(
            puzzle.is_valid_state(
                ((5, 3, 4, 6, 0, 8, 9, 1, 2), (6, 0, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 0, 2, 8, 4),
                 (2, 8, 7, 4, 7, 9, 6, 3, 5), (3, 4, 5, 2, 8, 6, 1, 7, 9))))

        self.assertFalse(
            puzzle.is_valid_state(
                ((5, 3, 4, 6, 7, 8, 9, 1, 2), (6, 0, 2, 1, 9, 5, 3, 4, 8),
                 (1, 9, 8, 3, 4, 2, 5, 6, 7), (8, 5, 9, 7, 6, 1, 4, 2, 3),
                 (4, 2, 6, 8, 5, 3, 7, 9, 1), (7, 1, 3, 9, 2, 4, 8, 5,
                                               6), (9, 6, 1, 5, 3, 7, 0, 8, 4),
                 (2, 8, 7, 4, 1, 9, 6, 3, 5), (3, 4, 5, 0, 8, 6, 1, 7, 2))))
예제 #5
0
파일: Task107Test.py 프로젝트: nmapx/uam
    def test_is_valid_state(self):
        """Test metody is_valid_state."""
        puzzle = SudokuPuzzle()

        self.assertTrue(
            puzzle.is_valid_state(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )

        self.assertTrue(
            puzzle.is_valid_state(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 0, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )

        self.assertFalse(
            puzzle.is_valid_state(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 0, 2, 1, 9, 5, 0, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 0, 3, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )

        self.assertFalse(
            puzzle.is_valid_state(
                (
                    (5, 3, 4, 6, 0, 8, 9, 1, 2),
                    (6, 0, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 0, 2, 8, 4),
                    (2, 8, 7, 4, 7, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            )
        )

        self.assertFalse(
            puzzle.is_valid_state(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 0, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 0, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 0, 8, 6, 1, 7, 2),
                )
            )
        )
예제 #6
0
파일: Task107Test.py 프로젝트: nmapx/uam
    def test_transition(self):
        """Test metody transition."""
        puzzle = SudokuPuzzle()

        # końcowy stan, nie ma przejść
        self.assertItemsEqual(
            puzzle.transition(
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            ),
            [],
        )

        self.assertItemsEqual(
            puzzle.transition(
                (
                    (5, 0, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            ),
            [
                (
                    (5, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            ],
        )

        self.assertItemsEqual(
            puzzle.transition(
                (
                    (0, 3, 0, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (0, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                )
            ),
            [
                (
                    (4, 3, 0, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (0, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                ),
                (
                    (5, 3, 0, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (0, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                ),
                (
                    (0, 3, 4, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (0, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                ),
                (
                    (0, 3, 0, 6, 7, 8, 9, 1, 2),
                    (6, 7, 2, 1, 9, 5, 3, 4, 8),
                    (1, 9, 8, 3, 4, 2, 5, 6, 7),
                    (8, 5, 9, 7, 6, 1, 4, 2, 3),
                    (4, 2, 6, 8, 5, 3, 7, 9, 1),
                    (7, 1, 3, 9, 2, 4, 8, 5, 6),
                    (9, 6, 1, 5, 3, 7, 2, 8, 4),
                    (2, 8, 7, 4, 1, 9, 6, 3, 5),
                    (3, 4, 5, 2, 8, 6, 1, 7, 9),
                ),
            ],
        )