コード例 #1
0
def test_random_node__simple():
    values = [1, 2, 3, 4, 5, 6, 7, 8]
    root = to_bst(values)
    tree = RandomTree(root)

    for index in range(0, len(values)):
        with patch('exercises.trees_graphs.random_node.randrange', return_value=index):  # noqa: E501
            found = tree.get_random_node()
            # broke encapsulation here, difficult to test
            assert list(tree._nodes)[index] == found
コード例 #2
0
ファイル: test_minimal_tree.py プロジェクト: emptyset/ctci
def test_to_bst__many_odd():
    array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    root = to_bst(array)
    traversal = root.traverse_inorder()
    assert list(map(lambda n: n.value, traversal)) == array
    assert root.height <= maximum_height(len(array))
コード例 #3
0
ファイル: test_minimal_tree.py プロジェクト: emptyset/ctci
def test_to_bst__one():
    array = [1]
    traversal = to_bst(array).traverse_inorder()
    assert list(map(lambda n: n.value, traversal)) == array
コード例 #4
0
ファイル: test_minimal_tree.py プロジェクト: emptyset/ctci
def test_to_bst__nothing():
    assert to_bst([]) is None
コード例 #5
0
ファイル: test_validate_bst.py プロジェクト: emptyset/ctci
def test_is_bst__complex():
    root = to_bst([1, 2, 3, 4, 5, 6, 7, 8])
    assert is_bst(root)
コード例 #6
0
def test_to_linked_lists__one():
    lists = to_linked_lists(to_bst([9000]))
    assert len(lists) == 1
    assert len(lists[0]) == 1
    assert lists[0][0] == 9000
コード例 #7
0
def test_to_linked_lists__many():
    lists = to_linked_lists(to_bst([1, 2, 3, 4, 5, 6, 7, 8]))
    assert len(lists) == 4

    assert [1, 1, 2, 4] == sorted([len(li) for li in lists])