Commit 4421a558 authored by Evan Simpson's avatar Evan Simpson

Rename 'total' to 'sequence_length' and make it lazy.

parent 72f599e1
......@@ -12,8 +12,8 @@
##############################################################################
__doc__='''Batch class, for iterating over a sequence in batches
$Id: Batch.py,v 1.8 2002/03/15 16:01:52 chrisw Exp $'''
__version__='$Revision: 1.8 $'[11:-2]
$Id: Batch.py,v 1.9 2002/03/15 21:47:38 evan Exp $'''
__version__='$Revision: 1.9 $'[11:-2]
from ExtensionClass import Base
......@@ -31,12 +31,18 @@ class LazyNextBatch(Base):
parent.end - parent.overlap, 0,
parent.orphan, parent.overlap)
class LazySequenceLength(Base):
def __of__(self, parent):
parent.sequence_length = l = len(parent._sequence)
return l
class Batch(Base):
"""Create a sequence batch"""
__allow_access_to_unprotected_subobjects__ = 1
previous = LazyPrevBatch()
next = LazyNextBatch()
sequence_length = LazySequenceLength()
def __init__(self, sequence, size, start=0, end=0,
orphan=0, overlap=0):
......@@ -54,7 +60,7 @@ class Batch(Base):
0-based index. "length" is the actual number of elements in
the batch.
"total" is the length of the original, unbatched, sequence
"sequence_length" is the length of the original, unbatched, sequence
'''
start = start + 1
......@@ -70,7 +76,6 @@ class Batch(Base):
self.overlap = overlap
self.first = max(start - 1, 0)
self.length = self.end - self.first
self.total = len(sequence)
if self.first == 0:
self.previous = None
......
......@@ -4,11 +4,11 @@ ZTUtils changes
Change information for previous versions can be found in the
file HISTORY.txt.
After Version 1.1.3
After Version 1.1.4
Features Added
- Added useful 'total' attribute to batches.
- Added 'sequence_length' attribute to batches.
Version 1.1.4
......
......@@ -23,7 +23,7 @@ class BatchTests(TestCase):
assert b.next is None
assert b.start == 1, b.start
assert len(b) == b.end == bsize
assert b.total == len(seq)
assert b.sequence_length == len(seq)
for i in seq:
assert b[i] == i, (b[i], i)
neg = -1 - i
......@@ -36,10 +36,10 @@ class BatchTests(TestCase):
assert b.next is None
assert len(b) == bsize
assert b[bsize - 1] == bsize - 1
assert b.total == bsize
assert b.sequence_length == bsize
b = Batch(range(8), 5)
assert len(b) == 5
assert b.total == 8
assert b.sequence_length == 8
assert len(b.next) == 3
def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment