コード例 #1
0
    def it_can_construct_from_an_ordered_sequence(self):
        bst = _BinarySearchTree.from_ordered_sequence(range(10))

        def in_order(node):
            """
            Traverse the tree depth first to produce a list of its values,
            in order.
            """
            result = []
            if node is None:
                return result
            result.extend(in_order(node._lesser))
            result.append(node.value)
            result.extend(in_order(node._greater))
            return result

        assert bst.value == 9
        assert bst._lesser.value == 4
        assert bst._greater is None
        assert in_order(bst) == list(range(10))
コード例 #2
0
 def max_fixture(self, request):
     seq, predicate, expected_value = request.param
     bst = _BinarySearchTree.from_ordered_sequence(seq)
     return bst, predicate, expected_value