Ejemplo n.º 1
0
    def test_5NodeWalk(self):
        """ 5 Node Walk - with insert before.

			This test adds three nodes in a row to see if the graph code works
			it also inserts two more nodes before node 2 and node 3.

			It then will walk the tree to see if the it finds all the nodes.
		"""
        node1 = NestedTreeNode(1)
        node2 = NestedTreeNode(2)
        node3 = NestedTreeNode(3)
        node4 = NestedTreeNode(4)
        node5 = NestedTreeNode(5)

        graph = NestedTree()

        # insert the three nodes
        graph.addNodeAfter(node1)
        node1.addNodeAfter(node2)
        node2.addNodeAfter(node3)

        # now insert the two extra nodes
        node2.addNodeBefore(node4)
        node3.addNodeBefore(node5)

        # we are only using the next function for this rest.
        count = 0
        count = graph.walkTree(self.count_function)
        self.assertTrue(count == 5)
Ejemplo n.º 2
0
    def test_addNodes(self):
        """ Add Nodes.

			This test adds three nodes in a row to see if the graph code works.
			This is an exploding test to see if the code works.
		"""
        node1 = NestedTreeNode(1)
        node2 = NestedTreeNode(2)
        node3 = NestedTreeNode(3)

        graph = NestedTree()

        graph.addNodeAfter(node1)
        node1.addNodeAfter(node2)
        node2.addNodeAfter(node3)

        self.assertTrue(graph.hasSibling())
        self.assertTrue(node1.hasSibling())
        self.assertTrue(node2.hasSibling())
Ejemplo n.º 3
0
    def test_3NodeWalk(self):
        """ 3 Node Walk.

			This test adds three nodes in a row to see if the graph code works.

			It then will walk the tree to see if the it finds all the nodes.
		"""
        node1 = NestedTreeNode(1)
        node2 = NestedTreeNode(2)
        node3 = NestedTreeNode(3)

        graph = NestedTree()

        graph.addNodeAfter(node1)
        node1.addNodeAfter(node2)
        node2.addNodeAfter(node3)

        # we are only using the next function for this rest.
        count = 0
        count = graph.walkTree(self.count_function)
        self.assertTrue(count == 3)
Ejemplo n.º 4
0
    def test_OrderedSiblingsListLast(self):
        graph = NestedTree()
        (leaf_node, end_node) = self.build_simple_tree(graph)

        leaf_node.addChildNode(NestedTreeNode(98))
        leaf_node.addChildNode(NestedTreeNode(99))

        # paint the tree.
        painted_list = graph.walkTree(self.all_nodes_level_function,
                                      NestedTreeNode.TREE_WALK_PARENTS_LAST)
        for item in painted_list:
            found = graph.findItemWithColour(
                item[2], NestedTreeNode.TREE_WALK_PARENTS_LAST, True)
            self.assertIsNotNone(found)
            self.assertEqual(found.payload, item[1])
            self.assertEqual(found.colour, item[2])

        # corner case graphs
        nodes = []

        for count in range(1, 6):
            nodes.append(NestedTreeNode(count))

        graph = NestedTree()

        # the empty graph.
        found = graph.findItemWithColour(1, NestedTreeNode.TREE_WALK_NORMAL,
                                         True)
        self.assertIsNone(found)
        found = graph.findItemWithColour(
            1, NestedTreeNode.TREE_WALK_PARENTS_FIRST, True)
        self.assertIsNone(found)
        found = graph.findItemWithColour(1,
                                         NestedTreeNode.TREE_WALK_PARENTS_LAST,
                                         True)
        self.assertIsNone(found)

        # single node
        graph.addNodeAfter(nodes[1])
        # unpainted
        found = graph.findItemWithColour(1, NestedTreeNode.TREE_WALK_NORMAL,
                                         True)
        self.assertIsNone(found)
        found = graph.findItemWithColour(
            1, NestedTreeNode.TREE_WALK_PARENTS_FIRST, True)
        self.assertIsNone(found)
        found = graph.findItemWithColour(1,
                                         NestedTreeNode.TREE_WALK_PARENTS_LAST,
                                         True)
        self.assertIsNone(found)

        # painted
        nodes[1].colour = 1
        found = graph.findItemWithColour(1, NestedTreeNode.TREE_WALK_NORMAL,
                                         True)
        self.assertIsNotNone(found)
        found = graph.findItemWithColour(
            1, NestedTreeNode.TREE_WALK_PARENTS_FIRST, True)
        self.assertIsNotNone(found)
        found = graph.findItemWithColour(1,
                                         NestedTreeNode.TREE_WALK_PARENTS_LAST,
                                         True)
        self.assertIsNotNone(found)

        # One child - only need to test painted.
        graph = NestedTree()
        graph.colour = 99  # colour the route or it won't search down.
        graph.addChildNode(nodes[1])
        found = graph.findItemWithColour(1, NestedTreeNode.TREE_WALK_NORMAL,
                                         True)
        self.assertIsNotNone(found)
        found = graph.findItemWithColour(
            1, NestedTreeNode.TREE_WALK_PARENTS_FIRST, True)
        self.assertIsNotNone(found)
        found = graph.findItemWithColour(1,
                                         NestedTreeNode.TREE_WALK_PARENTS_LAST,
                                         True)
        self.assertIsNotNone(found)

        graph.addChildNode(nodes[2])
        graph.addChildNode(nodes[3])

        painted_list = graph.walkTree(self.all_nodes_level_function,
                                      NestedTreeNode.TREE_WALK_NORMAL)
        for item in range(1, 4):
            found = graph.findItemWithColour(item,
                                             NestedTreeNode.TREE_WALK_NORMAL,
                                             True)
            self.assertIsNotNone(found)

        painted_list = graph.walkTree(self.all_nodes_level_function,
                                      NestedTreeNode.TREE_WALK_PARENTS_FIRST)
        for item in range(1, 4):
            found = graph.findItemWithColour(
                1, NestedTreeNode.TREE_WALK_PARENTS_FIRST, True)
            self.assertIsNotNone(found)

        painted_list = graph.walkTree(self.all_nodes_level_function,
                                      NestedTreeNode.TREE_WALK_PARENTS_LAST)
        for item in range(1, 4):
            found = graph.findItemWithColour(
                1, NestedTreeNode.TREE_WALK_PARENTS_FIRST, True)
            self.assertIsNotNone(found)