import faker from 'faker' ; import { applyEdit , del , edit , insert , preserve , TagEdit , } from '../aux-format-2' ; param count export function generateRandomEditCases ( count ) { let cases = [ ] as [ string , string , string [ ] , TagEdit [ ] ] [ ] ; for ( let i = 0 ; i < count ; i ++ ) { const startText = faker . lorem . sentence ( ) ; const editCount = faker . random . number ( { min : 1 , max : startText . length , } ) ; let edits = [ ] as TagEdit [ ] ; let strings = [ ] as string [ ] ; let currentText = startText ; for ( let b = 0 ; b < editCount ; b ++ ) { const shouldInsert = faker . random . boolean ( ) ; let tagEdit ; if ( shouldInsert || currentText . length <= 0 ) { const preserveCount = faker . random . number ( { min : 0 , max : currentText . length , } ) ; const newText = faker . lorem . word ( ) ; tagEdit = edit ( { } , preserve ( preserveCount ) , insert ( newText ) ) ; } else { const preserveCount = faker . random . number ( { min : 0 , max : currentText . length - 1 , } ) ; const deleteCount = faker . random . number ( { min : 1 , max : currentText . length - preserveCount , } ) ; tagEdit = edit ( { } , preserve ( preserveCount ) , del ( deleteCount ) ) ; } edits . push ( tagEdit ) ; currentText = applyEdit ( currentText , tagEdit ) ; strings . push ( currentText ) ; } cases . push ( [ startText , currentText , strings , edits ] ) ; } return cases ; } param count export function generateRandomEditParagraphCases ( count ) { let cases = [ ] as [ string , string , string [ ] , TagEdit [ ] ] [ ] ; for ( let i = 0 ; i < count ; i ++ ) { const startText = faker . lorem . paragraph ( 4 ) ; const editCount = faker . random . number ( { min : 1 , max : startText . length , } ) ; let edits = [ ] as TagEdit [ ] ; let strings = [ ] as string [ ] ; let currentText = startText ; for ( let b = 0 ; b < editCount ; b ++ ) { const shouldInsert = faker . random . boolean ( ) ; let tagEdit ; if ( shouldInsert || currentText . length <= 0 ) { const preserveCount = faker . random . number ( { min : 0 , max : currentText . length , } ) ; const newText = faker . lorem . sentence ( ) ; tagEdit = edit ( { } , preserve ( preserveCount ) , insert ( newText ) ) ; } else { const preserveCount = faker . random . number ( { min : 0 , max : currentText . length - 1 , } ) ; const deleteCount = faker . random . number ( { min : 1 , max : currentText . length - preserveCount , } ) ; tagEdit = edit ( { } , preserve ( preserveCount ) , del ( deleteCount ) ) ; } edits . push ( tagEdit ) ; currentText = applyEdit ( currentText , tagEdit ) ; strings . push ( currentText ) ; } cases . push ( [ startText , currentText , strings , edits ] ) ; } return cases ; }