import fs from 'fs-extra' ; import path from 'path' ; export const workspaceRootDir = __dirname ; export const testRootDior = path . resolve ( ) ; param p returns export const locateFixtures = ( ... p ) : string => path . resolve ( testRootDior , '__test__/fixtures' , ... p ) ; param p returns export const loadFixtures = ( ... p ) : string => fs . readFileSync ( locateFixtures ( ... p ) , 'utf-8' ) ; param filepaths export const unlinkSync = ( ... filepaths ) : void => { for ( let filepath of filepaths ) { if ( filepath == null ) continue ; if ( ! Array . isArray ( filepath ) ) filepath = [ filepath ] ; for ( const p of filepath ) if ( fs . existsSync ( p ) ) fs . unlinkSync ( p ) ; } } ; param start param end returns export function range ( start , end ) { const _size = end - start ; const nums = new Array ( _size ) ; for ( let i = 0 ; i < end ; ++ i ) nums [ i ] = start + i ; return nums ; } param max returns export const randomInt = ( max ) : number => Math . ceil ( Math . random ( ) * max ) ; export function createReader ( content ) { const integerRegex = /-?\d+/g ; const lines = content . split ( /\n/g ) ; return { readIntegersOfLine } ; /**
     * Read integers.
     */ function readIntegersOfLine ( ) { const line = nextNonBlankLine ( ) ! ; const m = line . match ( integerRegex ) ; if ( m == null ) return [ ] ; return m . map ( x => Number ( x ) ) ; } returns function nextNonBlankLine ( ) { while ( true ) { const line = lines . shift ( ) ; if ( line === undefined ) return undefined ; if ( /\S/ . test ( line ) ) return line ; } } }