license import { iteratorFromConcatenatedFunction } from './lazy_iterator' ; import { PrefetchIterator } from './lazy_iterator' ; import { TestIntegerIterator } from './lazy_iterator_test' ; describe ( 'PrefetchIterator' , ( ) => { it ( 'fetches a stream completely (stream size < buffer size)' , async ( ) => { const prefetchIterator = new PrefetchIterator ( new TestIntegerIterator ( ) , 500 ) ; const expectedResult = [ ] ; for ( let j = 0 ; j < 100 ; j ++ ) { expectedResult [ j ] = j ; } const result = await prefetchIterator . toArray ( ) ; expect ( result ) . toEqual ( expectedResult ) ; } ) ; it ( 'fetches a chained stream completely (stream size < buffer size)' , async ( ) => { const baseIterator = iteratorFromConcatenatedFunction ( ( ) => ( { value : new TestIntegerIterator ( ) , done : false } ) , 3 ) ; const prefetchIterator = new PrefetchIterator ( baseIterator , 500 ) ; const expectedResult = [ ] ; for ( let i = 0 ; i < 3 ; i ++ ) { for ( let j = 0 ; j < 100 ; j ++ ) { expectedResult [ i * 100 + j ] = j ; } } const result = await prefetchIterator . toArray ( ) ; expect ( result ) . toEqual ( expectedResult ) ; } ) ; it ( 'fetches a chained stream completely (stream size > buffer size)' , async ( ) => { const baseIterator = iteratorFromConcatenatedFunction ( ( ) => ( { value : new TestIntegerIterator ( ) , done : false } ) , 3 ) ; const prefetchIterator = new PrefetchIterator ( baseIterator , 122 ) ; const expectedResult = [ ] ; for ( let i = 0 ; i < 3 ; i ++ ) { for ( let j = 0 ; j < 100 ; j ++ ) { expectedResult [ i * 100 + j ] = j ; } } const result = await prefetchIterator . toArray ( ) ; expect ( result ) . toEqual ( expectedResult ) ; } ) ; } ) ;