示例#1
0
def test_isValidBST_Dup():
    one = node.Node(1)
    two = node.Node(1, one)

    solution = is_valid_bst.Solution()
    isValid = solution.isValidBST(two)
    assert isValid == False
示例#2
0
def test_isValidBST_True():
    three = node.Node(3)
    one = node.Node(1)
    two = node.Node(2, one, three)

    solution = is_valid_bst.Solution()
    isValid = solution.isValidBST(two)
    assert isValid == True
def test_sym_tree_3():
    three = node.Node(3)
    two = node.Node(2)
    one = node.Node(1, two, three)

    solution = isSymetricTree.Solution()
    result = solution.isSymetricTree(one)
    assert result == False
def test_sum_right_child():
    nine = node.Node(9)
    four = node.Node(4, None, nine)

    solution = sumRootToLeaf.Solution()
    result = solution.sumRootToLeaf(four)

    assert result == 49
示例#5
0
def test_isValidBST_Neg():
    forty = node.Node(-45)
    twenty = node.Node(25, forty)
    thirty = node.Node(38, twenty)
    eight = node.Node(-80, None, thirty)

    solution = is_valid_bst.Solution()
    isValid = solution.isValidBST(eight)
    assert isValid == True
示例#6
0
def test_find_same_value():
    thirteen = node.Node(13)
    twenty = node.Node(20)
    five = node.Node(5)
    fifteen = node.Node(15, thirteen, twenty)
    ten = node.Node(10, five, fifteen)

    solution = closestValueBST.Solution()
    result = solution.findClosestValue(ten, 13)
    assert result == 13
示例#7
0
def test_find_closest_value():
    eleven = node.Node(11)
    twenty = node.Node(20)
    five = node.Node(5)
    fifteen = node.Node(15, eleven, twenty)
    ten = node.Node(10, five, fifteen)

    solution = closestValueBST.Solution()
    result = solution.findClosestValue(ten, 13)
    assert result == 15
示例#8
0
def test_isValidBST_False():
    three = node.Node(3)
    six = node.Node(6)
    one = node.Node(1)
    four = node.Node(4, three, six)
    root = node.Node(5, one, four)

    solution = is_valid_bst.Solution()
    isValid = solution.isValidBST(root)
    assert isValid == False
def test_sum_two():
    zero = node.Node(8)
    nine = node.Node(9)
    four = node.Node(4, nine, zero)


    solution = sumRootToLeaf.Solution()
    result = solution.sumRootToLeaf(four)

    assert result == 97
def test_sym_tree_2():
    three = node.Node(3)
    three_2 = node.Node(3)
    two = node.Node(2, three)
    two_2 = node.Node(2, None, three_2)
    one = node.Node(1, two, two_2)

    solution = isSymetricTree.Solution()
    result = solution.isSymetricTree(one)
    assert result == True
def test_not_asymetry():
    three = node.Node(3)
    three_2 = node.Node(3)
    two = node.Node(2, None, three)
    two_2 = node.Node(2, None, three_2)
    one = node.Node(1, two, two_2)

    solution = isSymetricTree.Solution()
    result = solution.isSymetric(one)
    assert result == False
def test_getLevel():
    five = node.Node(5)
    four = node.Node(4)
    two = node.Node(2, four, five)
    three = node.Node(3)
    one = node.Node(1, two, three)

    solution = isSymetricTree.Solution()
    result = solution.getLevel(one, 0, {})
    assert result == {0:[two, three], 1: [four,five, None, None], 2: [None, None, None, None]}
示例#13
0
def test_isValidBST_Null():
    six = node.Node(6)
    twenty = node.Node(20)
    five = node.Node(5)
    fifteen = node.Node(15, six, twenty)
    ten = node.Node(10, five, fifteen)

    solution = is_valid_bst.Solution()
    isValid = solution.isValidBST(ten)
    assert isValid == False
def test_asymetry():
    five = node.Node(5)
    four = node.Node(4)
    two = node.Node(2, four, five)
    three = node.Node(3)
    one = node.Node(1, two, three)

    solution = isSymetricTree.Solution()
    result = solution.isSymetric(one)
    assert result == False
def test_sum_right():
    one = node.Node(1)
    five = node.Node(5)
    zero = node.Node(0)
    nine = node.Node(9, five, one)
    four = node.Node(4, zero, nine)


    solution = sumRootToLeaf.Solution()
    result = solution.sumRootToLeaf(four)

    assert result == 1026
def test_sum_root():
    four = node.Node(4)

    solution = sumRootToLeaf.Solution()
    result = solution.sumRootToLeaf(four)

    assert result == 4
示例#17
0
def test_find_closest_value_left_right():
    four = node.Node(4)
    eight = node.Node(8)
    one = node.Node(1, None, four)
    eleven = node.Node(11)
    twenty = node.Node(20)
    five = node.Node(5, one, eight)
    fifteen = node.Node(15, eleven, twenty)
    ten = node.Node(10, five, fifteen)

    solution = closestValueBST.Solution()
    result = solution.findClosestValue(ten, 2)
    assert result == 1
from Tree import Inorder
from library import node

five = node.Node(5)
four = node.Node(4)
two = node.Node(2, four, five)
three = node.Node(3)
one = node.Node(1, two, three)

result = Inorder.inorder(one)
assert [4,2,5,1,3] == result

def test_asymetryTrue():
    eight = node.Node(8)
    eight_2 = node.Node(8)
    seven = node.Node(7)
    seven_2 = node.Node(7)
    six = node.Node(6)
    six_2 = node.Node(6)
    five = node.Node(5)
    five_2 = node.Node(5)
    three = node.Node(3, eight, seven)
    three_2 = node.Node(3, seven_2, eight_2)
    four = node.Node(4, six, five)
    four_2 = node.Node(4, five_2, six_2)
    two = node.Node(2, three, four)
    two_2 = node.Node(2, four_2, three_2)
    one = node.Node(1, two, two_2)

    solution = isSymetricTree.Solution()
    result = solution.isSymetric(one)
    assert result == True