Skip to content

Commit

Permalink
Fix restore resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
numirias committed Dec 18, 2017
1 parent df8a772 commit eb3977a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions plasma/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ def close_right(self):
return self.close_neighbor(RIGHT)

def add_child(self, node, idx=None):
# TODO Currently we assume that the node has no size.
if idx is None:
idx = len(self)
self.children.insert(idx, node)
Expand All @@ -497,12 +496,14 @@ def remove_child(self, node):
node.force_size(0)
self.children.remove(node)
if len(self) == 1:
child = self[0]
if self.is_root:
# A single child doesn't need a fixed size
self[0].reset_size()
child.reset_size()
else:
# Collapse tree with a single child
self.parent.replace_child(self, self[0])
self.parent.replace_child(self, child)
Node.fit_into(child, self.capacity)

def remove(self):
self.parent.remove_child(self)
Expand Down Expand Up @@ -555,8 +556,10 @@ def restore(self, node):
raise NotRestorableError()
node.reset_size()
if flip:
old_parent_size = parent.size
parent.flip_with(node, reverse=(idx == 0))
node.size, parent.size = sizes
Node.fit_into(parent, old_parent_size)
else:
parent.add_child(node, idx=idx)
node.size = sizes[0]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,21 @@ def test_resize_max(self, root, tiny_grid):
assert a.width == 110
assert b.width == c.width == 10

def test_resize_with_collapse_and_restore(self, root, small_grid):
a, b, c, d = small_grid
root.height = 30
c.size = 30
d.size += 10
b.remove()
assert c.size == c.height == 10
assert d.size == d.height == 20
root.restore(b)
assert b.height == 15
assert b.width == 60
assert c.height == d.height == 15
assert c.width == 20
assert d.width == 40

class TestRestore:

def test_restore(self, root, grid):
Expand Down

0 comments on commit eb3977a

Please sign in to comment.