示例#1
0
def test_add_():
    assert List([]) + List([]) == List.empty()
    assert List([]) + List([1]) == List([1])
    assert List([1]) + List([]) == List([1])
    assert List([-1]) + List([0]) == List.cons(tail=List.cons(
        tail=List.empty(), head=Z(-1)),
                                               head=Z(0))

    assert List([-1]) + List([0, 1]) == List.cons(tail=List.cons(
        tail=List.cons(tail=List.empty(), head=Z(-1)), head=Z(0)),
                                                  head=Z(1))
示例#2
0
    def __init__(self, *args, **kwargs):
        if(len(args) == 1) and isinstance(args[0], Sequence):
            Sort.__init__(self)

            if len(args[0]) == 0:
                self._generator = List.empty
            else:
                self._generator = List.cons
                self._generator_args = {'tail': List(args[0][:-1]), 'head': Z(args[0][-1])}
        else:
            Sort.__init__(self, **kwargs)
示例#3
0
def test_constructor():
    assert Map({}) == Map.empty()
    assert Map({1: 1}) == Map.add(my_map=Map.empty(), key=Z(1), value=Z(1))
    assert Map({
        1: 1,
        -2: -2
    }) == Map.add(my_map=Map.add(my_map=Map.empty(), key=Z(-2), value=Z(-2)),
                  key=Z(1),
                  value=Z(1))
示例#4
0
def test_get_value():
    my_map = Map({1: 1, -2: -2, 0: 0})
    assert my_map.get_value(Z(1)) == Z(1)
    assert my_map.get_value(Z(-2)) == Z(-2)
    assert my_map.get_value(Z(-3)) == Map.empty()
示例#5
0
def test_constructor():
    assert List([]) == List.empty()
    assert List([-1, 0, 1]) == List.cons(tail=List.cons(tail=List.cons(
        tail=List.empty(), head=Z(-1)),
                                                        head=Z(0)),
                                         head=Z(1))
示例#6
0
def test_pop():
    assert List([-1, 0, 1]).pop() == (List([-1, 0]), Z(1))
    assert List([]).pop() == (List.empty(), List.empty())