diff options
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
3 files changed, 69 insertions, 1 deletions
diff --git a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj index 432cd03..11a1b90 100644 --- a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj +++ b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj @@ -44,6 +44,7 @@ <Compile Include="P69CopyAuditTests.fs" /> <Compile Include="P71ApiDocsTests.fs" /> <Compile Include="P72CharacterWalkTests.fs" /> + <Compile Include="P73LightingTierTests.fs" /> <Compile Include="SampleTests.fs" /> </ItemGroup> diff --git a/src/LivingVillage.Desktop.Tests/P73LightingTierTests.fs b/src/LivingVillage.Desktop.Tests/P73LightingTierTests.fs new file mode 100644 index 0000000..e5baf0a --- /dev/null +++ b/src/LivingVillage.Desktop.Tests/P73LightingTierTests.fs @@ -0,0 +1,67 @@ +namespace LivingVillage.Desktop.Tests + +open Microsoft.VisualStudio.TestTools.UnitTesting +open Microsoft.Xna.Framework +open LivingVillage.Desktop +open LivingVillage.Kernel +open LivingVillage.Kernel.Sim + +/// P73 回归:四时段光照档参数表完整性 + 与既有连续光照/时段标签一致。 +[<TestClass>] +type P73LightingTierTests () = + + let ticksPerHour = Sim.ticksPerDay / 24L + let atHour hour = int64 hour * ticksPerHour + + [<TestMethod>] + member _.PeriodTableCoversFourDistinctTiers () = + let periods = [ M6Presentation.Morning; M6Presentation.Noon; M6Presentation.Dusk; M6Presentation.Night ] + let stated = + periods + |> List.map (fun p -> + let l = M6Presentation.periodLighting p + (p, l.AmbientTint.R, l.AmbientTint.G, l.AmbientTint.B, l.Veil.R, l.Veil.G, l.Veil.B, l.VeilAlpha, l.LanternGlow)) + // 四档两两不同(色调/覆盖色/alpha/灯光至少一项相异)。 + Assert.AreEqual<int>(4, stated |> List.map (fun (_, r, g, b, vr, vg, vb, a, glow) -> (r, g, b, vr, vg, vb, a, glow)) |> List.distinct |> List.length) + // 名称表覆盖全四档。 + let names = periods |> List.map M6Presentation.lightingPeriodName + Assert.AreEqual<int>(4, names |> List.distinct |> List.length) + Assert.IsTrue(names |> List.forall (fun n -> n <> "")) + + [<TestMethod>] + member _.NoonTierIsIdentityAndNightLightsLanterns () = + let noon = M6Presentation.periodLighting M6Presentation.Noon + Assert.AreEqual<int>(255, int noon.AmbientTint.R) + Assert.AreEqual<int>(255, int noon.AmbientTint.G) + Assert.AreEqual<int>(255, int noon.AmbientTint.B) + Assert.AreEqual<int>(0, noon.VeilAlpha) + Assert.AreEqual<float32>(0.0f, noon.LanternGlow) + + let night = M6Presentation.periodLighting M6Presentation.Night + Assert.AreEqual<float32>(1.0f, night.LanternGlow) + let dusk = M6Presentation.periodLighting M6Presentation.Dusk + Assert.IsTrue(dusk.LanternGlow >= 0.3f, "黄昏须开始点亮路灯/灯笼") + + // 实际灯光强度:夜晚点亮,正午熄灭。 + Assert.IsTrue(M6Presentation.effectiveLanternGlow (atHour 22) >= 1.0f) + Assert.AreEqual<float32>(0.0f, M6Presentation.effectiveLanternGlow (atHour 12)) + + [<TestMethod>] + member _.PeriodAtTickMatchesRequestedHoursAndExistingLabels () = + Assert.AreEqual<M6Presentation.M6Period>(M6Presentation.Morning, M6Presentation.periodAtTick (atHour 6)) + Assert.AreEqual<M6Presentation.M6Period>(M6Presentation.Noon, M6Presentation.periodAtTick (atHour 12)) + Assert.AreEqual<M6Presentation.M6Period>(M6Presentation.Dusk, M6Presentation.periodAtTick (atHour 18)) + Assert.AreEqual<M6Presentation.M6Period>(M6Presentation.Night, M6Presentation.periodAtTick (atHour 22)) + // 边界与既有 timePeriodLabel 完全一致:清晨↔清晨、正午↔白天、黄昏↔黄昏、夜晚↔夜晚。 + let expectedLabel period = + match period with + | M6Presentation.Morning -> "清晨" + | M6Presentation.Noon -> "白天" + | M6Presentation.Dusk -> "黄昏" + | M6Presentation.Night -> "夜晚" + for hour in 0 .. 23 do + let label = M6Presentation.timePeriodLabel (atHour hour) + Assert.AreEqual<string>(expectedLabel (M6Presentation.periodAtTick (atHour hour)), label) + // 乘法色调:白色恒等。 + let day = M6Presentation.profileAtTick (atHour 12) + Assert.AreEqual<Color>(day.WorldTint, M6Presentation.multiplyTint day.WorldTint (M6Presentation.periodLighting M6Presentation.Noon).AmbientTint) diff --git a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs index 68e5b93..5da55f1 100644 --- a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs +++ b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs @@ -1100,7 +1100,7 @@ type PrototypeTests () = [<TestMethod>] member _.CjkGlyphAtlasHasAStableCharacterTableAndGeometry () = - Assert.AreEqual<int>(343, characters.Length) + Assert.AreEqual<int>(345, characters.Length) CollectionAssert.AreEqual(characters, characters |> Array.sort) Assert.AreEqual<int>(characters.Length, characters |> Array.distinct |> Array.length) Assert.AreEqual<int>(16, columns) |
