From 1b0c979308743cc0973623156d2c5135814d5d74 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 09:56:27 +0000 Subject: [PATCH] test: log solar and LOWESS deviations, cover domain-frame analysis Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- .../Analysis/LightAnalyzerTests.cs | 5 +++ .../Math/LocalRegressionTests.cs | 5 ++- .../Math/SolarPositionTests.cs | 33 +++++++++++-------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/tests/Titano.Core.Tests/Analysis/LightAnalyzerTests.cs b/tests/Titano.Core.Tests/Analysis/LightAnalyzerTests.cs index 5873ce17..75cdb54b 100644 --- a/tests/Titano.Core.Tests/Analysis/LightAnalyzerTests.cs +++ b/tests/Titano.Core.Tests/Analysis/LightAnalyzerTests.cs @@ -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] diff --git a/tests/Titano.Core.Tests/Math/LocalRegressionTests.cs b/tests/Titano.Core.Tests/Math/LocalRegressionTests.cs index 66b7d158..194b6724 100644 --- a/tests/Titano.Core.Tests/Math/LocalRegressionTests.cs +++ b/tests/Titano.Core.Tests/Math/LocalRegressionTests.cs @@ -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); diff --git a/tests/Titano.Core.Tests/Math/SolarPositionTests.cs b/tests/Titano.Core.Tests/Math/SolarPositionTests.cs index a81f514b..306b14ca 100644 --- a/tests/Titano.Core.Tests/Math/SolarPositionTests.cs +++ b/tests/Titano.Core.Tests/Math/SolarPositionTests.cs @@ -8,7 +8,7 @@ namespace Titano.Core.Tests.Mathematics; /// Reference values are NOAA Solar Calculator results (spreadsheet equations as implemented by the /// astral package, cross-checked against PyEphem/VSOP87 to within 35 s), UTC, for the local solar day. /// -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(() => SolarPosition.Compute(DateTime.UtcNow, 91, 0)); } - /// Expected "HH:mm:ss" on ; a leading '-' or '+' means the previous or next UTC day. - private static void Check(string label, DateOnly day, string? expected, DateTime? actual) + /// Expected "HH:mm:ss" on ; a leading '-' or '+' means the previous or next UTC day. + /// Returns the absolute deviation in seconds (0 when the event is correctly absent). + 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); } }