Skip to content

Commit

Permalink
Add more QuadTree serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdufault committed Feb 11, 2014
1 parent d30270e commit b095594
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions Forge.CollectionsTests/QuadTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,12 @@ public static IEnumerable<object[]> WorldScales {
}
}

[Fact]
public void SerializeQuadTree() {
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));

Console.WriteLine(SerializationHelpers.Serialize(tree));
private static void VerifyTreeClone<TItem>(QuadTree<TItem> tree) {
var cloned = SerializationHelpers.DeepClone(tree);

Assert.Equal(tree.Items.Count(), cloned.Items.Count());
foreach (var item in tree.Items) {
Assert.Contains(item, cloned.Items);
Assert.True(tree.Items.Contains(item));
}

Assert.Equal(tree.Monitors.Count(), cloned.Monitors.Count());
Expand All @@ -162,6 +154,33 @@ public void SerializeQuadTree() {
}
}

[Fact]
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);
}
}

[Theory, PropertyData("WorldScales")]
public void CollectFromQuadTree(int worldScale) {
var tree = new QuadTree<string>(worldScale);
Expand Down

0 comments on commit b095594

Please sign in to comment.