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())
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())
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())
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)
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
def test_raise_exception_on_set_color_if_invalid_color(self): block = Block(0, 0) with self.assertRaises(InvalidParameter): block.set_color(99999)
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)
def test_raise_exception_on_clear_if_no_color(self): block = Block(0, 0) with self.assertRaises(InvalidOperation): block.clear()