Пример #1
0
    def setUp(self):
        self.field1 = field.Field(4, 4)

        self.field2 = field.Field(4, 4)
        self.field2.mine_coords = {(0, 0), (1, 0)}
        self.field2.open_coords = {(1, 1), (0, 1)}
        self.field2.flag_coords = {(0, 0), (2, 1)}
        self.field2.hints = {
            (0, 0): -1,
            (0, 1): 2,
            (0, 2): 0,
            (0, 3): 0,
            (1, 0): -1,
            (1, 1): 2,
            (1, 2): 0,
            (1, 3): 0,
            (2, 0): 1,
            (2, 1): 1,
            (2, 2): 0,
            (2, 3): 0,
            (3, 0): 0,
            (3, 1): 0,
            (3, 2): 0,
            (3, 3): 0,
        }

        field3_mines = {(2, 0), (2, 2), (6, 3), (1, 5), (5, 6)}
        self.field3 = field.Field(8, 7, field3_mines)
Пример #2
0
    def test_render_mines(self):
        mines = {(0, 0), (3, 1), (1, 3)}
        f = field.Field(4, 4, mines)

        expected = "x...\n...x\n....\n.x..\n"
        self.assertEqual(f.render_mines(), expected)

        expected = "@ooo\nooo@\noooo\no@oo\n"
        self.assertEqual(f.render_mines("o", "@"), expected)
Пример #3
0
    def test_render_player_field(self):
        mines = {(0, 0), (3, 1), (0, 3)}
        pf = field.Field(4, 4, mines)
        pf.flag_coords = {(1, 1)}
        pf.open_coords = {(0, 1), (3, 3)}
        pf.hints = {(0, 1): 1, (3, 3): 0}

        expected = "....\n1!..\n....\n...0\n"
        self.assertEqual(pf.render_player_field(), expected)

        expected = "oooo\n1?oo\noooo\nooo0\n"
        self.assertEqual(pf.render_player_field("?", "o"), expected)
Пример #4
0
 def test_are_coords_valid(self):
     f = field.Field(4, 4)
     self.assertTrue(f.are_coords_valid(3, 2))
     self.assertFalse(f.are_coords_valid(5, 2))