def sort(self): data = range(10) random.choice(data) l = LazyList(data) l.sort() data.sort() Assert(l) == data
def insert(self): data = self._genrange(10) l = LazyList(data) l.insert(5, 'foobar') Assert(l[5]) == 'foobar' Assert(l.exhausted) == False l.insert(-3, 'spam') Assert(l[-4]) == 'spam'
def remove(self): data = range(10) l = LazyList(self._genrange(10)) data.remove(2) l.remove(2) Assert(l.exhausted) == False Assert(l) == data with Assert.raises(ValueError): l.remove('foo')
def len(self): Assert(len(LazyList(range(10)))) == 10 l = LazyList([]) Assert(len(l)) == 0 l.append(1) Assert(len(l)) == 1 l.extend([2, 3]) Assert(len(l)) == 3 l.pop() Assert(len(l)) == 2 del l[1] Assert(len(l)) == 1
def index(self): l = LazyList(self._genrange(10)) Assert(l.index(5)) == 5 with Assert.raises(ValueError): l.index('foo')
def count(self): l = LazyList(['a', 'b', 'c', 'a']) tests = [('a', 2), ('b', 1), ('c', 1)] for test, result in tests: Assert(l.count(test)) == result
def reverse(self): data = range(10) l = LazyList(reversed(data)) l.reverse() Assert(l) == data
def pop(self): data = xrange(10) l = LazyList(data) Assert(l.pop()) == 9 Assert(l.pop(0)) == 0
def extend(self): data = self._genrange(10) l = LazyList(data) l.extend(range(10, 20)) Assert(l.exhausted) == False Assert(l) == range(10) + range(10, 20)
def append(self): data = self._genrange(10) l = LazyList(data) l.append(10) Assert(l.exhausted) == False Assert(l) == range(11)
def factory(self): foo = LazyList.factory(xrange) Assert(foo(10).__class__).is_(LazyList) Assert(foo(10)) == range(10)