articulate(app): port single-device word game from partiverse + tests
中英猜词派对 — 选主题 / 难度 / 词数 → 大字模式描述给队友猜,无 room / 无 ws。 15 个 preset 主题(wordlists 已在 scaffold 时就位)+ 3 档难度 + 已看词跨场 记忆(localStorage,cap 5000)+ Enter/Space/Esc 键盘。pickWords 优先未看过 再 fallback 见过的。logic 层 24 个 vitest(解析 / 抽词 / 确定性 rng)。
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { addSeen } from '../logic/storage'
|
||||
|
||||
describe('addSeen', () => {
|
||||
it('appends new keys to the end', () => {
|
||||
expect(addSeen(['a', 'b'], ['c', 'd'])).toEqual(['a', 'b', 'c', 'd'])
|
||||
})
|
||||
|
||||
it('deduplicates existing keys', () => {
|
||||
expect(addSeen(['a', 'b'], ['b', 'c'])).toEqual(['a', 'b', 'c'])
|
||||
})
|
||||
|
||||
it('handles all-duplicate addition', () => {
|
||||
expect(addSeen(['a', 'b'], ['a', 'b'])).toEqual(['a', 'b'])
|
||||
})
|
||||
|
||||
it('respects MAX_SEEN cap (5000) by trimming oldest', () => {
|
||||
const existing = Array.from({ length: 5000 }, (_, i) => `k${i}`)
|
||||
const out = addSeen(existing, ['new1', 'new2'])
|
||||
expect(out).toHaveLength(5000)
|
||||
expect(out[out.length - 1]).toBe('new2')
|
||||
expect(out[out.length - 2]).toBe('new1')
|
||||
// 最旧的 'k0' 和 'k1' 被挤出
|
||||
expect(out.includes('k0')).toBe(false)
|
||||
expect(out.includes('k1')).toBe(false)
|
||||
})
|
||||
|
||||
it('empty input', () => {
|
||||
expect(addSeen([], [])).toEqual([])
|
||||
expect(addSeen([], ['a'])).toEqual(['a'])
|
||||
expect(addSeen(['a'], [])).toEqual(['a'])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user