コード例 #1
0
ファイル: test_BTree.py プロジェクト: hermajan/algorithms
def init_test_tree():
	tree = BTree()
	tree.arity = 4

	n12 = create_node([55, 75], [], True)
	n11 = create_node([25], [], True)
	n10 = create_node([17], [], True)
	n9 = create_node([14, 15], [], True)
	n8 = create_node([9, 10, 12], [], True)
	n7 = create_node([6, 7], [], True)
	n6 = create_node([3], [], True)
	n5 = create_node([0, 1], [], True)
	n4 = create_node([16, 18, 50], [n9, n10, n11, n12], False)
	n3 = create_node([8], [n7, n8], False)
	n2 = create_node([2], [n5, n6], False)
	n1 = create_node([5,13], [n2, n3, n4], False)

	tree.root = n1
	tree.height = 2

	return tree
コード例 #2
0
ファイル: test_BTree.py プロジェクト: hermajan/algorithms
def init_test_tree():
    tree = BTree()
    tree.arity = 4

    n12 = create_node([55, 75], [], True)
    n11 = create_node([25], [], True)
    n10 = create_node([17], [], True)
    n9 = create_node([14, 15], [], True)
    n8 = create_node([9, 10, 12], [], True)
    n7 = create_node([6, 7], [], True)
    n6 = create_node([3], [], True)
    n5 = create_node([0, 1], [], True)
    n4 = create_node([16, 18, 50], [n9, n10, n11, n12], False)
    n3 = create_node([8], [n7, n8], False)
    n2 = create_node([2], [n5, n6], False)
    n1 = create_node([5, 13], [n2, n3, n4], False)

    tree.root = n1
    tree.height = 2

    return tree
コード例 #3
0
ファイル: test_BTree.py プロジェクト: hermajan/algorithms
	def test_insert(self):
		tree = BTree()
		tree.arity = 4

		tree.insert(1)
		self.assertIsNotNone(tree.root)
		self.assertListEqual(tree.root.keys, [1], "Inserting to empty B-Tree order 2.")

		tree.insert(7)
		tree.insert(2)
		self.assertIsNotNone(tree.root)
		self.assertListEqual(tree.root.keys, [1, 2, 7], "Inserting to B-Tree without splitting.")

		tree.insert(5)
		self.assertIsNotNone(tree.root)
		msg = "Inserting to B-Tree with splitting of root."
		self.assertListEqual(tree.root.keys, [2], msg)
		self.assertListEqual(tree.root.children[0].keys, [1], msg)
		self.assertListEqual(tree.root.children[1].keys, [5, 7], msg)

		tree.insert(12)
		tree.insert(8)
		self.assertIsNotNone(tree.root)
		msg = "Inserting to B-Tree with splitting of leaf."
		self.assertListEqual(tree.root.keys, [2, 7], msg)
		self.assertListEqual(tree.root.children[0].keys, [1], msg)
		self.assertListEqual(tree.root.children[1].keys, [5], msg)
		self.assertListEqual(tree.root.children[2].keys, [8, 12], msg)
コード例 #4
0
ファイル: test_BTree.py プロジェクト: hermajan/algorithms
    def test_insert(self):
        tree = BTree()
        tree.arity = 4

        tree.insert(1)
        self.assertIsNotNone(tree.root)
        self.assertListEqual(tree.root.keys, [1],
                             "Inserting to empty B-Tree order 2.")

        tree.insert(7)
        tree.insert(2)
        self.assertIsNotNone(tree.root)
        self.assertListEqual(tree.root.keys, [1, 2, 7],
                             "Inserting to B-Tree without splitting.")

        tree.insert(5)
        self.assertIsNotNone(tree.root)
        msg = "Inserting to B-Tree with splitting of root."
        self.assertListEqual(tree.root.keys, [2], msg)
        self.assertListEqual(tree.root.children[0].keys, [1], msg)
        self.assertListEqual(tree.root.children[1].keys, [5, 7], msg)

        tree.insert(12)
        tree.insert(8)
        self.assertIsNotNone(tree.root)
        msg = "Inserting to B-Tree with splitting of leaf."
        self.assertListEqual(tree.root.keys, [2, 7], msg)
        self.assertListEqual(tree.root.children[0].keys, [1], msg)
        self.assertListEqual(tree.root.children[1].keys, [5], msg)
        self.assertListEqual(tree.root.children[2].keys, [8, 12], msg)