// 测试纯函数布局/可见性算法。 // 直接 import room-scene-layout.ts,不依赖 RoomSceneStart.ts(后者引入 cc 模块,需 Cocos 运行时)。 // 这与 CLAUDE.md 第二准则一致:纯逻辑放纯文件,被测方无需任何 cc mock。 import { test } from 'node:test'; import assert from 'node:assert/strict'; import { computeActiveFlags, computePositions } from '../../YouleNexus/assets/scripts/room-scene-layout.ts'; test('computeActiveFlags(2, 8) → 前 2 true, 其余 false', () => { assert.deepEqual( computeActiveFlags(2, 8), [true, true, false, false, false, false, false, false], ); }); test('computeActiveFlags(4, 8) → 前 4 true, 其余 false', () => { assert.deepEqual( computeActiveFlags(4, 8), [true, true, true, true, false, false, false, false], ); }); test('computeActiveFlags(0, 8) → throw', () => { assert.throws(() => computeActiveFlags(0, 8), /count must be 1-8/); }); test('computeActiveFlags(9, 8) → throw (exceeds 8)', () => { assert.throws(() => computeActiveFlags(9, 8), /count must be 1-8/); }); test('computePositions(horizontal, 4) → 4 玩家水平排列居中', () => { const positions = computePositions('horizontal', 4); assert.equal(positions.length, 4); // 对称居中:首末 + 中间两项 sum = 0 assert.equal(positions[0].x + positions[3].x, 0); assert.equal(positions[1].x + positions[2].x, 0); // 全员 y=0 assert.ok(positions.every((p) => p.y === 0)); });