update unit tests for QuadTree refactoring

This commit is contained in:
James Seibel
2023-05-18 22:07:02 -05:00
parent 6a6ea845ea
commit 95db633e09
2 changed files with 49 additions and 10 deletions
@@ -241,6 +241,45 @@ public class QuadTree<T>
}
});
// // remove out of bound nodes and clean up empty nodes
// // Note: this will iterate over a lot of unnecessary nodes, hopefully speed won't be an issue
// Iterator<DhSectionPos> rootNodePosIterator = this.rootNodePosIterator();
// while (rootNodePosIterator.hasNext())
// {
// // get the root node (regular nodeIterators won't return them if they are out of bounds)
// DhSectionPos rootPos = rootNodePosIterator.next();
// QuadNode<T> rootNode = this.getOrSetNode(rootPos, false, null, false);
// if (rootNode == null)
// {
// continue;
// }
//
// // remove any child nodes that are out of bounds
// Iterator<QuadNode<T>> nodeIterator = this.nodeIterator();
// while (nodeIterator.hasNext())
// {
// QuadNode<T> node = nodeIterator.next();
// if(!this.isSectionPosInBounds(node.sectionPos))
// {
// // node is out of bounds
//
// // FIXME(?) this appears to potentially return large nodes that are partially or entirely in bounds
//
// if (node.getNonNullChildCount() == 0)
// {
// // no child nodes, can be safely removed
// nodeIterator.remove();
// }
// else
// {
// // node can't be removed, but its value can be set to null
// node.value = null;
// }
// }
// }
// }
}
public final DhBlockPos2D getCenterBlockPos() { return this.centerBlockPos; }
+10 -10
View File
@@ -687,7 +687,7 @@ public class QuadTreeTest
rootNode.setValue(sectionPos, 1);
}
Assert.assertEquals("node not filled", 4, rootNode.getChildValueCount());
Assert.assertEquals("node not filled", 4, rootNode.getNonNullChildCount());
for (int i = 0; i < 4; i++)
@@ -722,7 +722,7 @@ public class QuadTreeTest
DhSectionPos childPos = childPosIterator.next();
centerRootNode.setValue(childPos, 1);
}
Assert.assertEquals("center node not filled", 4, centerRootNode.getChildValueCount());
Assert.assertEquals("center node not filled", 4, centerRootNode.getNonNullChildCount());
@@ -742,7 +742,7 @@ public class QuadTreeTest
offsetRootNode.setValue(childPos, 1);
}
// TODO James thought this shouldn't work for all 4 nodes, but he must've thought wrong.
Assert.assertEquals("offset should only contain some children.", 4, offsetRootNode.getChildValueCount());
Assert.assertEquals("offset should only contain some children.", 4, offsetRootNode.getNonNullChildCount());
}
@@ -782,8 +782,8 @@ public class QuadTreeTest
// validate nodes were added
Assert.assertEquals(4, rootNode.getChildValueCount());
Assert.assertEquals(4, rootNode.getNode(midNodePos).getChildValueCount());
Assert.assertEquals(4, rootNode.getNonNullChildCount());
Assert.assertEquals(4, rootNode.getNode(midNodePos).getNonNullChildCount());
@@ -792,30 +792,30 @@ public class QuadTreeTest
// remove two leaf nodes from the root
DhSectionPos leafPos = new DhSectionPos((byte)9, 1, 1);
rootNode.setValue(leafPos, null);
Assert.assertEquals(3, rootNode.getChildValueCount());
Assert.assertEquals(3, rootNode.getNonNullChildCount());
Assert.assertNull("Node wasn't deleted", rootNode.getNode(leafPos));
leafPos = new DhSectionPos((byte)9, 0, 1);
rootNode.setValue(leafPos, null);
Assert.assertEquals(2, rootNode.getChildValueCount());
Assert.assertEquals(2, rootNode.getNonNullChildCount());
Assert.assertNull("Node wasn't deleted", rootNode.getNode(leafPos));
// remove
// remove all child nodes
Assert.assertEquals(4, rootNode.getNode(midNodePos).getChildValueCount());
Assert.assertEquals(4, rootNode.getNode(midNodePos).getNonNullChildCount());
// remove all but one, mid-node should still be present
rootNode.setValue(new DhSectionPos((byte)8, 0, 0), null);
rootNode.setValue(new DhSectionPos((byte)8, 0, 1), null);
rootNode.setValue(new DhSectionPos((byte)8, 1, 0), null);
Assert.assertEquals(1, rootNode.getNode(midNodePos).getChildValueCount());
Assert.assertEquals(1, rootNode.getNode(midNodePos).getNonNullChildCount());
// remove last mid-node child, mid-node should now be removed
rootNode.setValue(new DhSectionPos((byte)8, 1, 1), null);
Assert.assertNull("Mid node not deleted.", rootNode.getNode(midNodePos));
Assert.assertEquals(3, rootNode.getChildValueCount());
Assert.assertEquals(3, rootNode.getNonNullChildCount());
}