Skip to content

Commit

Permalink
Test for TreeItem.setItemCount() eclipse-platform#882
Browse files Browse the repository at this point in the history
  • Loading branch information
basilevs committed Nov 19, 2023
1 parent 673cd50 commit e874da4
Showing 1 changed file with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,13 @@ public void test_getItemCountNoGrowth() {
});
}

@Test
public void test_setItemCountLinearGrowth() {
testTreeRegularAndVirtual(() -> {
assertLinear("setItemCount execution time", this::measureSetItemCountNanos);
});
}


void buildBinaryTree(TreeItem parent, int totalChildCount) {
if (totalChildCount <= 0) {
Expand Down Expand Up @@ -1373,9 +1380,16 @@ public void test_wideBreadthFirstTraversalLinearGrowth() {
}

@Test
public void test_updateAllChildrenLinearGrowth() {
public void test_updateAllChildrenWideLinearGrowth() {
testTreeRegularAndVirtual(() -> {
assertLinear("Update all children", this::measureUpdateAllChildrenWide);
});
}

@Test
public void test_updateAllChildrenBinaryLinearGrowth() {
testTreeRegularAndVirtual(() -> {
assertLinear("Update all children", this::measureUpdateAllChildren);
assertLinear("Update all children", this::measureUpdateAllChildrenBinary);
});
}

Expand All @@ -1396,7 +1410,7 @@ public void test_breadthFirstTraverseUnique() {
});
}

private double measureUpdateAllChildren(int totalChildCount) {
private double measureUpdateAllChildrenWide(int totalChildCount) {
TreeItem root = new TreeItem(tree, SWT.NONE);
buildWideTree(root, totalChildCount - 1);
return measureNanos(() -> {
Expand All @@ -1412,4 +1426,30 @@ private double measureUpdateAllChildren(int totalChildCount) {
});
}

private double measureUpdateAllChildrenBinary(int totalChildCount) {
TreeItem root = new TreeItem(tree, SWT.NONE);
buildBinaryTree(root, totalChildCount - 1);
return measureNanos(() -> {
tree.setRedraw(false);
try {
String text = "" + System.currentTimeMillis();
breadthFirstTraverse(root, item -> {
item.setText(text);
});
} finally {
tree.setRedraw(true);
}
});
}

private double measureSetItemCountNanos(int totalChildCount) {
TreeItem root = new TreeItem(tree, SWT.NONE);
buildWideTree(root, totalChildCount - 1);
return measureNanos(() -> {
root.setItemCount(0);
root.setItemCount(totalChildCount - 1);
root.setItemCount(0);
});
}

}

0 comments on commit e874da4

Please sign in to comment.