diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-19 18:47:24 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-19 18:47:24 +0800 |
| commit | ab0cdf47f453bf3e12df0201cd7bd1835fb03cae (patch) | |
| tree | c0b755429ead73c9177d0704c109e3aa71b59ce4 /src/LivingVillage.Kernel.Tests | |
| parent | c1242ee391a25d5e5664befb5efe84b3e471ffd2 (diff) | |
| download | living-village-ab0cdf47f453bf3e12df0201cd7bd1835fb03cae.tar.gz | |
fix: M3c 关系半衰期单位错误 86400L(=24模拟分钟)→ticksPerDay(1模拟日=5,184,000tick) + 衰减改真半衰 exp(-ln2*age/halfLife)(age=halfLife 处权重恰0.5, 旧式 exp(-age/halfLife) 为 e^-1≈0.368) + 单测锁定(1天=5184000tick/halfLife=1天/半衰权重0.5, 手算期望随真半衰语义更新) + headless 批验新增旧判据 old_crit 观测报告(60% 覆盖判据保留为门)
Diffstat (limited to 'src/LivingVillage.Kernel.Tests')
| -rw-r--r-- | src/LivingVillage.Kernel.Tests/RelationTests.fs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/LivingVillage.Kernel.Tests/RelationTests.fs b/src/LivingVillage.Kernel.Tests/RelationTests.fs index f1d9673..0f9de83 100644 --- a/src/LivingVillage.Kernel.Tests/RelationTests.fs +++ b/src/LivingVillage.Kernel.Tests/RelationTests.fs @@ -71,12 +71,30 @@ type RelationTests () = if older >= old then Assert.Fail("weight must strictly decrease with age") [<TestMethod>] + member _.OneDayEqualsTicksPerDayConstant () = + // 守卫:1 模拟日 = 24h * 3600s * 60tick/s = 5,184,000 tick + if Sim.ticksPerDay <> 5_184_000L then Assert.Fail($"ticksPerDay={Sim.ticksPerDay}, expected 5184000") + + [<TestMethod>] + member _.RelationHalfLifeEqualsOneDay () = + // HALF_LIFE 必须 = 1 模拟日(修复单位错误:原 86400L 实为 24 模拟分钟) + if Sim.relationHalfLifeTicks <> Sim.ticksPerDay then + Assert.Fail($"relationHalfLifeTicks={Sim.relationHalfLifeTicks}, ticksPerDay={Sim.ticksPerDay}") + + [<TestMethod>] + member _.RelationDecayWeightAtHalfLifeIsHalf () = + // 真半衰语义:age = halfLife 处权重恰为 0.5(旧式 exp(-age/halfLife) 给出 e^-1≈0.368) + let now = 2L * Sim.relationHalfLifeTicks + let w = Sim.relationDecayWeight now (now - Sim.relationHalfLifeTicks) + if abs (w - 0.5f) > 1e-4f then Assert.Fail($"weight at one half-life = {w}, expected 0.5") + + [<TestMethod>] member _.RelationMatrixMatchesHandComputedDecay () = - // 单次闲聊记忆(tick=0, valence=0.3),now = 1 个半衰期 → 双向累加 2 * 0.3 * e^-1 + // 单次闲聊记忆(tick=0, valence=0.3),now = 1 个半衰期 → 真半衰权重恰 0.5 → 双向累加 2 * 0.3 * 0.5 let w = RelationHarness.handWorld Sim.relationHalfLifeTicks [ RelationHarness.chatted 0L 1 ] [ RelationHarness.chatted 0L 0 ] let m = Sim.relationMatrix w - let expected = 2.0f * Sim.chatValence * float32 (System.Math.Exp(-1.0)) + let expected = 2.0f * Sim.chatValence * 0.5f if abs (m.[0, 1] - expected) > 1e-6f then Assert.Fail($"m[0,1]={m.[0, 1]} expected={expected}") if abs (m.[1, 0] - expected) > 1e-6f then Assert.Fail($"m[1,0]={m.[1, 0]} expected={expected}") if m.[0, 0] <> 0.0f then Assert.Fail("diagonal must be zero") |
