Repository navigation
Pu/large tests #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+268
−0
Merged
Pu/large tests #755
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
62bdfea
large random tests
izulin 9d30698
this test fails sometimes
izulin bc3b8f3
removal of unnecessary nulls/undefined in serialization
izulin b4348e2
simplified tests
izulin cbf0092
Remove redundant tests
voodoo11 7745ceb
Merge branch 'develop' into pu/large-tests
izulin 20af2f6
cleanup
izulin 794fd07
restoring old version of a file
izulin f3acafd
columns
izulin 84ce252
large test
izulin faabaa3
moveCells
izulin 4387006
Fix error when moving only part of a range. Handle cycles when moving
voodoo11 d5ce0c6
Restore old data when undo move rows/columns
voodoo11 b81ab28
Batch transformations
voodoo11 dfc5cca
Changelog
voodoo11 bbb20da
Merge branch 'develop' into jk/move-cells-transformer-fix
voodoo11 318dd24
Use ??
voodoo11 dd8f002
Rename method
voodoo11 2c62e23
Update CHANGELOG.md
voodoo11 c75721b
Update CHANGELOG.md
voodoo11 354bf80
Merge branch 'develop' into jk/move-cells-transformer-fix
voodoo11 44546f0
Merge branch 'pu/large-tests' into jk/move-cells-transformer-fix
izulin 0b339b2
.
izulin 5664d14
Merge branch 'develop' into pu/large-tests
izulin 5a00a79
fails
izulin fab3f7e
.
izulin b2a0d2b
Merge branch 'develop' into pu/large-tests
izulin f58cc61
cleanup
izulin 6f511e4
Merge branch 'develop' into pu/large-tests
izulin 743f616
Merge branch 'develop' into pu/large-tests
izulin f85785c
Merge branch 'develop' into pu/large-tests
izulin 8bf1cb0
minor cleanup
izulin 8abfc59
Update CHANGELOG.md
izulin 033bd17
changelog
izulin 9c41eea
Merge branch 'pu/large-tests' of https://github.com/handsontable/hype…
izulin 346d42f
less iterations
izulin d8d1f16
Merge branch 'develop' into pu/large-tests
izulin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| import {HyperFormula} from '../src' | ||
| import {AbsoluteCellRange} from '../src/AbsoluteCellRange' | ||
| import {verifyValues} from './testUtils' | ||
|
|
||
|
|
||
| /** | ||
| * random int from global variable 'state' | ||
| */ | ||
|
|
||
| const getInt = (function() { | ||
| let state = 1 | ||
| return function() { | ||
| state ^= state << 13 | ||
| state ^= state >> 17 | ||
| state ^= state << 5 | ||
| state &= 0x7FFFFFFF | ||
| return state | ||
| } | ||
| })() | ||
|
|
||
| /** | ||
| * random float from global variable 'state' | ||
| */ | ||
| function getFloat(): number { | ||
| return getInt()/0x80000000 | ||
| } | ||
|
|
||
| /** | ||
| * boolean flag for outputing crud operations | ||
| */ | ||
| const outputLog = false | ||
|
|
||
| /** | ||
| * random int in range between min and max | ||
| * | ||
| * @param min | ||
| * @param max | ||
| */ | ||
| function randomInteger(min: number, max: number) { | ||
| return Math.floor(getFloat() * (max - min)) + min | ||
| } | ||
|
|
||
| type Pts = { x: number, y: number } | ||
|
|
||
| type Rectangle = { topleft: Pts, bottomright: Pts } | ||
|
|
||
| /** | ||
| * picks a random range as a subset of rectangle | ||
| * and builds a formula =SUM(range) | ||
| * @param engine | ||
| * @param rect | ||
| */ | ||
| function randomRange(engine: HyperFormula, rect: Rectangle): string { | ||
| const x1 = randomInteger(rect.topleft.x, rect.bottomright.x) | ||
| const x2 = randomInteger(rect.topleft.x, rect.bottomright.x) | ||
| const y1 = randomInteger(rect.topleft.y, rect.bottomright.y) | ||
| const y2 = randomInteger(rect.topleft.y, rect.bottomright.y) | ||
| const startAddress = engine.simpleCellAddressToString({ | ||
| sheet: 0, | ||
| col: Math.min(x1, x2), | ||
| row: Math.min(y1, y2), | ||
| }, 0) | ||
| const endAddress = engine.simpleCellAddressToString({ | ||
| sheet: 0, | ||
| col: Math.max(x1, x2), | ||
| row: Math.max(y1, y2) | ||
| }, 0) | ||
| return '=SUM(' + startAddress + ':' + endAddress + ')' | ||
| } | ||
|
|
||
| function undoRedo(engine: HyperFormula) { | ||
| if(outputLog) { | ||
| console.log('engine.undo()') | ||
| } | ||
| engine.undo() | ||
| if(outputLog) { | ||
| console.log('engine.redo()') | ||
| } | ||
| engine.redo() | ||
| } | ||
|
|
||
| /** | ||
| * Fills a rectangle of cells with random formula sums with a random ranges from another rectangle. | ||
| * @param engine | ||
| * @param rectFormulas | ||
| * @param rectValues | ||
| */ | ||
| function randomSums(engine: HyperFormula, rectFormulas: Rectangle, rectValues: Rectangle) { | ||
| allPts(rectFormulas).forEach((pts) => { | ||
| const formula = randomRange(engine, rectValues) | ||
| if(outputLog) { | ||
| console.log(`engine.setCellContents({sheet: 0, col: ${pts.x}, row: ${pts.y}}, '${formula}')`) | ||
| } | ||
| engine.setCellContents({sheet: 0, col: pts.x, row: pts.y}, formula) | ||
| undoRedo(engine) | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Fills a rectangle of cells with random values. | ||
| * @param engine | ||
| * @param rectValues | ||
| */ | ||
| function randomVals(engine: HyperFormula, rectValues: Rectangle) { | ||
| allPts(rectValues).forEach((pts) => { | ||
| const val = randomInteger(-10, 10) | ||
| if(outputLog) { | ||
| console.log(`engine.setCellContents({sheet: 0, col:${pts.x}, row:${pts.y}}, ${val})`) | ||
| } | ||
| engine.setCellContents({sheet: 0, col: pts.x, row: pts.y}, val) | ||
| undoRedo(engine) | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * builds a rectangle from corner + X side length + Y side length | ||
| * @param pts | ||
| * @param sideX | ||
| * @param sideY | ||
| */ | ||
| function rectangleFromCorner(pts: Pts, sideX: number, sideY: number): Rectangle { | ||
| return {topleft: pts, bottomright: {x: pts.x + sideX, y: pts.y + sideY}} | ||
| } | ||
|
|
||
| /** | ||
| * all addresses from a rectangle | ||
| * | ||
| * @param rect | ||
| */ | ||
| function allPts(rect: Rectangle): Pts[] { | ||
| const ret: Pts[] = [] | ||
| for (let x = rect.topleft.x; x < rect.bottomright.x; x++) { | ||
| for (let y = rect.topleft.y; y < rect.bottomright.y; y++) { | ||
| ret.push({x, y}) | ||
| } | ||
| } | ||
| return ret | ||
| } | ||
|
|
||
| /** | ||
| * random shuffle of an array | ||
| * | ||
| * @param array | ||
| */ | ||
| function shuffleArray<T>(array: T[]): T[] { | ||
| for (let i = array.length - 1; i > 0; i--) { | ||
| const j = Math.floor(Math.random() * (i + 1)); | ||
| [array[i], array[j]] = [array[j], array[i]] | ||
| } | ||
| return array | ||
| } | ||
|
|
||
| /** | ||
| * swaps two rectangles in-place | ||
| * @param engine | ||
| * @param corner1 | ||
| * @param corner2 | ||
| * @param sideX | ||
| * @param sideY | ||
| */ | ||
| function swapTwoRectangles(engine: HyperFormula, pts1: Pts, pts2: Pts, sideX: number, sideY: number) { | ||
| if(outputLog) { | ||
| console.log(`engine.moveCells( AbsoluteCellRange.spanFrom({sheet: 0, col: ${pts1.x}, row: ${pts1.y}}, ${sideX}, ${sideY}), {sheet: 0, col: 1000, row: 1000})`) | ||
| } | ||
| engine.moveCells( AbsoluteCellRange.spanFrom({sheet: 0, col: pts1.x, row: pts1.y}, sideX, sideY), {sheet: 0, col: 1000, row: 1000}) | ||
| undoRedo(engine) | ||
| if(outputLog) { | ||
| console.log(`engine.moveCells( AbsoluteCellRange.spanFrom({sheet: 0, col: ${pts2.x}, row: ${pts2.y}}, ${sideX}, ${sideY}), {sheet: 0, col: ${pts1.x}, row: ${pts1.y}})`) | ||
| } | ||
| engine.moveCells( AbsoluteCellRange.spanFrom({sheet: 0, col: pts2.x, row: pts2.y}, sideX, sideY), {sheet: 0, col: pts1.x, row: pts1.y}) | ||
| undoRedo(engine) | ||
| if(outputLog) { | ||
| console.log(`engine.moveCells( AbsoluteCellRange.spanFrom({sheet: 0, col: 1000, row: 1000}, ${sideX}, ${sideY}), {sheet: 0, col: ${pts2.x}, row: ${pts2.y}})`) | ||
| } | ||
| engine.moveCells( AbsoluteCellRange.spanFrom({sheet: 0, col: 1000, row: 1000}, sideX, sideY), {sheet: 0, col: pts2.x, row: pts2.y}) | ||
| undoRedo(engine) | ||
| } | ||
|
|
||
| /** | ||
| * Empties the engine using .setCellContents() | ||
| * operates only on sheet: 0 | ||
| * | ||
| * @param engine - engine to be emptied | ||
| * @param rect - rectangle of adresses we expect nonempty cell to be in | ||
| * | ||
| * The outcome should be that there are no cells in the engine. | ||
| */ | ||
| function randomCleanup(engine: HyperFormula, rect: Rectangle) { | ||
| shuffleArray(allPts(rect)).forEach((pts) => { | ||
| if(outputLog) { | ||
| console.log(`engine.setCellContents({sheet: 0, col:${pts.x}, row:${pts.y}}, null)`) | ||
| } | ||
| engine.setCellContents({sheet: 0, col: pts.x, row: pts.y}, null) | ||
| undoRedo(engine) | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| describe('large psuedo-random test', () => { | ||
| it('growing rectangle + addRows + addColumns + removeRows + removeColumns should produce the same sheet as static sheet', () => { | ||
| const engine = HyperFormula.buildFromArray([]) | ||
| let sideX = 3 | ||
| const n = 4 | ||
| let sideY = 3 | ||
| for(let rep=0;rep<5;rep++) { | ||
| randomVals(engine, rectangleFromCorner({x: 0, y: 0}, sideX, sideY)) | ||
| verifyValues(engine) | ||
| for (let i = 0; i < n; i++) { | ||
| randomSums(engine, | ||
| rectangleFromCorner({x: sideX * (i + 1), y: 0}, sideX, sideY), | ||
| rectangleFromCorner({x: sideX * i, y: 0}, sideX, sideY) | ||
| ) | ||
| verifyValues(engine) | ||
| } | ||
| for (let i = 0; i < n; i++) { | ||
| randomSums(engine, | ||
| rectangleFromCorner({x: sideX * (i + 1), y: 0}, sideX, sideY), | ||
| rectangleFromCorner({x: 0, y: 0}, sideX * (i+1), sideY) | ||
| ) | ||
| verifyValues(engine) | ||
| } | ||
| for (let i=0; i<n; i++) { | ||
| const columnPositionToAdd = randomInteger(0, sideX*(n+1)+1) | ||
| if(outputLog) { | ||
| console.log(`engine.addColumns(0, [${columnPositionToAdd},2])`) | ||
| } | ||
| engine.addColumns(0, [columnPositionToAdd, 2]) | ||
| undoRedo(engine) | ||
| verifyValues(engine) | ||
| const columnPositionToRemove = randomInteger(0, sideX*(n+1)) | ||
| if(outputLog) { | ||
| console.log(`engine.removeColumns(0, [${columnPositionToRemove},1])`) | ||
| } | ||
| engine.removeColumns(0, [columnPositionToRemove, 1]) | ||
| undoRedo(engine) | ||
| } | ||
| sideX += 1 | ||
|
|
||
| const rowPositionToAdd = randomInteger(0, sideY + 1) | ||
| if(outputLog) { | ||
| console.log(`engine.addRows(0, [${rowPositionToAdd},2])`) | ||
| } | ||
| engine.addRows(0, [rowPositionToAdd, 2]) | ||
| undoRedo(engine) | ||
| sideY += 2 | ||
| verifyValues(engine) | ||
| const rowPositionToRemove = randomInteger(0, sideY) | ||
| if(outputLog) { | ||
| console.log(`engine.removeRows(0, [${rowPositionToRemove},1])`) | ||
| } | ||
| engine.removeRows(0, [rowPositionToRemove, 1]) | ||
| undoRedo(engine) | ||
| sideY -= 1 | ||
| verifyValues(engine) | ||
| const x1 = randomInteger(0, n*sideX) | ||
| const x2 = randomInteger(0, n*sideX) | ||
| const y1 = randomInteger(0, sideY) | ||
| const y2 = randomInteger(0, sideY) | ||
| swapTwoRectangles(engine, {x: x1, y: y1}, {x: x2, y: y2}, sideX, sideY) | ||
| verifyValues(engine) | ||
| } | ||
| randomCleanup(engine, rectangleFromCorner({x: 0, y: 0}, 2 * (n + 1) * sideX, 2 * sideY)) | ||
| expect(engine.dependencyGraph.graph.nodesCount()).toBe(0) | ||
| expect(engine.dependencyGraph.rangeMapping.getMappingSize(0)).toBe(0) | ||
| }) | ||
| }) | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.