public void Insert_Adds_An_Item_To_An_Existing_Tree_Correctly() { const string itemsAsJson = @"[ [0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [1, 1, 2, 2] ]"; int id = -1; var items = JsonConvert.DeserializeObject <int[][]>(itemsAsJson).Select(array => new RTreeNode <int>(id, new BoundingBox(array[0], array[1], array[2], array[3]))).ToArray(); var tree = new RTree <int>(4); tree.Load(items.Take(3)); tree.Insert(items[3]); Assert.AreEqual(1, tree.Height); tree.Insert(items[4]); Assert.AreEqual(2, tree.Height); CompareNodes(items, tree.All().ToArray(), true); }
public void Bulk_Load() { var tree = new RTree <int>(4); tree.Load(_data); CompareNodes(_data, tree.All().ToArray(), true); }
public void All_Returns_All_Points_In_The_Tree() { var tree = new RTree <int>(4); tree.Load(_data); var all = tree.All(); CompareNodes(_data, all.ToArray(), true); }
public void Load_Properly_Splits_Tree_Root_When_Merging_Trees_Of_Same_Height() { var tree = new RTree <int>(4); tree.Load(_data); tree.Load(_data); Assert.AreEqual(4, tree.Height); CompareNodes(_data.Concat(_data).ToArray(), tree.All().ToArray(), true); }
public void ToJson_And_FromJson_Exports_And_Imports_Tree() { var tree = new RTree <int>(4); tree.Load(_data); string json = tree.ToJson(); var treeFromJson = new RTree <int>(4); treeFromJson.FromJson(json); CompareNodes(tree.All().ToArray(), treeFromJson.All().ToArray()); }
public void Insert_Forms_A_Valid_Tree_If_Items_Are_Inserted_One_By_One() { var tree = new RTree <int>(4); foreach (var item in _data) { tree.Insert(item); } var tree2 = new RTree <int>(4); tree2.Load(_data); Assert.IsTrue(tree.Height - tree2.Height <= 1); CompareNodes(tree.All().ToArray(), tree2.All().ToArray()); }
public void Load_Properly_Merges_Data_Of_Smaller_Or_Bigger_Tree_Heights() { var smaller = SomeData(10); var tree1 = new RTree <int>(4); tree1.Load(_data); tree1.Load(smaller); var tree2 = new RTree <int>(4); tree2.Load(smaller); tree2.Load(_data); Assert.AreEqual(tree1.Height, tree2.Height); CompareNodes(_data.Concat(smaller).ToArray(), tree1.All().ToArray()); CompareNodes(_data.Concat(smaller).ToArray(), tree2.All().ToArray()); }
public void Remove_Removes_Items_Correctly() { var tree = new RTree <int>(4); tree.Load(_data); var length = _data.Length; tree.Remove(_data[0]); tree.Remove(_data[1]); tree.Remove(_data[2]); tree.Remove(_data[length - 1]); tree.Remove(_data[length - 2]); tree.Remove(_data[length - 3]); var dataRemainng = _data.Skip(3).Take(length - 6).ToArray(); CompareNodes(dataRemainng, tree.All().ToArray(), true); }