public void SerializeQuadTree() { { var tree = new QuadTree <string>(); VerifyTreeClone(tree); } { var tree = new QuadTree <string>(); tree.AddItem("(0, 0)", new Vector2r()); tree.AddItem("(1, -1)", new Vector2r(1, -1)); tree.AddMonitor(new TestMonitor <string>(), new Bound(0, 10, 5)); VerifyTreeClone(tree); } { var tree = new QuadTree <string>(); tree.AddMonitor(new TestMonitor <string>(), new Bound(0, 0, 100)); tree.AddMonitor(new TestMonitor <string>(), new Bound(0, 5, 100)); VerifyTreeClone(tree); } }
public void MonitorTests(int worldScale) { var tree = new QuadTree <object>(worldScale); // test a monitor on an initially empty tree, add an object to the tree and ensure that // the monitor contains it, update the monitor to a position that doesn't contain the // item in the tree, ensure the monitor is empty, update the monitor so that it contains // the item again, ensure the monitor contains the item, update the monitor so that it // still contains the item & verify, then remove the monitor and ensure it is empty { var monitor = new TestMonitor <object>(); // inserting a monitor into an empty tree should result in an empty monitor tree.AddMonitor(monitor, new Bound(0, 0, 25)); Assert.Empty(monitor.Contained); // add an object to (0,0) var added = new object(); tree.AddItem(added, new Vector2r()); Assert.Contains(added, monitor.Contained); // update the position of the monitor so that it doesn't contain anything tree.UpdateMonitor(monitor, new Bound(0, 0, 25), new Bound(100, 100, 25)); Assert.Empty(monitor.Contained); // update the position of the monitor so that it contains the item tree.UpdateMonitor(monitor, new Bound(100, 100, 25), new Bound(5, 5, 25)); Assert.Contains(added, monitor.Contained); // update it back to its original position so that it contains everything tree.UpdateMonitor(monitor, new Bound(5, 5, 25), new Bound(0, 0, 25)); Assert.Contains(added, monitor.Contained); // remove the monitor tree.RemoveMonitor(monitor, new Bound(0, 0, 25)); Assert.Empty(monitor.Contained); } // test a monitor on a non-empty tree { var monitor = new TestMonitor <object>(); // the monitor should have the object already in the tree added to it tree.AddMonitor(monitor, new Bound(0, 0, 25)); Assert.NotEmpty(monitor.Contained); // add an object to (0,0) var added = new object(); tree.AddItem(added, new Vector2r()); Assert.Contains(added, monitor.Contained); // remove the monitor tree.RemoveMonitor(monitor, new Bound(0, 0, 25)); Assert.Empty(monitor.Contained); } // test a monitor on a non-empty tree that doesn't contain the objects already in the // tree { var monitor = new TestMonitor <object>(); // the monitor should remain empty when being added to the tree tree.AddMonitor(monitor, new Bound(100, 100, 25)); Assert.Empty(monitor.Contained); // add an object to (0,0); it should not be added to the monitor var added = new object(); tree.AddItem(added, new Vector2r()); Assert.Empty(monitor.Contained); // remove the monitor tree.RemoveMonitor(monitor, new Bound(100, 100, 25)); Assert.Empty(monitor.Contained); } }