/
docNemo
/
tactic-hack-core
Обзор
Документация
Войти
/
docNemo
/
tactic-hack-core
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/geometry.test.ts
53 строки
2 KB
neo
Implement rules engine: geometry, placement, attack reducer, replay, projection, deduction, protocol types
19 июл 2026, 00:03
19 июл 2026, 00:03
d1403fb
Код
Авторство
О чём код?
import { describe, expect, it } from "vitest"; import { axisCells, countSolidLines, sharedAxis, shipLineCells } from "./geometry.js"; import { BOARD_SIZE, Cell } from "./types.js"; describe("axisCells", () => { it("горизонталь через (3,3) покрывает всю строку кроме самой клетки", () => { const cells = axisCells({ row: 3, col: 3 }, "horizontal"); expect(cells).toHaveLength(BOARD_SIZE - 1); expect(cells.every((c) => c.row === 3)).toBe(true); expect(cells.some((c) => c.col === 3)).toBe(false); }); it("диагонали из угла (0,0)", () => { expect(axisCells({ row: 0, col: 0 }, "diagonalDown")).toHaveLength(9); expect(axisCells({ row: 0, col: 0 }, "diagonalUp")).toHaveLength(0); }); it("линии корабля в центре покрывают 4 оси без дублей", () => { const cells = shipLineCells({ row: 4, col: 4 }); const keys = new Set(cells.map((c) => `${c.row},${c.col}`)); expect(keys.size).toBe(cells.length); // строка 9 + столбец 9 + диагонали (8 + 9) expect(cells).toHaveLength(9 + 9 + 8 + 9); }); }); describe("sharedAxis", () => { it("определяет каждую из осей", () => { const origin: Cell = { row: 4, col: 4 }; expect(sharedAxis(origin, { row: 4, col: 9 })).toBe("horizontal"); expect(sharedAxis(origin, { row: 0, col: 4 })).toBe("vertical"); expect(sharedAxis(origin, { row: 2, col: 6 })).toBe("diagonalUp"); expect(sharedAxis(origin, { row: 6, col: 6 })).toBe("diagonalDown"); expect(sharedAxis(origin, { row: 2, col: 5 })).toBeNull(); expect(sharedAxis(origin, origin)).toBeNull(); }); }); describe("countSolidLines", () => { it("клетка на пересечении двух линий разных кораблей", () => { const ships: Cell[] = [ { row: 0, col: 0 }, { row: 1, col: 2 }, ]; // (0,2): строка корабля (0,0) + столбец корабля (1,2) expect(countSolidLines(ships, { row: 0, col: 2 })).toBe(2); }); it("клетка вне всех линий", () => { const ships: Cell[] = [{ row: 0, col: 0 }]; expect(countSolidLines(ships, { row: 2, col: 5 })).toBe(0); }); });