Пример #1
0
    def test_cleanup(self):
        # Make sure that if a child is freed cleanup only occurs when empty

        # +----+----+
        # |    |    |
        # +----+    |
        # |    |    |
        # +----+----+
        p = PackTree(0, 0, 10, 10)
        p.vsplit(x=5)
        p.children[0].hsplit(y=5)

        p.children[0].children[0].allocated = True
        p.children[0].children[1].allocated = True
        p.children[1].allocated = True

        # If we free one of the grandchildren the tree should remain unchanged
        p.free(0, 0)
        assert p.children is not None
        assert p.children[0].children is not None
        assert p.children[0].children[0].children is None
        assert p.children[0].children[1].children is None
        assert p.children[1].children is None

        # If we free a top level child the tree should remain unchanged
        p.free(5, 0)
        assert p.children is not None
        assert p.children[0].children is not None
        assert p.children[0].children[0].children is None
        assert p.children[0].children[1].children is None
        assert p.children[1].children is None

        # If we free the remaining grandchild the whole tree should collapse
        p.free(0, 5)
        assert p.children is None
Пример #2
0
    def test_cleanup(self):
        # Make sure that if a child is freed cleanup only occurs when empty

        # +----+----+
        # |    |    |
        # +----+    |
        # |    |    |
        # +----+----+
        p = PackTree(0, 0, 10, 10)
        p.vsplit(x=5)
        p.children[0].hsplit(y=5)

        p.children[0].children[0].allocated = True
        p.children[0].children[1].allocated = True
        p.children[1].allocated = True

        # If we free one of the grandchildren the tree should remain unchanged
        p.free(0, 0)
        assert p.children is not None
        assert p.children[0].children is not None
        assert p.children[0].children[0].children is None
        assert p.children[0].children[1].children is None
        assert p.children[1].children is None

        # If we free a top level child the tree should remain unchanged
        p.free(5, 0)
        assert p.children is not None
        assert p.children[0].children is not None
        assert p.children[0].children[0].children is None
        assert p.children[0].children[1].children is None
        assert p.children[1].children is None

        # If we free the remaining grandchild the whole tree should collapse
        p.free(0, 5)
        assert p.children is None
Пример #3
0
    def test_smallest_child_first(self):
        p = PackTree(0, 0, 3, 1)
        p.vsplit(1)
        assert p.alloc_area(1) == (0, 0, 1, 1)

        p = PackTree(0, 0, 3, 1)
        p.vsplit(2)
        assert p.alloc_area(1) == (2, 0, 1, 1)
Пример #4
0
    def test_smallest_child_first(self):
        p = PackTree(0, 0, 3, 1)
        p.vsplit(1)
        assert p.alloc_area(1) == (0, 0, 1, 1)

        p = PackTree(0, 0, 3, 1)
        p.vsplit(2)
        assert p.alloc_area(1) == (2, 0, 1, 1)
Пример #5
0
 def test_candidate_filter(self):
     p = PackTree(0, 0, 2, 1)
     p.vsplit(1)
     cf = Mock(side_effect=[False, True])
     assert p.alloc_area(1, 0.0, cf) == (1, 0, 1, 1)
     assert cf.mock_calls == [
         call(0, 0, 1, 1),
         call(1, 0, 1, 1),
     ]
Пример #6
0
 def test_candidate_filter(self):
     p = PackTree(0, 0, 2, 1)
     p.vsplit(1)
     cf = Mock(side_effect=[False, True])
     assert p.alloc_area(1, 0.0, cf) == (1, 0, 1, 1)
     assert cf.mock_calls == [
         call(0, 0, 1, 1),
         call(1, 0, 1, 1),
     ]
Пример #7
0
    def test_try_children(self):
        # Try inserting into the children, try the smallest chlid first
        p = PackTree(0, 0, 3, 1)
        p.vsplit(x=2)

        assert p.alloc(1, 1) == (2, 0)

        assert p.allocated is False
        assert p.children[0].allocated is False
        assert p.children[1].allocated is True
Пример #8
0
    def test_try_children(self):
        # Try inserting into the children, try the smallest chlid first
        p = PackTree(0, 0, 3, 1)
        p.vsplit(x=2)

        assert p.alloc(1, 1) == (2, 0)

        assert p.allocated is False
        assert p.children[0].allocated is False
        assert p.children[1].allocated is True
Пример #9
0
def test_vsplit():
    p = PackTree(1, 2, 3, 4)
    p.vsplit(x=3)

    assert p.children[0].x == 1
    assert p.children[0].y == 2
    assert p.children[0].width == 2
    assert p.children[0].height == 4

    assert p.children[1].x == 3
    assert p.children[1].y == 2
    assert p.children[1].width == 1
    assert p.children[1].height == 4
Пример #10
0
def test_vsplit():
    p = PackTree(1, 2, 3, 4)
    p.vsplit(x=3)

    assert p.children[0].x == 1
    assert p.children[0].y == 2
    assert p.children[0].width == 2
    assert p.children[0].height == 4

    assert p.children[1].x == 3
    assert p.children[1].y == 2
    assert p.children[1].width == 1
    assert p.children[1].height == 4
Пример #11
0
    def test_try_children(self):
        p = PackTree(1, 2, 2, 1)
        p.vsplit(x=2)
        assert p.request(1, 2) == (1, 2)

        assert p.allocated is False
        assert p.children is not None
        assert p.children[0].allocated is True
        assert p.children[0].children is None
        assert p.children[1].allocated is False
        assert p.children[1].children is None

        assert p.request(2, 2) == (2, 2)

        assert p.allocated is False
        assert p.children is not None
        assert p.children[0].allocated is True
        assert p.children[0].children is None
        assert p.children[1].allocated is True
        assert p.children[1].children is None
Пример #12
0
    def test_try_children(self):
        p = PackTree(1, 2, 2, 1)
        p.vsplit(x=2)
        assert p.request(1, 2) == (1, 2)

        assert p.allocated is False
        assert p.children is not None
        assert p.children[0].allocated is True
        assert p.children[0].children is None
        assert p.children[1].allocated is False
        assert p.children[1].children is None

        assert p.request(2, 2) == (2, 2)

        assert p.allocated is False
        assert p.children is not None
        assert p.children[0].allocated is True
        assert p.children[0].children is None
        assert p.children[1].allocated is True
        assert p.children[1].children is None
Пример #13
0
    def test_try_children_impossible(self):
        # Try inserting into the children which don't have room
        p = PackTree(0, 0, 3, 1)
        p.vsplit(x=2)

        assert p.alloc(3, 1) is None
Пример #14
0
    def test_try_children_impossible(self):
        # Try inserting into the children which don't have room
        p = PackTree(0, 0, 3, 1)
        p.vsplit(x=2)

        assert p.alloc(3, 1) is None