コード例 #1
0
        public void Test_InnerNode_Split_Test()
        {
            var innerNode = new InnerNode<int, int>(3);

            var leafNode = new LeafNode<int, int>(3);
            leafNode.Keys.Add(1);
            leafNode.Values.Add(new List<int>());
            leafNode.Values[0].Add(1);
            innerNode.Children.Add(leafNode);

            innerNode.Keys.Add(2);

            leafNode = new LeafNode<int, int>(3);
            leafNode.Keys.Add(2);
            leafNode.Values.Add(new List<int>());
            leafNode.Values[0].Add(2);
            innerNode.Children.Add(leafNode);

            innerNode.Keys.Add(3);

            leafNode = new LeafNode<int, int>(3);
            leafNode.Keys.Add(3);
            leafNode.Values.Add(new List<int>());
            leafNode.Values[0].Add(3);
            innerNode.Children.Add(leafNode);

            innerNode.Keys.Add(4);

            leafNode = new LeafNode<int, int>(3);
            leafNode.Keys.Add(4);
            leafNode.Values.Add(new List<int>());
            leafNode.Values[0].Add(4);
            leafNode.Keys.Add(5);
            leafNode.Values.Add(new List<int>());
            leafNode.Values[1].Add(5);
            innerNode.Children.Add(leafNode);

            var split = innerNode.Split() as InnerNode<int, int>;
            Assert.IsNotNull(split);
            Assert.AreEqual(2, innerNode.Children.Count);
            Assert.AreEqual(2, innerNode.Keys.Count);
            Assert.AreEqual(2, split.Children.Count);

            // this key will get promoted
            Assert.AreEqual(1, split.Keys.Count);
        }