コード例 #1
0
def test_flatten_01() -> None:
    board = Block((0, 0), 750, None, 0, 2)
    colours = [None, COLOUR_LIST[2], None, COLOUR_LIST[3]]
    set_children(board, colours)

    colours = [COLOUR_LIST[0], COLOUR_LIST[1], COLOUR_LIST[1], COLOUR_LIST[3]]
    set_children(board.children[0], colours)

    colours = [COLOUR_LIST[1], COLOUR_LIST[1], COLOUR_LIST[0], COLOUR_LIST[3]]
    set_children(board.children[2], colours)

    result = _flatten(board)
    assert result == [[COLOUR_LIST[2], COLOUR_LIST[2], COLOUR_LIST[1],
                                COLOUR_LIST[0]], [COLOUR_LIST[2], COLOUR_LIST[2],
                                                  COLOUR_LIST[1], COLOUR_LIST[3]],
                               [COLOUR_LIST[1], COLOUR_LIST[1], COLOUR_LIST[3],
                               COLOUR_LIST[3]], [COLOUR_LIST[0], COLOUR_LIST[3],
                               COLOUR_LIST[3], COLOUR_LIST[3]]]
コード例 #2
0
def test__flatten() -> None:
    """ Test the _flatten function. """
    b1 = Block((0, 0), 1000, (255, 255, 255), 0, 0)

    assert _flatten(b1) == [[(255, 255, 255)]]

    b2 = Block((0, 0), 1000, (255, 255, 255), 0, 1)

    assert _flatten(b2) == [[(255, 255, 255), (255, 255, 255)],
                            [(255, 255, 255), (255, 255, 255)]]

    b3 = Block((0, 0), 1000, (255, 255, 255), 0, 3)

    assert _flatten(b3) == [[(255, 255, 255) for w in range(8)]
                            for n in range(8)]

    b4 = Block((0, 0), 1000, None, 0, 2)
    b4.children = [Block((500, 0), 500, (255, 0, 0), 1, 2),
                   Block((0, 0), 500, None, 1, 2),
                   Block((0, 500), 500, (255, 0, 255), 1, 2),
                   Block((500, 500), 500, (0, 0, 255), 1, 2)]

    b4.children[1].children = [Block((250, 0), 250, (0, 0, 0), 2, 2),
                               Block((0, 0), 250, (0, 255, 0), 2, 2),
                               Block((0, 250), 250, (0, 0, 0), 2, 2),
                               Block((250, 250), 250, (0, 0, 255), 2, 2)]

    assert _flatten(b4.children[1]) == [[(0, 255, 0), (0, 0, 0)],
                                        [(0, 0, 0), (0, 0, 255)]]

    assert _flatten(b4) == [
        [(0, 255, 0), (0, 0, 0), (255, 0, 255), (255, 0, 255)],
        [(0, 0, 0), (0, 0, 255), (255, 0, 255), (255, 0, 255)],
        [(255, 0, 0), (255, 0, 0), (0, 0, 255), (0, 0, 255)],
        [(255, 0, 0), (255, 0, 0), (0, 0, 255), (0, 0, 255)]]

    b5 = Block((0, 0), 1000, None, 0, 2)
    b5.children = [Block((500, 0), 500, (0, 255, 0), 1, 2),
                   Block((0, 0), 500, (0, 0, 0), 1, 2),
                   Block((0, 500), 500, (255, 255, 255), 1, 2),
                   Block((500, 500), 500, (0, 255, 0), 1, 2)]

    assert _flatten(b5) == [[(0, 0, 0), (0, 0, 0),
                             (255, 255, 255), (255, 255, 255)],
                            [(0, 0, 0), (0, 0, 0),
                             (255, 255, 255), (255, 255, 255)],
                            [(0, 255, 0), (0, 255, 0),
                             (0, 255, 0), (0, 255, 0)],
                            [(0, 255, 0), (0, 255, 0),
                             (0, 255, 0), (0, 255, 0)]]
コード例 #3
0
def test_flatten() -> None:
    blocky = Block((0, 0), 16, (1, 128, 181), 0, 0)
    assert _flatten(blocky) == [[(1, 128, 181)]]
    block = Block((0, 0), 16, None, 0, 1)
    b1 = Block((8, 0), 8, (1, 128, 181), 1, 1)
    b2 = Block((0, 0), 8, (199, 44, 58), 1, 1)
    b3 = Block((0, 8), 8, (1, 128, 181), 1, 1)
    b4 = Block((8, 8), 8, (255, 211, 92), 1, 1)
    block.children = [b1, b2, b3, b4]
    assert _flatten(block) == [[(199, 44, 58), (1, 128, 181)],
                               [(1, 128, 181), (255, 211, 92)]]
    block1 = Block((0, 0), 16, None, 0, 2)
    c1 = Block((8, 0), 8, (1, 128, 181), 1, 2)
    c2 = Block((0, 0), 8, (199, 44, 58), 1, 2)
    c3 = Block((0, 8), 8, None, 1, 2)
    c4 = Block((8, 8), 8, None, 1, 2)
    block1.children = [c1, c2, c3, c4]
    b31 = Block((4, 8), 4, (1, 128, 181), 2, 2)
    b32 = Block((0, 8), 4, (199, 44, 58), 2, 2)
    b33 = Block((0, 12), 4, (255, 211, 92), 2, 2)
    b34 = Block((4, 12), 4, (199, 44, 58), 2, 2)
    c3.children = [b31, b32, b33, b34]
    b41 = Block((12, 8), 4, (255, 211, 92), 2, 2)
    b42 = Block((8, 8), 4, (199, 44, 58), 2, 2)
    b43 = Block((8, 12), 4, (255, 211, 92), 2, 2)
    b44 = Block((12, 12), 4, (199, 44, 58), 2, 2)
    c4.children = [b41, b42, b43, b44]
    block2 = Block((0, 0), 16, None, 0, 2)
    c1 = Block((8, 0), 8, (1, 128, 181), 1, 2)
    c2 = Block((0, 0), 8, (199, 44, 58), 1, 2)
    c3 = Block((0, 8), 8, (255, 211, 92), 1, 2)
    c4 = Block((8, 8), 8, (1, 128, 181), 1, 2)
    block2.children = [c1, c2, c3, c4]
    assert len(_flatten(block1)) == len(_flatten(block2))
    assert _flatten(block1) == [[(199, 44, 58), (199, 44, 58), (199, 44, 58),
                                 (255, 211, 92)],
                                [(199, 44, 58), (199, 44, 58), (1, 128, 181),
                                 (199, 44, 58)],
                                [(1, 128, 181), (1, 128, 181), (199, 44, 58),
                                 (255, 211, 92)],
                                [(1, 128, 181), (1, 128, 181), (255, 211, 92),
                                 (199, 44, 58)]]
    assert _flatten(block2) == [[(199, 44, 58), (199, 44, 58), (255, 211, 92),
                                 (255, 211, 92)],
                                [(199, 44, 58), (199, 44, 58), (255, 211, 92),
                                 (255, 211, 92)],
                                [(1, 128, 181), (1, 128, 181), (1, 128, 181),
                                 (1, 128, 181)],
                                [(1, 128, 181), (1, 128, 181), (1, 128, 181),
                                 (1, 128, 181)]]
コード例 #4
0
 def test_flatten_3(self):
     """
                     A_____B______C_______D______
                     |     |      |       |      |
                     E_____F______G_______H______|
                     |     |      |       |      |
                     I_____J______K_______L______|
                     |     |      |       |      |
                     M_____N______O_______P______|
                     |     |      |       |      |
                     |_____|______|_______|______|
     A:(30, 30, 30)
     B:(30, 30, 30)
     C:(20, 20, 20)
     D:(20, 20, 20)
     E:(30, 30, 30)
     F:(30, 30, 30)
     G:(20, 20, 20)
     H:(20, 20, 20)
     I:(40, 40, 40)
     J:(40, 40, 40)
     K:(50, 50, 50)
     L:(50, 50, 50)
     M:(40, 40, 40)
     N:(40, 40, 40)
     O:(50, 50, 50)
     P:(50, 50, 50)
     Expected Return Value:
     [[(30, 30, 30), (30, 30, 30), (40, 40, 40), (40, 40, 40)],
     [(30, 30, 30), (30, 30, 30), (40, 40, 40), (40, 40, 40)],
     [(20, 20, 20), (20, 20, 20), (50, 50, 50), (50, 50, 50)],
     [(20, 20, 20), (20, 20, 20), (50, 50, 50), (50, 50, 50)]]
     """
     self.one_level.max_depth = 2
     for child in self.one_level.children:
         child.max_depth = 2
     res = _flatten(self.one_level)
     exp = [[(30, 30, 30), (30, 30, 30), (40, 40, 40), (40, 40, 40)],
            [(30, 30, 30), (30, 30, 30), (40, 40, 40), (40, 40, 40)],
            [(20, 20, 20), (20, 20, 20), (50, 50, 50), (50, 50, 50)],
            [(20, 20, 20), (20, 20, 20), (50, 50, 50), (50, 50, 50)]]
     self.assertEqual(exp, res)
コード例 #5
0
ファイル: example_tests.py プロジェクト: alxshev/csc148_a2
    def test_block_flatten(self, board_16x16, flattened_board_16x16) -> None:
        """Test that flattening the reference board results in the expected list
        of colours.
        """
        result = _flatten(board_16x16)
        board_16x16.children[0].children[0].colour = ()
        print("children: ")
        print([child for child in board_16x16.children])
        print(board_16x16.children[0].children[0].colour)
        print("Flattened:")
        _2d_print(result)

        print("\n Correct:")
        _2d_print(flattened_board_16x16)

        # We are expected a "square" 2D list
        for sublist in result:
            assert len(result) == len(sublist)
        print(result == flattened_board_16x16)
        assert result == flattened_board_16x16
コード例 #6
0
 def test_flatten_2(self):
     """
     Case 1:
     (0, 0, (30, 30, 30))      (5, 0, (20, 20, 20))
                     ___________________________
                     |            |             |
                     |            |             |
                     |            |             |
         (0, 5, (40, 40, 40))           (5, 5, (50, 50, 50))
                     |____________|____________ |
                     |            |             |
                     |            |             |
                     |            |             |
                     |____________|_____________|
     Expected Return Value
     [[(30, 30, 30), (40, 40, 40)],
     [(20, 20, 20), (50, 50, 50)]]
     """
     res = _flatten(self.one_level)
     self.assertEqual([[(30, 30, 30),
                        (40, 40, 40)], [(20, 20, 20), (50, 50, 50)]], res)
コード例 #7
0
ファイル: test.py プロジェクト: Fenil-P/Blocky
 def test_flatten_(self) -> None:
     assert _flatten(standard_borde()) == [
         [
             DAFFODIL_DELIGHT, DAFFODIL_DELIGHT, DAFFODIL_DELIGHT,
             DAFFODIL_DELIGHT, REAL_RED, REAL_RED, OLD_OLIVE, OLD_OLIVE
         ],
         [
             DAFFODIL_DELIGHT, DAFFODIL_DELIGHT, DAFFODIL_DELIGHT,
             DAFFODIL_DELIGHT, REAL_RED, REAL_RED, OLD_OLIVE, OLD_OLIVE
         ],
         [
             DAFFODIL_DELIGHT, DAFFODIL_DELIGHT, DAFFODIL_DELIGHT,
             DAFFODIL_DELIGHT, PACIFIC_POINT, PACIFIC_POINT, PACIFIC_POINT,
             PACIFIC_POINT
         ],
         [
             DAFFODIL_DELIGHT, DAFFODIL_DELIGHT, DAFFODIL_DELIGHT,
             DAFFODIL_DELIGHT, PACIFIC_POINT, PACIFIC_POINT, PACIFIC_POINT,
             PACIFIC_POINT
         ],
         [
             REAL_RED, REAL_RED, OLD_OLIVE, OLD_OLIVE, PACIFIC_POINT,
             PACIFIC_POINT, PACIFIC_POINT, PACIFIC_POINT
         ],
         [
             REAL_RED, REAL_RED, OLD_OLIVE, OLD_OLIVE, PACIFIC_POINT,
             PACIFIC_POINT, PACIFIC_POINT, PACIFIC_POINT
         ],
         [
             PACIFIC_POINT, PACIFIC_POINT, DAFFODIL_DELIGHT,
             DAFFODIL_DELIGHT, PACIFIC_POINT, PACIFIC_POINT, PACIFIC_POINT,
             PACIFIC_POINT
         ],
         [
             PACIFIC_POINT, PACIFIC_POINT, DAFFODIL_DELIGHT,
             DAFFODIL_DELIGHT, PACIFIC_POINT, PACIFIC_POINT, PACIFIC_POINT,
             PACIFIC_POINT
         ]
     ]
コード例 #8
0
def test_flatten_board_4x4(board_4x4) -> None:
    result = _flatten(board_4x4)
    print(result)
    assert result == [[COLOUR_LIST[1], COLOUR_LIST[2]],
                      [COLOUR_LIST[0], COLOUR_LIST[3]]]
コード例 #9
0
def test_flatten_single_board(single_board) -> None:
    assert [[COLOUR_LIST[0]]] == _flatten(single_board)
コード例 #10
0
def test_flatten_second_to_lowest(block_second_to_lowest):
    colour = block_second_to_lowest.colour
    assert _flatten(block_second_to_lowest) == [[colour, colour],
                                                [colour, colour]]
コード例 #11
0
def test_flatten_lowest(block_lowest):
    colour = block_lowest.colour
    assert _flatten(block_lowest) == [[colour]]
コード例 #12
0
ファイル: A2_testing_suite.py プロジェクト: jaspermai/Blocky
 def test_flatten_leaf(self, board_32x32) -> None:
     leaf = board_32x32.children[0].children[1].children[2]
     assert _flatten(leaf) == [[COLOUR_LIST[0]]]
コード例 #13
0
ファイル: A2_testing_suite.py プロジェクト: jaspermai/Blocky
 def test_flatten(self, board_32x32, flattened_board_32x32) -> None:
     assert _flatten(board_32x32) == flattened_board_32x32