Ejemplo 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())
Ejemplo 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())
Ejemplo 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())
Ejemplo 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)
Ejemplo 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())
Ejemplo 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
Ejemplo 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)
Ejemplo 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())
Ejemplo 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())
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 12
0
    def test_raise_exception_on_clear_if_no_color(self):
        block = Block(0, 0)

        with self.assertRaises(InvalidOperation):
            block.clear()
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 15
0
    def test_raise_exception_on_clear_if_no_color(self):
        block = Block(0, 0)

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