43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { Board } from '../../src/core/board.js';
|
|
import { applyGravity } from '../../src/core/gravity.js';
|
|
|
|
describe('applyGravity', () => {
|
|
it('should move values down to fill empty cells', () => {
|
|
const grid = Array.from({ length: 10 }, () => new Array(17).fill(0));
|
|
grid[0][0] = 5; // top cell has value
|
|
// middle and bottom are empty
|
|
const board = new Board(grid);
|
|
|
|
applyGravity(board);
|
|
|
|
// value should fall to bottom
|
|
expect(board.get(9, 0)).toBe(5);
|
|
expect(board.get(0, 0)).toBe(0);
|
|
});
|
|
|
|
it('should preserve order when multiple values fall', () => {
|
|
const grid = Array.from({ length: 10 }, () => new Array(17).fill(0));
|
|
grid[0][0] = 3;
|
|
grid[2][0] = 7;
|
|
grid[5][0] = 1;
|
|
const board = new Board(grid);
|
|
|
|
applyGravity(board);
|
|
|
|
expect(board.get(9, 0)).toBe(1);
|
|
expect(board.get(8, 0)).toBe(7);
|
|
expect(board.get(7, 0)).toBe(3);
|
|
});
|
|
|
|
it('should not change a fully packed board', () => {
|
|
const grid = Array.from({ length: 10 }, () => new Array(17).fill(5));
|
|
const board = new Board(grid);
|
|
const before = board.grid.map(r => [...r]);
|
|
|
|
applyGravity(board);
|
|
|
|
expect(board.grid).toEqual(before);
|
|
});
|
|
});
|