public void TestMethod3() { Node root = new Node(node_type.inner, new List<int>() { 16 }); Node child1 = new Node(node_type.inner, new List<int>() { 7, 13 }); Node child2 = new Node(node_type.inner, new List<int>() { 20, 24 }); Node child3 = new Node(node_type.leaf, new List<int>() { 1, 2, 3, 4, 5 }); Node child4 = new Node(node_type.leaf, new List<int>() { 10, 11, 12 }); Node child5 = new Node(node_type.leaf, new List<int>() { 14, 15 }); Node child6 = new Node(node_type.leaf, new List<int>() { 17, 18, 19 }); Node child7 = new Node(node_type.leaf, new List<int>() { 21, 22 }); Node child8 = new Node(node_type.leaf, new List<int>() { 25, 26 }); root.AddChild(child1); root.AddChild(child2); child1.AddChild(child3); child1.AddChild(child4); child1.AddChild(child5); child2.AddChild(child6); child2.AddChild(child7); child2.AddChild(child8); BTree tree = new BTree(root, 3); bool flag = BTree.Check(tree); Assert.AreEqual(true, flag); }
public void TestMethod2() { Node root = new Node(node_type.inner, new List<int>() { 7, 13, 20, 30 }); Node child1 = new Node(node_type.leaf, new List<int>() { 1, 3, 4, 5 }); Node child2 = new Node(node_type.leaf, new List<int>() { 10, 11 }); Node child3 = new Node(node_type.leaf, new List<int>() { 14, 15 }); Node child4 = new Node(node_type.leaf, new List<int>() { 19, 20, 21 }); Node child5 = new Node(node_type.leaf, new List<int>() { 31, 32 }); root.AddChild(child1); root.AddChild(child2); root.AddChild(child3); root.AddChild(child4); root.AddChild(child5); BTree tree = new BTree(root, 3); bool flag = BTree.Check(tree); Assert.AreEqual(false, flag); }
public void TestMethod4() { Node root = new Node(node_type.inner, new List<int>() { 20, 22, 35 }); Node child1 = new Node(node_type.leaf, new List<int>() { 5, 7, 10, 15 }); Node child2 = new Node(node_type.leaf, new List<int>() { 23, 24 }); Node child3 = new Node(node_type.leaf, new List<int>() { 27, 29, 30 }); Node child4 = new Node(node_type.leaf, new List<int>() { 36, 38 }); root.AddChild(child1); root.AddChild(child2); root.AddChild(child3); root.AddChild(child4); BTree tree = new BTree(root, 3); bool flag = BTree.Check(tree); Assert.AreEqual(false, flag); }
public void TestMethod9() { Node root = new Node(node_type.inner, new List<int>() { 22 }); Node child1 = new Node(node_type.leaf, new List<int>() { 10 }); root.AddChild(child1); BTree tree = new BTree(root, 2); bool flag = BTree.Check(tree); Assert.AreEqual(false, flag); }
public void TestMethod6() { Node root = new Node(node_type.inner, new List<int>() { 25 }); Node child1 = new Node(node_type.inner, new List<int>() { 10, 16 }); Node child2 = new Node(node_type.inner, new List<int>() { 26 }); Node child3 = new Node(node_type.leaf, new List<int>() { 4, 6, 8 }); Node child4 = new Node(node_type.leaf, new List<int>() { 12, 14 }); Node child5 = new Node(node_type.leaf, new List<int>() { 18, 20 }); Node child6 = new Node(node_type.leaf, new List<int>() { 24 }); Node child7 = new Node(node_type.leaf, new List<int>() { 28, 30 }); root.AddChild(child1); root.AddChild(child2); child1.AddChild(child3); child1.AddChild(child4); child1.AddChild(child5); child2.AddChild(child6); child2.AddChild(child7); BTree tree = new BTree(root, 2); bool flag = BTree.Check(tree); Assert.AreEqual(false, flag); }
/// <summary> /// Проверка корня на: /// 1. Упорядоченность элементов по возрастанию /// 2. Для каждого элемента корня: левый сосед меньше, правый - больше /// </summary> /// <param name="tree"> б-дерево </param> /// <returns> результат проверки </returns> public static bool RootTest(BTree tree) { int rootCount = tree.root.values.Count; int childrenCount = tree.root.children.Count; if (!(rootCount + 1 == childrenCount)) return false; if (rootCount == 1)//если корень сосотоит из одного элемента, то всегда два потомка { if (tree.root.children[0].values[0] > tree.root.values[0]) return false; if (tree.root.children[1].values[0] < tree.root.values[0]) return false; } for (int i = 0; i < rootCount - 1; i++) { if (tree.root.values[i] > tree.root.values[i + 1]) return false; if (tree.root.values[i] < tree.root.children[i].values[0]) return false; if (tree.root.values[i] > tree.root.children[i + 1].values[0]) return false; } int rootValue = tree.root.values[rootCount - 1]; if (rootValue < tree.root.children[rootCount - 1].values[0]) return false; if (rootValue > tree.root.children[rootCount].values[0]) return false; return true; }