Beispiel #1
0
 def sort(self):
     data = range(10)
     random.choice(data)
     l = LazyList(data)
     l.sort()
     data.sort()
     Assert(l) == data
Beispiel #2
0
 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'
Beispiel #3
0
    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')
Beispiel #4
0
    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
Beispiel #5
0
 def index(self):
     l = LazyList(self._genrange(10))
     Assert(l.index(5)) == 5
     with Assert.raises(ValueError):
         l.index('foo')
Beispiel #6
0
 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
Beispiel #7
0
 def reverse(self):
     data = range(10)
     l = LazyList(reversed(data))
     l.reverse()
     Assert(l) == data
Beispiel #8
0
 def pop(self):
     data = xrange(10)
     l = LazyList(data)
     Assert(l.pop()) == 9
     Assert(l.pop(0)) == 0
Beispiel #9
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)
Beispiel #10
0
 def append(self):
     data = self._genrange(10)
     l = LazyList(data)
     l.append(10)
     Assert(l.exhausted) == False
     Assert(l) == range(11)
Beispiel #11
0
 def factory(self):
     foo = LazyList.factory(xrange)
     Assert(foo(10).__class__).is_(LazyList)
     Assert(foo(10)) == range(10)
Beispiel #12
0
 def index(self):
     l = LazyList(self._genrange(10))
     Assert(l.index(5)) == 5
     with Assert.raises(ValueError):
         l.index('foo')
Beispiel #13
0
 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
Beispiel #14
0
 def reverse(self):
     data = range(10)
     l = LazyList(reversed(data))
     l.reverse()
     Assert(l) == data
Beispiel #15
0
 def pop(self):
     data = xrange(10)
     l = LazyList(data)
     Assert(l.pop()) == 9
     Assert(l.pop(0)) == 0