import { describe, it, expect } from 'vitest'; import { captureTally } from '../../src/captures.js'; import type { Game, MoveRecord } from '../../src/state.js'; import type { Color, PieceType } from '@blind-chess/shared'; function rec(by: Color, capturedPieceType?: PieceType): MoveRecord { return { ply: 1, by, from: 'e2', to: 'e4', san: 'e4', capturedPieceType, flags: {}, at: 0, }; } describe('captureTally', () => { it('counts captures per viewer', () => { const moveHistory: MoveRecord[] = [ rec('w', 'p'), rec('b'), rec('w', 'n'), rec('b', 'p'), rec('w', 'p'), ]; const game = { moveHistory } as unknown as Game; expect(captureTally(game, 'w')).toEqual({ byYou: { p: 2, n: 1 }, byOpponent: { p: 1 }, }); expect(captureTally(game, 'b')).toEqual({ byYou: { p: 1 }, byOpponent: { p: 2, n: 1 }, }); }); it('returns empty tallies when there are no captures', () => { const game = { moveHistory: [rec('w'), rec('b')] } as unknown as Game; expect(captureTally(game, 'w')).toEqual({ byYou: {}, byOpponent: {} }); }); });