-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGame.js
More file actions
89 lines (71 loc) · 3.25 KB
/
Copy pathtestGame.js
File metadata and controls
89 lines (71 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { checkMatch, findPath, generateGrid } from './src/utils/gameLogic.js';
console.log("Starting Game Logic Verification...");
let passed = 0;
let failed = 0;
const assert = (condition, message) => {
if (condition) {
console.log(`PASS: ${message}`);
passed++;
} else {
console.error(`FAIL: ${message}`);
failed++;
}
};
console.log("\n--- Verifying Equivalence Classes ---");
const tileX = { id: '1', content: 'x', classKey: 'x' };
const tileSinX = { id: '2', content: '\\sin x', classKey: 'x' };
const tile2x = { id: '3', content: '2x', classKey: '2x' };
const tileSin2x = { id: '4', content: '\\sin(2x)', classKey: '2x' };
assert(checkMatch(tileX, tileSinX) === true, "x should match sin(x)");
assert(checkMatch(tile2x, tileSin2x) === true, "2x should match sin(2x)");
assert(checkMatch(tileX, tile2x) === false, "x should NOT match 2x");
assert(checkMatch(tileX, tileX) === false, "Tile should not match itself by ID");
console.log("\n--- Verifying Grid Generation ---");
try {
const grid = generateGrid(4, 4);
assert(grid.length === 4 && grid[0].length === 4, "Grid dimensions should be 4x4");
const counts = {};
grid.flat().forEach(tile => {
counts[tile.classKey] = (counts[tile.classKey] || 0) + 1;
});
const allEven = Object.values(counts).every(count => count % 2 === 0);
assert(allEven, "All classes should have an even number of tiles");
} catch (e) {
console.error("Grid generation failed", e);
failed++;
}
console.log("\n--- Verifying Pathfinding ---");
const start = { row: 0, col: 0 };
const end = { row: 0, col: 2 };
const straightGrid = [
[{ status: 'idle' }, { status: 'matched' }, { status: 'idle' }],
[{ status: 'matched' }, { status: 'matched' }, { status: 'matched' }],
[{ status: 'matched' }, { status: 'matched' }, { status: 'matched' }]
];
const path1 = findPath(straightGrid, start, end);
assert(path1 !== null, "Should find straight path through empty space");
const uTurnGrid = [
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }],
[{ status: 'matched' }, { status: 'matched' }, { status: 'matched' }],
[{ status: 'matched' }, { status: 'matched' }, { status: 'matched' }]
];
const path2 = findPath(uTurnGrid, start, end);
assert(path2 !== null, "Should find U-shaped path with two turns");
const blockedStart = { row: 1, col: 1 };
const blockedEnd = { row: 1, col: 3 };
const blockedGrid = [
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }, { status: 'idle' }],
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }, { status: 'idle' }],
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }, { status: 'idle' }]
];
const path3 = findPath(blockedGrid, blockedStart, blockedEnd);
assert(path3 === null, "Should NOT find path when the start is blocked");
const outsideEdgeGrid = [
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }],
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }],
[{ status: 'idle' }, { status: 'idle' }, { status: 'idle' }]
];
const path4 = findPath(outsideEdgeGrid, start, end);
assert(path4 !== null, "Should find outside-edge path for boundary tiles");
console.log(`\nVerification Complete: ${passed} Passed, ${failed} Failed`);
if (failed > 0) process.exit(1);