public void TestFindExistingKey() { var store = new Store(); var btree = new PersistentBTree <IntData>(store.GetNextObjectId(), 5, store); btree.Insert(3, null); btree.Insert(10, null); btree.Insert(2, null); btree.Insert(7, null); btree.Insert(5, null); btree.Insert(4, null); btree.Insert(1, null); btree.Insert(12, null); btree.Insert(19, null); btree.Insert(11, null); Assert.AreEqual(10, InOrderTraversal(btree).Count); foreach (var key in InOrderTraversal(btree)) { Node <IntData> keyNode = btree.Lookup(key); Assert.IsNotNull(keyNode); Assert.IsTrue(keyNode.Keys.Contains(key)); } }
public void TestDeleteInLeafWithRightSiblingBorrow() { var store = new Store(); var btree = new PersistentBTree <IntData>(store.GetNextObjectId(), 3, store); btree.Insert(1, null); btree.Insert(2, null); btree.Insert(3, null); btree.Insert(4, null); Assert.IsNotNull(btree.Lookup(1)); btree.Delete(1); Assert.IsNull(btree.Lookup(1)); AssertOrderInList(InOrderTraversal(btree)); Assert.AreEqual(3ul, btree.Root.Keys[0].Key); Assert.AreEqual(2ul, btree.LoadNode(btree.Root.ChildNodes[0]).Keys[0].Key); Assert.AreEqual(4ul, btree.LoadNode(btree.Root.ChildNodes[1]).Keys[0].Key); }
public void TestDeleteInLeaf() { var store = new Store(); var btree = new PersistentBTree <IntData>(store.GetNextObjectId(), 3, store); btree.Insert(1, null); btree.Insert(3, null); btree.Insert(4, null); btree.Insert(2, null); btree.Insert(5, null); btree.Delete(2); Assert.IsNull(btree.Lookup(2)); AssertOrderInList(InOrderTraversal(btree)); }
public void TestFindNonExistantKey() { var store = new Store(); var btree = new PersistentBTree <IntData>(store.GetNextObjectId(), 3, store); btree.Insert(3, null); btree.Insert(10, null); btree.Insert(2, null); btree.Insert(7, null); btree.Insert(5, null); btree.Insert(4, null); btree.Insert(1, null); var keyNode = btree.Lookup(100); Assert.IsNull(keyNode); }