license import { ChainedIterator } from './lazy_iterator' ; import { iteratorFromItems } from './lazy_iterator' ; import { TestIntegerIterator } from './lazy_iterator_test' ; const SHORT_STREAM_LENGTH = 15 ; describe ( 'ChainedIterator' , ( ) => { it ( 'produces a single underlying stream as expected' , async ( ) => { const chainedIterator = new ChainedIterator ( iteratorFromItems ( [ new TestIntegerIterator ( SHORT_STREAM_LENGTH ) ] ) ) ; const expectedResult = [ ] ; for ( let i = 0 ; i < 1 ; i ++ ) { for ( let j = 0 ; j < SHORT_STREAM_LENGTH ; j ++ ) { expectedResult [ i * SHORT_STREAM_LENGTH + j ] = j ; } } const result = await chainedIterator . toArrayForTest ( ) ; expect ( result ) . toEqual ( expectedResult ) ; } ) ; it ( 'produces multiple underlying streams as expected' , async ( ) => { const chainedIterator = new ChainedIterator ( iteratorFromItems ( [ new TestIntegerIterator ( SHORT_STREAM_LENGTH ) , new TestIntegerIterator ( SHORT_STREAM_LENGTH ) , new TestIntegerIterator ( SHORT_STREAM_LENGTH ) ] ) ) ; const expectedResult = [ ] ; for ( let i = 0 ; i < 3 ; i ++ ) { for ( let j = 0 ; j < SHORT_STREAM_LENGTH ; j ++ ) { expectedResult [ i * SHORT_STREAM_LENGTH + j ] = j ; } } const result = await chainedIterator . toArrayForTest ( ) ; expect ( result ) . toEqual ( expectedResult ) ; } ) ; } ) ;