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