示例#1
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)
示例#2
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)
示例#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)
示例#4
0
 def test_AddKeyValueToEmptyTree(self):
     tree = BST(None)
     testKey = 1
     self.assertFalse(tree.FindNodeByKey(testKey).NodeHasKey)
     self.assertTrue(tree.AddKeyValue(testKey, testKey))
     self.assertTrue(tree.FindNodeByKey(testKey).NodeHasKey)
示例#5
0
 def test_FindNodeByKeyEmpty(self):
     tree = BST(None)
     result = tree.FindNodeByKey(0)
     self.assertTrue(result.Node is None)
示例#6
0
 def test_CountOneNode(self):
     node = BSTNode(1, 1, None)
     tree = BST(node)
     self.assertEqual(tree.Count(), 1)
示例#7
0
 def test_CountEmpty(self):
     tree = BST(None)
     self.assertEqual(tree.Count(), 0)
示例#8
0
 def test_DeleteNodeByKeyEmpty(self):
     tree = BST(None)
     self.assertFalse(tree.DeleteNodeByKey(0))
示例#9
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)
示例#10
0
 def test_DeepAllNodesEmptyPre(self):
     tree = BST(None)
     result = tree.DeepAllNodes(2)
     correct_answer = tuple()
     self.assertEqual(result, correct_answer)
示例#11
0
 def test_WideAllNodesEmpty(self):
     tree = BST(None)
     result = tree.WideAllNodes()
     correct_answer = tuple()
     self.assertEqual(result, correct_answer)