Esempio n. 1
0
    def test_clear(self):
        block = Block(0, 0, Color.RED)
        self.assertEqual(block.color, Color.RED)
        self.assertFalse(block.is_clear())

        block.clear()
        self.assertEqual(block.color, Color.CLEAR)
        self.assertTrue(block.is_clear())
Esempio n. 2
0
    def test_init(self):
        block = Block(1, 2)

        self.assertEqual(block.color, Color.CLEAR)
        self.assertEqual(block.x, 1)
        self.assertEqual(block.y, 2)
        self.assertTrue(block.is_clear())

        block = Block(0, 0, Color.RED)
        self.assertEqual(block.color, Color.RED)
        self.assertFalse(block.is_clear())
Esempio n. 3
0
    def test_set_falling(self):
        block = Block(0, 0)
        self.assertFalse(block.is_falling())

        block.set_falling(True)
        self.assertTrue(block.is_falling())

        block.set_falling(False)
        self.assertFalse(block.is_falling())
Esempio n. 4
0
    def test_set_falling_raises_exception_on_double_set(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidOperation):
            block.set_falling(False)

        block.set_falling(True)
        with self.assertRaises(InvalidOperation):
            block.set_falling(True)
Esempio n. 5
0
    def test_set_falling(self):
        block = Block(0, 0)
        self.assertFalse(block.is_falling())

        block.set_falling(True)
        self.assertTrue(block.is_falling())

        block.set_falling(False)
        self.assertFalse(block.is_falling())
Esempio n. 6
0
    def __init__(self):
        self._display = pygame.Surface((WIDTH_PIXELS, HEIGHT_PIXELS))
        # Init board with clear blocks
        self._board = []
        for h in range(0, HEIGHT):
            self._board.append([])
            for w in range(0, WIDTH):
                self._board[h].append(Block(w, h))

        self._brick = None
Esempio n. 7
0
    def test_set_falling_raises_exception_on_double_set(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidOperation):
            block.set_falling(False)

        block.set_falling(True)
        with self.assertRaises(InvalidOperation):
            block.set_falling(True)
Esempio n. 8
0
    def test_clear(self):
        block = Block(0, 0, Color.RED)
        self.assertEqual(block.color, Color.RED)
        self.assertFalse(block.is_clear())

        block.clear()
        self.assertEqual(block.color, Color.CLEAR)
        self.assertTrue(block.is_clear())
Esempio n. 9
0
    def test_init(self):
        block = Block(1, 2)

        self.assertEqual(block.color, Color.CLEAR)
        self.assertEqual(block.x, 1)
        self.assertEqual(block.y, 2)
        self.assertTrue(block.is_clear())

        block = Block(0, 0, Color.RED)
        self.assertEqual(block.color, Color.RED)
        self.assertFalse(block.is_clear())
Esempio n. 10
0
    def test_raise_exception_on_set_color_if_invalid_color(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidParameter):
            block.set_color(99999)
Esempio n. 11
0
    def test_raise_exception_on_set_color_if_not_clear(self):
        block = Block(0, 0, Color.RED)

        with self.assertRaises(InvalidOperation):
            block.set_color(Color.BLUE)
Esempio n. 12
0
    def test_raise_exception_on_clear_if_no_color(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidOperation):
            block.clear()
Esempio n. 13
0
    def test_raise_exception_on_set_color_if_invalid_color(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidParameter):
            block.set_color(99999)
Esempio n. 14
0
    def test_raise_exception_on_set_color_if_not_clear(self):
        block = Block(0, 0, Color.RED)

        with self.assertRaises(InvalidOperation):
            block.set_color(Color.BLUE)
Esempio n. 15
0
    def test_raise_exception_on_clear_if_no_color(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidOperation):
            block.clear()