public void Split_NodeIsOverFlownAndHasChildren_ExpectsSuccessfulSplitForKeysAndChildren() { var node = new BTreeNode <int, string>(3); node.InsertKeyValue(new KeyValuePair <int, string>(20, "A")); node.InsertKeyValue(new KeyValuePair <int, string>(50, "B")); node.InsertKeyValue(new KeyValuePair <int, string>(200, "C")); var child1 = new BTreeNode <int, string>(3); child1.InsertKeyValue(new KeyValuePair <int, string>(10, "D")); node.InsertChild(child1); var child2 = new BTreeNode <int, string>(3); child2.InsertKeyValue(new KeyValuePair <int, string>(30, "E")); node.InsertChild(child2); var child3 = new BTreeNode <int, string>(3); child3.InsertKeyValue(new KeyValuePair <int, string>(100, "F")); node.InsertChild(child3); var child4 = new BTreeNode <int, string>(3); child4.InsertKeyValue(new KeyValuePair <int, string>(300, "G")); node.InsertChild(child4); BTreeNode <int, string> newNode = node.Split(); /* At this point we do not expect 'node' to be valid (i.e., HasBTreeNodeProperties(node)==false ), because the key in the middle has not yet moved up, that step is part of split method in the tree itself and not in the node.*/ Assert.IsTrue(BTreeTestsUtils.HasBTreeNodeProperties <BTreeNode <int, string>, int, string>(newNode)); }
public void Split_NodeIsOverFlownAndHasNoChildren_ExpectsSuccessfulSplitForKeys() { var node = new BTreeNode <int, string>(3); Assert.AreEqual(2, node.MaxKeys); /* Thus to be overFlown (which is the condition for split) node should have 3 keys. */ node.InsertKeyValue(new KeyValuePair <int, string>(100, "C")); node.InsertKeyValue(new KeyValuePair <int, string>(50, "B")); node.InsertKeyValue(new KeyValuePair <int, string>(10, "A")); var newNode = node.Split(); Assert.IsTrue(BTreeTestsUtils.HasBTreeNodeProperties <BTreeNode <int, string>, int, string>(node)); Assert.IsTrue(BTreeTestsUtils.HasBTreeNodeProperties <BTreeNode <int, string>, int, string>(newNode)); Assert.AreEqual(2, node.KeyCount); Assert.AreEqual(1, newNode.KeyCount); }