本文整理汇总了Python中Node.Node.factory方法的典型用法代码示例。如果您正苦于以下问题:Python Node.factory方法的具体用法?Python Node.factory怎么用?Python Node.factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.factory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tree_insertion_equal_node
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_tree_insertion_equal_node(self):
tree = Tree()
tree.insert(Node.factory(12))
tree.insert(Node.factory(12))
self.assertIsNotNone(tree.root_node)
self.assertIsNotNone(tree.root_node.value)
self.assertEqual(12, tree.root_node.value)
self.assertIsNone(tree.root_node.left.value)
self.assertIsNone(tree.root_node.right.value)
示例2: test_node_assignment
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_node_assignment(self):
node1 = Node.factory(25)
node2 = Node.factory(None)
self.assertIsNone(node2.value)
self.assertIsNone(node2.left.value)
self.assertIsNone(node2.right.value)
node2.assign(node1)
self.assertEqual(25, node2.value)
self.assertIsNone(node2.left.value)
self.assertIsNone(node2.right.value)
node1.left = Node.factory(15)
node1.right = Node.factory(35)
node2.assign(node1)
self.assertEqual(25, node2.value)
self.assertEqual(15, node2.left.value)
self.assertEqual(35, node2.right.value)
示例3: test_tree_multi_level_insertion
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_tree_multi_level_insertion(self):
tree = Tree()
tree.insert(Node.factory(12))
tree.insert(Node.factory(12))
tree.insert(Node.factory(10))
tree.insert(Node.factory(11))
tree.insert(Node.factory(1))
tree.insert(Node.factory(100))
self.assertEqual(12, tree.root_node.value)
self.assertEqual(100, tree.root_node.right.value)
self.assertEqual(10, tree.root_node.left.value)
self.assertEqual(11, tree.root_node.left.right.value)
self.assertEqual(1, tree.root_node.left.left.value)
示例4: test_deletion_leaf_node
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_deletion_leaf_node(self):
tree = Tree()
tree.insert(Node.factory(12))
tree.insert(Node.factory(10))
tree.insert(Node.factory(11))
tree.insert(Node.factory(1))
tree.insert(Node.factory(100))
tree.delete(Node.factory(1))
self.assertTrue(tree.search(Node.factory(12)))
self.assertTrue(tree.search(Node.factory(10)))
self.assertTrue(tree.search(Node.factory(11)))
self.assertFalse(tree.search(Node.factory(1)))
self.assertTrue(tree.search(Node.factory(100)))
self.assertEqual(12, tree.root_node.value)
self.assertEqual(100, tree.root_node.right.value)
self.assertEqual(10, tree.root_node.left.value)
self.assertEqual(11, tree.root_node.left.right.value)
self.assertEqual(None, tree.root_node.left.left.value)
self.assertFalse(tree.root_node.left.left.value == 1)
示例5: test_tree_search
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_tree_search(self):
tree = Tree()
tree.insert(Node.factory(12))
tree.insert(Node.factory(12))
tree.insert(Node.factory(10))
tree.insert(Node.factory(11))
tree.insert(Node.factory(1))
tree.insert(Node.factory(100))
self.assertTrue(tree.search(Node.factory(12)))
self.assertTrue(tree.search(Node.factory(10)))
self.assertTrue(tree.search(Node.factory(11)))
self.assertTrue(tree.search(Node.factory(1)))
self.assertTrue(tree.search(Node.factory(100)))
self.assertFalse(tree.search(Node.factory(None)))
self.assertFalse(tree.search(Node.factory(123)))
self.assertFalse(tree.search(Node.factory(0)))
self.assertFalse(tree.search(Node.factory(-01)))
self.assertFalse(tree.search(Node.factory(1001)))
示例6: test_deletion_node_with_two_children
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_deletion_node_with_two_children(self):
tree = Tree()
tree.insert(Node.factory(12))
tree.insert(Node.factory(10))
tree.insert(Node.factory(11))
tree.insert(Node.factory(1))
tree.insert(Node.factory(100))
tree.insert(Node.factory(99))
tree.delete(Node.factory(10))
self.assertTrue(tree.search(Node.factory(12)))
self.assertFalse(tree.search(Node.factory(10)))
self.assertTrue(tree.search(Node.factory(11)))
self.assertTrue(tree.search(Node.factory(1)))
self.assertTrue(tree.search(Node.factory(100)))
self.assertTrue(tree.search(Node.factory(99)))
self.assertEqual(1, tree.root_node.left.value)
self.assertEqual(11, tree.root_node.left.right.value)
示例7: __init__
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def __init__(self, file_path):
self.tree = Tree()
with open(file_path) as f:
for line in f:
for word in line.split():
self.tree.insert(Node.factory(WordWrapper(word)))
示例8: test_node_factory
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_node_factory(self):
node = Node.factory(12)
self.assertEqual(12, node.value)
self.assertIsNone(node.left.value)
self.assertIsNone(node.right.value)
示例9: test_node_factory_none_case
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import factory [as 别名]
def test_node_factory_none_case(self):
self.assertIsNone(Node.factory(None).value)
self.assertIsNone(Node.factory(None).left.value)
self.assertIsNone(Node.factory(None).right.value)