Beispiel #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())
Beispiel #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())
Beispiel #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())
Beispiel #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)
Beispiel #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())
Beispiel #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
Beispiel #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)
Beispiel #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())
Beispiel #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())
Beispiel #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)
Beispiel #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)
Beispiel #12
0
    def test_raise_exception_on_clear_if_no_color(self):
        block = Block(0, 0)

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

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