Beispiel #1
0
        public void Compare_TwoEmptyNodes_ExpectsEqual()
        {
            var node1 = new BTreeNode <int, string>(3);
            var node2 = new BTreeNode <int, string>(3);

            Assert.AreEqual(0, node1.CompareTo(node2));
        }
Beispiel #2
0
        public void Compare_NonEmptyToEmpty_ExpectsNonEmptyToBeBigger()
        {
            var node1 = new BTreeNode <int, string>(3);

            node1.InsertKeyValue(new KeyValuePair <int, string>(10, "A"));
            var node2 = new BTreeNode <int, string>(3);

            Assert.AreEqual(1, node1.CompareTo(node2));
        }
Beispiel #3
0
        public void Compare_TwoNodesEachWithOneKey_ExpectsNodeWithSmallerKeyToBeSmaller()
        {
            var node1 = new BTreeNode <int, string>(3);

            node1.InsertKeyValue(new KeyValuePair <int, string>(10, "A"));
            var node2 = new BTreeNode <int, string>(3);

            node2.InsertKeyValue(new KeyValuePair <int, string>(50, "B2"));
            Assert.AreEqual(-1, node1.CompareTo(node2));
        }
Beispiel #4
0
        public void Compare_TwoNodesWithEqualMinKeyAndDifferentMaxKey_ExpectsEqual()
        {
            var node1 = new BTreeNode <int, string>(3);

            node1.InsertKeyValue(new KeyValuePair <int, string>(10, "A"));
            var node2 = new BTreeNode <int, string>(3);

            node2.InsertKeyValue(new KeyValuePair <int, string>(50, "B2"));
            node2.InsertKeyValue(new KeyValuePair <int, string>(10, "A2"));

            /* Notice that in a B-Tree node we do not expect 2 children to have the same min key. Thus these 2 nodes are expected to be equal, and considered duplicates to prevent inserting one of them in the tree.*/
            Assert.AreEqual(0, node1.CompareTo(node2));
        }
Beispiel #5
0
        public void Compare_OtherIsNull_ExpectsBigger()
        {
            var node = new BTreeNode <int, string>(3);

            Assert.AreEqual(1, node.CompareTo(null));
        }