def main():
    #      3
    #    2   5
    #  1    4 6
    tree = BinaryTreeNode(3)
    tree.left = BinaryTreeNode(2)
    tree.left.left = BinaryTreeNode(1)
    tree.right = BinaryTreeNode(5)
    tree.right.left = BinaryTreeNode(4)
    tree.right.right = BinaryTreeNode(6)
    # should output True.
    assert is_binary_tree_BST(tree) == True
    print(is_binary_tree_BST(tree))
    #      10
    #    2   5
    #  1    4 6
    tree.data = 10
    # should output False.
    assert not is_binary_tree_BST(tree)
    print(is_binary_tree_BST(tree))
    # should output True.
    assert is_binary_tree_BST(None) == True
    print(is_binary_tree_BST(None))
Beispiel #2
0
def main():
    #      3
    #    2   5
    #  1    4 6
    tree = BinaryTreeNode(3)
    tree.left = BinaryTreeNode(2)
    tree.left.left = BinaryTreeNode(1)
    tree.right = BinaryTreeNode(5)
    tree.right.left = BinaryTreeNode(4)
    tree.right.right = BinaryTreeNode(6)
    # should output True.
    assert is_binary_tree_BST(tree) == True
    print(is_binary_tree_BST(tree))
    #      10
    #    2   5
    #  1    4 6
    tree.data = 10
    # should output False.
    assert not is_binary_tree_BST(tree)
    print(is_binary_tree_BST(tree))
    # should output True.
    assert is_binary_tree_BST(None) == True
    print(is_binary_tree_BST(None))
def test():
    #      3
    #    2   5
    #  1    4 6
    tree = BinaryTreeNode(3)
    tree.left = BinaryTreeNode(2)
    tree.left.left = BinaryTreeNode(1)
    tree.right = BinaryTreeNode(5)
    tree.right.left = BinaryTreeNode(4)
    tree.right.right = BinaryTreeNode(6)
    # should output True.
    assert is_binary_tree_bst(tree)
    assert is_binary_tree_bst_alternative(tree)
    #      10
    #    2   5
    #  1    4 6
    tree.data = 10
    # should output False.
    assert not is_binary_tree_bst(tree)
    assert not is_binary_tree_bst_alternative(tree)
    # should output True.
    assert is_binary_tree_bst(None)
    assert is_binary_tree_bst_alternative(None)
def test():
    #      3
    #    2   5
    #  1    4 6
    tree = BinaryTreeNode(3)
    tree.left = BinaryTreeNode(2)
    tree.left.left = BinaryTreeNode(1)
    tree.right = BinaryTreeNode(5)
    tree.right.left = BinaryTreeNode(4)
    tree.right.right = BinaryTreeNode(6)
    # should output True.
    assert is_binary_tree_bst(tree)
    assert is_binary_tree_bst_alternative(tree)
    #      10
    #    2   5
    #  1    4 6
    tree.data = 10
    # should output False.
    assert not is_binary_tree_bst(tree)
    assert not is_binary_tree_bst_alternative(tree)
    # should output True.
    assert is_binary_tree_bst(None)
    assert is_binary_tree_bst_alternative(None)
Beispiel #5
0
            if not front.lower <= front.node.data <= front.upper:
                return False
            bfs_queue += [
                QueueEntry(front.node.left, front.lower, front.node.data),
                QueueEntry(front.node.right, front.node.data, front.upper),
            ]
    return True


#      3
#    2   5
#  1    4 6
tree = BinaryTreeNode(3)
tree.left = BinaryTreeNode(2)
tree.left.left = BinaryTreeNode(1)
tree.right = BinaryTreeNode(5)
tree.right.left = BinaryTreeNode(4)
tree.right.right = BinaryTreeNode(6)
# should output True.
assert is_binary_tree_bst(tree)
print(is_binary_tree_bst(tree))
#      10
#    2   5
#  1    4 6
tree.data = 10
# should output False.
assert not is_binary_tree_bst(tree)
print(is_binary_tree_bst(tree))
# should output True.
assert is_binary_tree_bst(None)
print(is_binary_tree_bst(None))