/** * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ import Iterator from '../iterator' function iteratorToArray(it: Iterator): T[] { const ret = []; for (let v = it.move(); !it.done; v = it.move()) ret[ret.length] = v; return ret; } describe('basic iterators', () => { function check(name: string, iter: Iterator, 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]); });