Files
DTrierFlood_New/Assets/FloodSWE/Scripts/Tests/RainFillTest.cs

56 lines
1.5 KiB
C#

using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public sealed class RainFillTest
{
[UnityTest]
public IEnumerator RainFill_AccumulatesAtExpectedRate()
{
if (!SweTestUtils.SupportsGpu)
{
Assert.Ignore("Compute shaders or async GPU readback not supported on this platform.");
}
const float rainRateMmPerHr = 3600.0f;
SweTileSimulator sim = SweTestUtils.CreateSimulator(
gridRes: 32,
tileSizeMeters: 10.0f,
tickSeconds: 0.1f,
damBreak: false,
initialDepthLeft: 0.0f,
initialDepthRight: 0.0f,
rainRateMmPerHr: rainRateMmPerHr);
if (sim == null)
{
Assert.Ignore("Compute shader assets could not be loaded.");
}
yield return null;
float simSeconds = 2.0f;
float endTime = Time.time + simSeconds;
while (Time.time < endTime)
{
yield return null;
}
float expected = (rainRateMmPerHr / 1000.0f / 3600.0f) * simSeconds;
float measured = 0.0f;
yield return SweTestUtils.Readback(sim.debugWater, data =>
{
measured = SweTestUtils.ComputeAverageDepth(data);
});
Object.Destroy(sim.gameObject);
float lower = expected * 0.7f;
float upper = expected * 1.3f;
Assert.That(measured, Is.InRange(lower, upper),
$"Average depth {measured:F6}m outside expected range [{lower:F6}, {upper:F6}]m");
}
}