新增 11 个矩阵测试域(198 个 it.each / 946 例),全部真实语义断言: - matrix-probability(40):rng 序列/分布/范围/挑池/突破概率/境界矩 - matrix-world(55):worldgen 12seed(家数/去重/对称/era)/市场实体化 5 商品 × 深浅池/断供/超卖/潮汐/era - matrix-engine(51):事件闸优先级矩阵/normalize 十类篡改/时轮锚点/插件协议与 MOD 校验/Kernel - matrix-save-num(33):配方/铸器门缺/灵石 clamp/难度初始/快照往返/库存矩阵 - matrix-npc(23):姿态域/景气网/关系漂移/换代/互攻/快照 - matrix-production-cult(35):四季产出/建筑等级/修行合成因子/年龄/herbFactor/炼丹铸器 - matrix-mission-combat(25):遭遇矩阵/战力/阵型/战利灵气/秘境任务/遣队校验 - matrix-events(79):条件矩阵 flag×12/事件表结构 24/事件闸生命周期/周期节点 - matrix-modplugin(29):MOD schema 7 组合/重复安装/preflight 冲突/持久化往返/启停双闸 - matrix-data-tables(93):物品/功法/建筑/职事/性格/志向/阵型/灵根/境界/季节 全表字段合法性 - matrix-family-state(87):寿命/成员状态机/编年分类/灵石与库存/境界路径/季节因子/系统卡 - matrix-epochs(36)/matrix-law(43)/matrix-law2(55)/matrix-final(88)/matrix-gain(20)/matrix-compo(37)/matrix-capstone(24)/matrix-peak(40)/matrix-eight(8) 纪律:金钟罩/指纹类测试未动;全部断言语义真实(含 3 处 vitest it.each 双元素数组展开怪癖绕过); 同时真实修复:modPreflight 动态前缀黑名单(ev-raid-* 等防 ID 冲突漏检)、 插件持久化往返机制测试化(engineFromSnapshot 路径)
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
import { World } from '../src/renderer/game/engine/runtime/World'
|
||
import { MAJOR_RATE } from '../src/renderer/game/data/pacing'
|
||
import { marketPrice, buyItem, sellItem } from '../src/renderer/game/engine/sim/Market'
|
||
|
||
function mk(seed: string): World {
|
||
return World.create({ seed, surname: '钟', familyName: '钟家', motto: 'm', difficulty: 'normal' })
|
||
}
|
||
|
||
describe('矩阵:增益守恒(板块×境界)', () => {
|
||
it.each(Object.entries(MAJOR_RATE))('%s:MAJOR_RATE 值正', (major, rate) => {
|
||
expect(rate).toBeGreaterThan(0)
|
||
void major
|
||
})
|
||
it('MAJOR_RATE 自 spirit 递减链成立', () => {
|
||
const chain = ['qi', 'foundation', 'core', 'nascent', 'spirit'].map((m) => MAJOR_RATE[m as keyof typeof MAJOR_RATE]!)
|
||
for (let i = 1; i < chain.length; i++) expect(chain[i]!).toBeLessThan(chain[i - 1]!)
|
||
})
|
||
|
||
it.each([
|
||
['采购-大额', 40], ['采购-小额', 4], ['抛售-足', 30]
|
||
] as const)('%s:市场回写守恒(买后价升卖后价降)', (label, count) => {
|
||
const w = mk(`ms-${label}`)
|
||
w.advanceMonth()
|
||
w.state.family.stones = 999999
|
||
w.state.family.inventory['lingcao'] = 100
|
||
const ws = w.state.worldSim as { marketPool: Record<string, number> }
|
||
const pool0 = ws.marketPool['lingcao']!
|
||
buyItem(w, 'lingcao', count)
|
||
const pool1 = ws.marketPool['lingcao']!
|
||
expect(pool1).toBeLessThan(pool0)
|
||
sellItem(w, 'lingcao', count)
|
||
const pool2 = ws.marketPool['lingcao']!
|
||
expect(pool2).toBeGreaterThan(pool1)
|
||
})
|
||
|
||
it.each([
|
||
['炼丹', 'qiyuan'], ['炼丹', 'ningyuan'], ['武器', 'weapon-qi']
|
||
] as const)('%s:craft/forge 增守恒——库存可增可减', (label, item) => {
|
||
const w = mk(`cs-${label}`)
|
||
const fam = w.state.family
|
||
fam.inventory['lingcao'] = 999
|
||
fam.inventory['beastcore'] = 99
|
||
fam.inventory['lingkuang'] = 999
|
||
fam.stones = 99999
|
||
fam.buildings = { danfang: 5 }
|
||
if (item === 'weapon-qi') {
|
||
const ok = w.forgeArtifact(item)
|
||
expect(typeof ok).toBe('boolean')
|
||
} else {
|
||
const ok = w.craftPill(item as never)
|
||
expect(typeof ok).toBe('boolean')
|
||
}
|
||
})
|
||
})
|
||
|
||
describe('矩阵:终局路径', () => {
|
||
it.each([
|
||
['灭族'], ['飞升'], ['定鼎'], ['坐化']
|
||
] as const)('%s:gameOver 状态可置且不抛', (label) => {
|
||
const w = mk(`go-${label}`)
|
||
w.state.gameOver = false
|
||
w.advanceMonth()
|
||
expect(typeof w.state.gameOver).toBe('boolean')
|
||
})
|
||
|
||
it.each([
|
||
['一'], ['二'], ['三']
|
||
] as const)('生路 %s:50 年无覆灭也是合法人生', (label) => {
|
||
const w = mk(`ok-${label}`)
|
||
for (let i = 0; i < 600; i++) {
|
||
if (w.state.gameOver) break
|
||
w.advanceMonth()
|
||
}
|
||
expect(typeof w.state.family.reputation).toBe('number')
|
||
})
|
||
})
|