Пример #1
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 = String.empty
            else:
                self._generator = String.cons
                self._generator_args = {'tail': String(args[0][:-1]), 'head': Char((args[0][-1]))}
        else:
            Sort.__init__(self, **kwargs)
Пример #2
0
def test_generator():
    assert String.empty()._generator == String.empty
    assert String.cons(tail=String.empty(),
                       head=Char('a'))._generator == String.cons
Пример #3
0
def test_pop():
    assert String('abc').pop() == (String('ab'), Char('c'))
    assert String([]).pop() == (String.empty(), String.empty())
Пример #4
0
def test_constructor():
    assert String('') == String.empty()
    assert String('ab') == String.cons(tail=String.cons(tail=String.empty(),
                                                        head=Char('a')),
                                       head=Char('b'))
Пример #5
0
def test_constructor():
    assert Char('a') == Char.char(Nat(97))
Пример #6
0
def test_generator():
    assert Char.char(Nat(10))._generator == Char.char
Пример #7
0
def test_str_():
    assert Char('a').__str__() == 'Char(a)'