Ejemplo n.º 1
0
 def test_set_cell(self):
     n = 5
     puzzle = Puzzle(Grid(n))
     puzzle.set_cell(2, 3, 'D')
     cell = puzzle.get_cell(2, 3)
     self.assertEqual('D', cell)
     for r in range(1, n + 1):
         if r == 2:
             continue
         for c in range(1, n + 1):
             if c == 3:
                 continue
             cell = puzzle.get_cell(r, c)
             self.assertEqual(Puzzle.WHITE, cell, f'Mismatch at ({r}, {c})')
Ejemplo n.º 2
0
    def test_add_black(self):
        n = 5
        grid = Grid(n)
        black_cells = [
            (1, 1),
            (1, 3),
            (2, 3),
            (2, 4),
            (3, 1),
            (3, 2),
        ]
        for (r, c) in black_cells:
            grid.add_black_cell(r, c)

        puzzle = Puzzle(grid)

        expected_cells = [
            ["*", " ", "*", " ", " "],
            [" ", " ", "*", "*", " "],
            ["*", "*", " ", "*", "*"],
            [" ", "*", "*", " ", " "],
            [" ", " ", "*", " ", "*"],
        ]
        for r in range(1, n + 1):
            for c in range(1, n + 1):
                expected = expected_cells[r - 1][c - 1]
                actual = puzzle.get_cell(r, c)
                self.assertEqual(expected, actual, f'Mismatch at ({r},{c})')