Example #1
0
 def test_FindNodeByKeyOneNode(self):
     testKey = 0
     node = BSTNode(testKey, testKey, None)
     tree = BST(node)
     result = tree.FindNodeByKey(testKey)
     self.assertTrue(result.Node is node)
     self.assertTrue(result.NodeHasKey is True)
Example #2
0
 def test_DeleteNodeByKeyOneNode(self):
     testKey = 0
     tree = BST(BSTNode(testKey, testKey, None))
     self.assertTrue(tree.FindNodeByKey(testKey).NodeHasKey)
     self.assertTrue(tree.DeleteNodeByKey(testKey))
     self.assertFalse(tree.FindNodeByKey(testKey).NodeHasKey)
     self.assertTrue(tree.Root is None)
Example #3
0
    def getTestTree(self):
        nodes = []

        for i in range(15):
            nodes.append(BSTNode(i, i, None))

        nodes[1].LeftChild = nodes[0]
        nodes[1].RightChild = nodes[2]
        nodes[0].Parent = nodes[1]
        nodes[2].Parent = nodes[1]

        nodes[5].LeftChild = nodes[4]
        nodes[5].RightChild = nodes[6]
        nodes[4].Parent = nodes[5]
        nodes[6].Parent = nodes[5]

        nodes[3].LeftChild = nodes[1]
        nodes[3].RightChild = nodes[5]
        nodes[1].Parent = nodes[3]
        nodes[5].Parent = nodes[3]

        nodes[9].LeftChild = nodes[8]
        nodes[9].RightChild = nodes[10]
        nodes[8].Parent = nodes[9]
        nodes[10].Parent = nodes[9]

        nodes[13].LeftChild = nodes[12]
        nodes[13].RightChild = nodes[14]
        nodes[12].Parent = nodes[13]
        nodes[14].Parent = nodes[13]

        nodes[11].LeftChild = nodes[9]
        nodes[11].RightChild = nodes[13]
        nodes[9].Parent = nodes[11]
        nodes[13].Parent = nodes[11]

        nodes[7].LeftChild = nodes[3]
        nodes[7].RightChild = nodes[11]
        nodes[3].Parent = nodes[7]
        nodes[11].Parent = nodes[7]

        tree = BST(nodes[7])

        return (tree, nodes)
Example #4
0
 def test_CountOneNode(self):
     node = BSTNode(1, 1, None)
     tree = BST(node)
     self.assertEqual(tree.Count(), 1)
Example #5
0
 def test_DeepAllNodesOneNodeIn(self):
     node = BSTNode(1, 1, None)
     tree = BST(node)
     result = tree.DeepAllNodes(0)
     correct_answer = tuple([node])
     self.assertEqual(result, correct_answer)