auu
This commit is contained in:
parent
d995726462
commit
0a343ecbc5
326 changed files with 15584 additions and 0 deletions
11
test/anomaly-smoke-test.js
Normal file
11
test/anomaly-smoke-test.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
const {vm,assert,functionSource,loadBendPuzzle,loadAppLogic}=require('./helpers/app-source');
|
||||
const BendPuzzle=loadBendPuzzle(),AppLogic=loadAppLogic();
|
||||
const context={AppLogic,hash32:BendPuzzle.hash32,rngFrom:BendPuzzle.rngFrom,shuffle:BendPuzzle.shuffle,deepClone:value=>JSON.parse(JSON.stringify(value)),ckey:(r,c)=>`${r},${c}`,sameCell:(a,b)=>a[0]===b[0]&&a[1]===b[1],manhattan:(a,b)=>Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]),SIDE_D:{N:[-1,0],S:[1,0],W:[0,-1],E:[0,1]}};
|
||||
vm.createContext(context);
|
||||
vm.runInContext(['specialCellSet','warpMap','warpPairForCell','isWarpTransition','gateObj','outsidePoint','analyzeTurns','turnAnalysis','obstacleDetours','obstacleCellLimit','addObstaclePattern'].map(name=>functionSource(name)).join('\n')+'\nthis.logic={obstacleCellLimit,addObstaclePattern};',context);
|
||||
let obstacleCells=0,allCells=0,boards=0;for(let seed=1;seed<=240;seed++){let puzzle;try{puzzle=BendPuzzle.generatePuzzle([[0,0]],0x330000+seed,3,seed%7,-seed%5)}catch(_){continue}const changed=context.logic.addObstaclePattern(puzzle,0x550000+seed);obstacleCells+=(changed.obstacles||[]).length;allCells+=puzzle.valid.length;boards++}
|
||||
const obstacleRate=obstacleCells/allCells;assert(boards>200,'Too few obstacle samples');assert(obstacleRate>=.008&&obstacleRate<=.05,`Obstacle rate ${(obstacleRate*100).toFixed(2)}% is implausible`);
|
||||
let largeObstacleCells=0,largeAllCells=0,largeBoards=0;for(let seed=1;seed<=60;seed++){let puzzle;try{puzzle=BendPuzzle.generatePuzzle([[0,0],[1,0],[0,1],[1,1]],0x660000+seed,5,20,-20)}catch(_){continue}const changed=context.logic.addObstaclePattern(puzzle,0x770000+seed),totalCells=changed.valid.length+(changed.obstacles||[]).length;assert((changed.obstacles||[]).length<=Math.floor(totalCells*.2),'Obstacle generation exceeded 20% of the puzzle');largeObstacleCells+=(changed.obstacles||[]).length;largeAllCells+=totalCells;largeBoards++}
|
||||
const largeObstacleRate=largeObstacleCells/largeAllCells;assert(largeBoards>=45,'Too few large obstacle samples');assert(largeObstacleRate>obstacleRate+.005,`Large-puzzle obstacle rate ${(largeObstacleRate*100).toFixed(2)}% is not higher than small puzzles`);
|
||||
console.log(`Obstacle test passed: ${(obstacleRate*100).toFixed(2)}% small and ${(largeObstacleRate*100).toFixed(2)}% large obstacle cells`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue