59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System.Collections;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
public sealed class DamBreakTest
|
|
{
|
|
private const float Gravity = 9.81f;
|
|
|
|
[UnityTest]
|
|
public IEnumerator DamBreak_WaveFrontAdvances()
|
|
{
|
|
if (!SweTestUtils.SupportsGpu)
|
|
{
|
|
Assert.Ignore("Compute shaders or async GPU readback not supported on this platform.");
|
|
}
|
|
|
|
SweTileSimulator sim = SweTestUtils.CreateSimulator(
|
|
gridRes: 64,
|
|
tileSizeMeters: 20.0f,
|
|
tickSeconds: 0.1f,
|
|
damBreak: true,
|
|
initialDepthLeft: 1.0f,
|
|
initialDepthRight: 0.0f,
|
|
rainRateMmPerHr: 0.0f);
|
|
|
|
if (sim == null)
|
|
{
|
|
Assert.Ignore("Compute shader assets could not be loaded.");
|
|
}
|
|
|
|
yield return null;
|
|
|
|
float simSeconds = 1.0f;
|
|
float endTime = Time.time + simSeconds;
|
|
while (Time.time < endTime)
|
|
{
|
|
yield return null;
|
|
}
|
|
|
|
float dx = sim.tileSizeMeters / sim.gridRes;
|
|
float expectedFront = 2.0f * Mathf.Sqrt(Gravity * sim.initialDepthLeft) * simSeconds;
|
|
float measuredFront = 0.0f;
|
|
|
|
yield return SweTestUtils.Readback(sim.debugWater, data =>
|
|
{
|
|
measuredFront = SweTestUtils.ComputeFrontDistance(data, sim.gridRes, dx, threshold: 0.005f);
|
|
});
|
|
|
|
Object.Destroy(sim.gameObject);
|
|
|
|
float tolerance = Mathf.Max(dx * 2.0f, expectedFront * 0.35f);
|
|
float lower = Mathf.Max(0.0f, expectedFront - tolerance);
|
|
float upper = expectedFront + tolerance;
|
|
Assert.That(measuredFront, Is.InRange(lower, upper),
|
|
$"Wave front distance {measuredFront:F3}m outside expected range [{lower:F3}, {upper:F3}]m");
|
|
}
|
|
}
|