47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
import { expect, test } from 'bun:test';
|
|
import { movePath, newEvents, toSegments, type GameEvent } from './events';
|
|
|
|
const ev = (type: string, extra: Record<string, unknown> = {}): GameEvent => ({ type, ...extra }) as GameEvent;
|
|
|
|
test('부루마불 화면: 새 기록만 골라내기(60개 창이 밀려도)', () => {
|
|
const old = Array.from({ length: 60 }, (_, i) => ev('turn', { player: 'A', round: i }));
|
|
expect(newEvents(old, old)).toEqual([]);
|
|
expect(newEvents(old, [...old])).toEqual([]);
|
|
const added = [ev('rolled', { player: 'A', dice: [1, 2] }), ev('moved', { player: 'A', from: 0, to: 3, kind: 'roll' })];
|
|
expect(newEvents(old, [...old.slice(2), ...added])).toEqual(added);
|
|
expect(newEvents(old.slice(0, 5), [...old.slice(0, 5), ...added])).toEqual(added);
|
|
expect(newEvents([], added)).toEqual(added);
|
|
// Replay jumping back / unrelated log: no match, stay quiet.
|
|
expect(newEvents(old.slice(10, 20), old.slice(0, 5))).toBeNull();
|
|
});
|
|
|
|
test('부루마불 화면: 말이 지나가는 칸', () => {
|
|
expect(movePath(ev('moved', { from: 37, to: 2, kind: 'roll' }))).toEqual([37, 38, 39, 0, 1, 2]);
|
|
expect(movePath(ev('moved', { from: 2, to: 39, kind: 'back' }))).toEqual([2, 1, 0, 39]);
|
|
expect(movePath(ev('moved', { from: 30, to: 5, kind: 'space' }))).toEqual([30, 5]);
|
|
expect(movePath(ev('moved', { from: 0, to: 0, kind: 'card', passedStart: true }))).toHaveLength(41);
|
|
});
|
|
|
|
test('부루마불 화면: 굴림 → 이동 → 도착 처리 순서로 나누기', () => {
|
|
const segs = toSegments(
|
|
[
|
|
ev('rolled', { player: 'A' }),
|
|
ev('moved', { player: 'A', from: 38, to: 3, kind: 'roll', passedStart: true }),
|
|
ev('salary', { player: 'A' }),
|
|
ev('tollPaid', { from: 'A', to: 'B' }),
|
|
ev('turn', { player: 'B' }),
|
|
ev('rolled', { player: 'B' }),
|
|
ev('toIsland', { player: 'B', why: 'doubles' }),
|
|
],
|
|
new Map([
|
|
['A', 38],
|
|
['B', 7],
|
|
]),
|
|
);
|
|
expect(segs.map((s) => [s.player, s.path, s.walk, s.salary, s.start.map((e) => e.type), s.after.map((e) => e.type)])).toEqual([
|
|
[null, [], false, false, [], ['rolled']],
|
|
['A', [38, 39, 0, 1, 2, 3], true, true, [], ['salary', 'tollPaid', 'turn', 'rolled']],
|
|
['B', [7, 10], false, false, ['toIsland'], []],
|
|
]);
|
|
});
|