90eaf4964b
Tests · Go / test (push) Successful in 10s
Tests · Integration / integration (push) Successful in 12s
Tests · UI / test (push) Successful in 19s
Tests · Go / test (pull_request) Successful in 9s
Tests · Integration / integration (pull_request) Successful in 12s
Tests · UI / test (pull_request) Successful in 19s
Live play now exchanges per-variant alphabet indices instead of concrete letters (rack out; submit-play, evaluate, exchange, word-check in). The client caches each variant's (index, letter, value) table behind StateRequest.include_alphabet and renders the rack and blank chooser from it, dropping the hardcoded value/alphabet tables. History, the durable journal and GCG stay decoded concrete characters (ARCHITECTURE §9.1, unchanged). - pkg/fbs: new AlphabetEntry + PlayTile; StateView.rack -> [ubyte] + alphabet; StateRequest.include_alphabet; SubmitPlay/Eval tiles -> [PlayTile]; Exchange tiles + CheckWord word -> [ubyte] (committed Go + TS regenerated). - engine: AlphabetTable + a cached per-variant codec (LetterForIndex/EncodeRack/ DecodeTiles/DecodeWord) + BlankIndex sentinel; Go parity test. - backend server edge maps index<->letter (new thin game.Service.GameVariant); game.Service domain methods, engine.Game and the robot keep one letter-based play path. The gateway forwards indices verbatim (no alphabet table). - ui: lib/alphabet.ts in-memory cache; codec encodes/decodes indices; premiums.ts is geometry-only; the mock seeds a fixture table; the UI normalises display to upper case (codec + cache), leaving placement/board/checkword unchanged. Parity moved to the Go engine.AlphabetTable test; premiums.ts loses its value tables. Discharges TODO-4.
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
alphabetLetters,
|
|
BLANK_INDEX,
|
|
hasAlphabet,
|
|
indexForLetter,
|
|
letterForIndex,
|
|
setAlphabet,
|
|
valueForLetter,
|
|
} from './alphabet';
|
|
|
|
// The cache module is per-file-isolated by vitest, so only what these tests seed exists.
|
|
describe('alphabet cache (Stage 13)', () => {
|
|
it('upper-cases letters for display and maps indices and values case-insensitively', () => {
|
|
setAlphabet('english', [
|
|
{ index: 0, letter: 'a', value: 1 },
|
|
{ index: 16, letter: 'q', value: 10 },
|
|
]);
|
|
expect(hasAlphabet('english')).toBe(true);
|
|
expect(letterForIndex('english', 0)).toBe('A');
|
|
expect(letterForIndex('english', 16)).toBe('Q');
|
|
expect(indexForLetter('english', 'a')).toBe(0);
|
|
expect(indexForLetter('english', 'Q')).toBe(16);
|
|
expect(valueForLetter('english', 'a')).toBe(1);
|
|
expect(valueForLetter('english', 'Q')).toBe(10);
|
|
});
|
|
|
|
it('handles the blank sentinel and unknown letters/indices', () => {
|
|
setAlphabet('english', [{ index: 0, letter: 'a', value: 1 }]);
|
|
expect(letterForIndex('english', BLANK_INDEX)).toBe('?');
|
|
expect(indexForLetter('english', '?')).toBe(BLANK_INDEX);
|
|
expect(valueForLetter('english', '?')).toBe(0);
|
|
expect(letterForIndex('english', 99)).toBe(''); // out of range
|
|
expect(valueForLetter('english', 'Z')).toBe(0); // not in this alphabet
|
|
expect(() => indexForLetter('english', 'Z')).toThrow();
|
|
});
|
|
|
|
it('lists the alphabet for the blank chooser and is empty for an uncached variant', () => {
|
|
setAlphabet('english', [
|
|
{ index: 0, letter: 'a', value: 1 },
|
|
{ index: 1, letter: 'b', value: 3 },
|
|
]);
|
|
expect(alphabetLetters('english')).toEqual(['A', 'B']);
|
|
expect(hasAlphabet('erudit')).toBe(false);
|
|
expect(alphabetLetters('erudit')).toEqual([]);
|
|
expect(valueForLetter('erudit', 'A')).toBe(0);
|
|
});
|
|
});
|