werewolf(app): port single-device dealer from partiverse + tests
单机发牌器 — 一台手机轮流传,无 room / 无 ws。30 个角色 + 4 档默认预设 (8/9/10/12 人) + 配置历史(dedup + cap 50)+ 4x 偏好加权 + swipe-to-reveal + tap-to-confirm + 3D card flip + 死亡标记,全部本地 localStorage。 RNG 注入,logic 层 29 个 vitest(含 2000 次蒙特卡洛验证偏好命中率 > 40%、 均匀分布 ±5%)。也把 *.tsbuildinfo 加进 .gitignore。
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { addHistory, type HistoryEntry } from '../logic/storage'
|
||||
|
||||
describe('addHistory', () => {
|
||||
it('inserts new entries at the front', () => {
|
||||
const h: HistoryEntry[] = [{ playerCount: 8, roles: { 狼人: 2 } }]
|
||||
const out = addHistory(h, { playerCount: 9, roles: { 狼人: 3 } })
|
||||
expect(out[0]).toEqual({ playerCount: 9, roles: { 狼人: 3 } })
|
||||
expect(out).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('deduplicates same (playerCount, roles)', () => {
|
||||
const h: HistoryEntry[] = [
|
||||
{ playerCount: 8, roles: { 狼人: 2, 村民: 6 } },
|
||||
{ playerCount: 9, roles: { 狼人: 3, 村民: 6 } },
|
||||
]
|
||||
const out = addHistory(h, { playerCount: 8, roles: { 狼人: 2, 村民: 6 } })
|
||||
expect(out).toHaveLength(2)
|
||||
expect(out[0]).toEqual({ playerCount: 8, roles: { 狼人: 2, 村民: 6 } })
|
||||
// 9 人配置应该还在
|
||||
expect(out[1]).toEqual({ playerCount: 9, roles: { 狼人: 3, 村民: 6 } })
|
||||
})
|
||||
|
||||
it('distinguishes entries with same playerCount but different role counts', () => {
|
||||
const h: HistoryEntry[] = [{ playerCount: 8, roles: { 狼人: 2 } }]
|
||||
const out = addHistory(h, { playerCount: 8, roles: { 狼人: 3 } })
|
||||
expect(out).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('caps history at 50 entries', () => {
|
||||
let h: HistoryEntry[] = []
|
||||
for (let i = 0; i < 100; i++) {
|
||||
h = addHistory(h, { playerCount: 8, roles: { 狼人: i } })
|
||||
}
|
||||
expect(h).toHaveLength(50)
|
||||
// 最新的(i=99)在最前
|
||||
expect(h[0]).toEqual({ playerCount: 8, roles: { 狼人: 99 } })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user