test: log solar and LOWESS deviations, cover domain-frame analysis
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+29
-14
No files matched your search
@@ -59,6 +59,11 @@ public sealed class LightAnalyzerTests(TestContext context)
|
||||
Assert.Equal(FindingSeverity.Warning, gaps.Severity);
|
||||
Assert.Equal(3, (int)gaps.Arguments[0]);
|
||||
Assert.Approximately(7210, (double)gaps.Arguments[1], 1e-9);
|
||||
|
||||
// Domain frames (no camera or GPS fields) give the same timing and exposure analysis.
|
||||
var fromFrames = LightAnalyzer.Analyze(Timeline().Frames);
|
||||
Assert.SequenceEqual(report.Intervals, fromFrames.Intervals);
|
||||
Assert.SequenceEqual(report.ExposureSteps.Select(s => s.Index), fromFrames.ExposureSteps.Select(s => s.Index));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Globalization;
|
||||
using Titano.Core.Mathematics;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Mathematics;
|
||||
|
||||
public sealed class LocalRegressionTests
|
||||
public sealed class LocalRegressionTests(TestContext context)
|
||||
{
|
||||
[Theory]
|
||||
[Case(1)]
|
||||
@@ -46,6 +47,8 @@ public sealed class LocalRegressionTests
|
||||
var robustShift = Enumerable.Range(0, n).Max(i => Math.Abs(robust.Fitted[i] - reference.Fitted[i]));
|
||||
var plainShift = Enumerable.Range(0, n).Max(i => Math.Abs(plain.Fitted[i] - reference.Fitted[i]));
|
||||
var robustError = Enumerable.Range(0, n).Max(i => Math.Abs(robust.Fitted[i] - truth[i]));
|
||||
context.Log(string.Create(CultureInfo.InvariantCulture,
|
||||
$"20 % outliers: robust fit moved {robustShift:F4} (error vs truth {robustError:F4}), non-robust fit moved {plainShift:F4}"));
|
||||
Assert.Less(robustShift, 0.03, "robust fit moved by the outliers");
|
||||
Assert.Less(robustError, 0.04);
|
||||
Assert.Greater(plainShift, 10 * robustShift);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Titano.Core.Tests.Mathematics;
|
||||
/// Reference values are NOAA Solar Calculator results (spreadsheet equations as implemented by the
|
||||
/// <c>astral</c> package, cross-checked against PyEphem/VSOP87 to within 35 s), UTC, for the local solar day.
|
||||
/// </summary>
|
||||
public sealed class SolarPositionTests
|
||||
public sealed class SolarPositionTests(TestContext context)
|
||||
{
|
||||
private const double OneMinute = 60;
|
||||
|
||||
@@ -29,14 +29,18 @@ public sealed class SolarPositionTests
|
||||
{
|
||||
var day = DateOnly.ParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
|
||||
var events = SolarPosition.Events(day, latitude, longitude);
|
||||
Check(place + " sunrise", day, sunrise, events.Sunrise);
|
||||
Check(place + " sunset", day, sunset, events.Sunset);
|
||||
Check(place + " civil dawn", day, civilDawn, events.CivilDawn);
|
||||
Check(place + " civil dusk", day, civilDusk, events.CivilDusk);
|
||||
Check(place + " nautical dawn", day, nauticalDawn, events.NauticalDawn);
|
||||
Check(place + " nautical dusk", day, nauticalDusk, events.NauticalDusk);
|
||||
Check(place + " astronomical dawn", day, astroDawn, events.AstronomicalDawn);
|
||||
Check(place + " astronomical dusk", day, astroDusk, events.AstronomicalDusk);
|
||||
double[] deviations =
|
||||
[
|
||||
Check(place + " sunrise", day, sunrise, events.Sunrise),
|
||||
Check(place + " sunset", day, sunset, events.Sunset),
|
||||
Check(place + " civil dawn", day, civilDawn, events.CivilDawn),
|
||||
Check(place + " civil dusk", day, civilDusk, events.CivilDusk),
|
||||
Check(place + " nautical dawn", day, nauticalDawn, events.NauticalDawn),
|
||||
Check(place + " nautical dusk", day, nauticalDusk, events.NauticalDusk),
|
||||
Check(place + " astronomical dawn", day, astroDawn, events.AstronomicalDawn),
|
||||
Check(place + " astronomical dusk", day, astroDusk, events.AstronomicalDusk),
|
||||
];
|
||||
context.Log(string.Create(CultureInfo.InvariantCulture, $"{place}: worst deviation {deviations.Max():F1} s"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -87,18 +91,21 @@ public sealed class SolarPositionTests
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => SolarPosition.Compute(DateTime.UtcNow, 91, 0));
|
||||
}
|
||||
|
||||
/// <summary>Expected "HH:mm:ss" on <paramref name="day"/>; a leading '-' or '+' means the previous or next UTC day.</summary>
|
||||
private static void Check(string label, DateOnly day, string? expected, DateTime? actual)
|
||||
/// <summary>Expected "HH:mm:ss" on <paramref name="day"/>; a leading '-' or '+' means the previous or next UTC day.
|
||||
/// Returns the absolute deviation in seconds (0 when the event is correctly absent).</summary>
|
||||
private static double Check(string label, DateOnly day, string? expected, DateTime? actual)
|
||||
{
|
||||
if (expected is null)
|
||||
{
|
||||
Assert.Null(actual);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
var offsetDays = expected[0] switch { '-' => -1, '+' => 1, _ => 0 };
|
||||
var clock = TimeOnly.ParseExact(expected.TrimStart('+', '-'), "HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
var reference = day.AddDays(offsetDays).ToDateTime(clock, DateTimeKind.Utc);
|
||||
var value = Assert.NotNull(actual, label);
|
||||
Assert.Approximately(0, (value - reference).TotalSeconds, OneMinute, label);
|
||||
var deviation = (value - reference).TotalSeconds;
|
||||
Assert.Approximately(0, deviation, OneMinute, label);
|
||||
return Math.Abs(deviation);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user