1234567891011121314151617181920212223242526 |
- /**
- * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @author David Sehnal <david.sehnal@gmail.com>
- */
- import Iterator from '../iterator'
- function iteratorToArray<T>(it: Iterator<T>): T[] {
- const ret = [];
- for (let v = it.move(); !it.done; v = it.move()) ret[ret.length] = v;
- return ret;
- }
- describe('basic iterators', () => {
- function check<T>(name: string, iter: Iterator<T>, expected: T[]) {
- it(name, () => {
- expect(iteratorToArray(iter)).toEqual(expected);
- });
- }
- check('empty', Iterator.Empty, []);
- check('singleton', Iterator.Value(10), [10]);
- check('array', Iterator.Array([1, 2, 3]), [1, 2, 3]);
- check('range', Iterator.Range(0, 3), [0, 1, 2, 3]);
- });
|