Example #1
0
    def test_empty_iter(self):
        seq1 = []
        seq2 = RandomAccessIterator(iter(seq1), 7)
        assert seq2[0:3] == seq1[0:3]

        try:
            seq2.next()
            self.fail('StopIteration expected')
        except StopIteration:
            pass
Example #2
0
    def test_short_iter(self):
        seq1 = range(3)
        seq2 = RandomAccessIterator(iter(seq1), 7)
        assert seq1[0] == seq1[0]
        assert seq2[0:3] == seq1[0:3]
        assert seq2[:3] == seq1[:3]

        assert seq1[0] == seq1[0]
        assert seq2[0:3] == seq1[0:3]
        assert seq2[:3] == seq1[:3]

        first = seq2.next()
        assert first == 0
        assert seq2[0:4] == seq1[0:4]

        item = seq2.next()
        assert item == 1
        assert seq2[0:4] == seq1[0:4]

        item = seq2.next()
        assert item == 2
        assert seq2[0:4] == seq1[0:4]

        try:
            item = seq2.next()
            self.fail('StopIteration expected')
        except StopIteration:
            pass

        seq1 = range(2)
        seq2 = RandomAccessIterator(iter(seq1), 7)
        assert seq1[0] == seq1[0]
        assert seq2[0:3] == seq1[0:3]
        assert seq2[:3] == seq1[:3]
Example #3
0
    def test_next_items(self):
        seq1 = range(10)
        seq2 = RandomAccessIterator(iter(seq1), 7)
        assert seq1[0] == seq1[0]
        assert seq2[0:3] == seq1[0:3]
        assert seq2[:3] == seq1[:3]
        assert seq2[2] == seq1[2]

        first = seq2.next()
        assert first == 0
        assert seq2[0:4] == seq1[0:4]

        item = seq2.next()
        assert item == 1
        assert seq2[0:5] == seq1[0:5]

        item = seq2.next()
        assert item == 2
        assert seq2[0:6] == seq1[0:6]

        item = seq2.next()
        assert item == 3
        assert seq2[0:7] == seq1[0:7]

        try:
            seq2[0:8]
            self.fail('IndexError expexted')
        except IndexError:
            pass

        item = seq2.next()
        assert item == 4
        assert seq2[1:8] == seq1[1:8]
        assert seq2[1] == seq1[1]
        try:
            seq2[0]
            self.fail('IndexError expexted')
        except IndexError:
            pass

        item = seq2.next()
        assert item == 5
        assert seq2[2:9] == seq1[2:9]

        try:
            seq2[1:8]
            self.fail('IndexError expexted')
        except IndexError:
            pass

        item = seq2.next()
        assert item == 6
        assert seq2[3:10] == seq1[3:10]

        item = seq2.next()
        assert item == 7
        assert seq2[3:10] == seq1[3:10]
        item = seq2.next()
        assert item == 8
        item = seq2.next()
        assert item == 9
        assert seq2[3:10] == seq1[3:10]