import { expect } from "chai" ; import { count , filter , first , generate , map , max , pipe , sensor } from "../index" ; describe ( "readme" , ( ) => { it ( "quick example" , ( ) => { const c1 = count ( ) ; const c2 = count ( ) ; const c3 = count ( ) ; const m1 = max ( row => row . value ) ; const p1 = pipe ( sensor ( c1 ) , filter ( n => n <= 0.5 ) , sensor ( c2 ) , map ( ( n , idx ) => ( { index : idx , value : n } ) ) , filter ( row => row . index % 2 === 0 ) , sensor ( c3 ) , sensor ( m1 ) , first ( 3 ) ) ; console . log ( `Counts: ${ c1 . peek ( ) }, ${ c2 . peek ( ) }, ${ c3 . peek ( ) }` ) ; const outIterable = p1 ( generate ( Math . random , 1000 ) ) ; console . log ( `Counts: ${ c1 . peek ( ) }, ${ c2 . peek ( ) }, ${ c3 . peek ( ) }` ) ; console . log ( JSON . stringify ( [ ... outIterable ] ) ) ; console . log ( `Counts: ${ c1 . peek ( ) }, ${ c2 . peek ( ) }, ${ c3 . peek ( ) }, ${ m1 . peek ( ) }` ) ; const outArray = [ ... p1 ( [ 0.7 , 0.5 , 0.4 , 0.8 , 0.3 , 1 ] ) ] ; console . log ( JSON . stringify ( outArray ) ) ; console . log ( `Counts: ${ c1 . peek ( ) }, ${ c2 . peek ( ) }, ${ c3 . peek ( ) }, ${ m1 . peek ( ) }` ) ; expect ( outArray . length ) . to . equal ( 2 ) ; for ( const row of p1 ( generate ( Math . random , 1000000 ) ) ) { console . log ( `${ row . index }: ${ c1 . peek ( ) }, ${ c2 . peek ( ) }, ${ c3 . peek ( ) }, ${ m1 . peek ( ) }` ) ; } } ) ; it ( "interesting example" , ( ) => { const c1 = count ( ) ; const c2 = count ( ) ; const c3 = count ( ) ; const m1 = max ( row => row . value ) ; const p1 = pipe ( sensor ( c1 ) , filter ( n => n <= 0.5 ) , sensor ( c2 ) , map ( ( n , idx ) => ( { index : idx , value : n } ) ) , filter ( row => row . index % 2 === 0 ) , sensor ( c3 ) , sensor ( m1 ) ) ; for ( const row of p1 ( generate ( Math . random , 1000000 ) ) ) { if ( row . index % 100000 === 0 ) { console . log ( `${ row . index }: ${ c1 . peek ( ) }, ${ c2 . peek ( ) }, ${ c3 . peek ( ) }, ${ m1 . peek ( ) }` ) ; } } } ) ; } ) ;