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
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))
def test_to_bst__one(): array = [1] traversal = to_bst(array).traverse_inorder() assert list(map(lambda n: n.value, traversal)) == array
def test_to_bst__nothing(): assert to_bst([]) is None
def test_is_bst__complex(): root = to_bst([1, 2, 3, 4, 5, 6, 7, 8]) assert is_bst(root)
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
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])