init
This commit is contained in:
commit
a986cfea41
1716 files changed
+1004440
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { Board } from '../../src/core/board.js';
|
||||
import { findAllValidMoves } from '../../src/core/moves.js';
|
||||
|
||||
describe('findAllValidMoves', () => {
|
||||
it('should find single-cell moves where value is 10 (none, since max is 9)', () => {
|
||||
const board = new Board([[1, 2, 3], [4, 5, 6], [7, 8, 9]].map(r => [...r, ...new Array(14).fill(0)]).concat(new Array(7).map(() => new Array(17).fill(0))));
|
||||
// This board has values only in top-left 3x3
|
||||
// No single cell equals 10
|
||||
});
|
||||
|
||||
it('should find valid rectangles summing to 10', () => {
|
||||
// Create a small test: 1 2 3 4 in first row, rest 0
|
||||
const grid = Array.from({ length: 10 }, () => new Array(17).fill(0));
|
||||
grid[0][0] = 1;
|
||||
grid[0][1] = 2;
|
||||
grid[0][2] = 3;
|
||||
grid[0][3] = 4;
|
||||
const board = new Board(grid);
|
||||
|
||||
const moves = findAllValidMoves(board);
|
||||
// 1+2+3+4 = 10, so the rectangle (0,0)-(0,3) should be found
|
||||
const hasFullRow = moves.some(m => m.r1 === 0 && m.c1 === 0 && m.r2 === 0 && m.c2 === 3);
|
||||
expect(hasFullRow).toBe(true);
|
||||
|
||||
// 2+3+4 = 9, not valid; 3+4 = 7, not valid; etc.
|
||||
// But 1+2+3+4 = 10 ✓
|
||||
// Also check that no invalid moves are included
|
||||
for (const m of moves) {
|
||||
let sum = 0;
|
||||
for (let r = m.r1; r <= m.r2; r++) {
|
||||
for (let c = m.c1; c <= m.c2; c++) {
|
||||
sum += board.get(r, c);
|
||||
}
|
||||
}
|
||||
expect(sum).toBe(10);
|
||||
}
|
||||
});
|
||||
|
||||
it('should find no moves on empty board', () => {
|
||||
const grid = Array.from({ length: 10 }, () => new Array(17).fill(0));
|
||||
const board = new Board(grid);
|
||||
expect(findAllValidMoves(board)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user