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
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
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)
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)
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), ]
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), ]
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
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
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
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
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
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
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
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