def METHOD_NAME(self, xs, ys, test_id, limit=None):
    # check that an iterator xs matches the expected results ys,
    # up to a given limit.
    if limit is not None:
        xs = itertools.islice(xs, limit)
        ys = itertools.islice(ys, limit)
    sentinel = object()
    pairs = itertools.izip_longest(xs, ys, fillvalue=sentinel)
    for i, (x, y) in enumerate(pairs):
        if x == y:
            continue
        elif x == sentinel:
            self.fail('{}: iterator ended unexpectedly '
                      'at position {}; expected {}'.format(test_id, i, y))
        elif y == sentinel:
            self.fail('{}: unexpected excess element {} at '
                      'position {}'.format(test_id, x, i))
        else:
            self.fail('{}: wrong element at position {};'
                      'expected {}, got {}'.format(test_id, i, y, x))