Files
Chronos/tests/Chronos.Core.Tests/Analysis/AnalysisPropertyTests.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

94 lines
4.5 KiB
C#

using Chronos.Core.Analysis;
using Chronos.Testing;
namespace Chronos.Core.Tests.Analysis;
/// <summary>Seeded random inputs: outputs stay finite where defined and repeat exactly.</summary>
public sealed class AnalysisPropertyTests
{
private static double[] RandomSeries(Random random, int n, double missing)
{
var level = 0.0;
var series = new double[n];
for (var i = 0; i < n; i++)
{
level += 0.05 * (random.NextDouble() - 0.5);
series[i] = random.NextDouble() < missing ? double.NaN : level + 0.3 * (random.NextDouble() - 0.5) + (random.NextDouble() < 0.03 ? 4 : 0);
}
return series;
}
[Test]
public void DeflickerHolyGrailAndSpectrumAreFiniteAndDeterministic()
{
var random = new Random(1234);
for (var trial = 0; trial < 25; trial++)
{
var n = 2 + random.Next(300);
var series = RandomSeries(random, n, missing: 0.1);
if (series.All(double.IsNaN)) series[0] = 0;
var ev = new double?[n];
double camera = 12;
for (var i = 0; i < n; i++)
{
if (random.NextDouble() < 0.05) camera -= Math.Round(random.NextDouble() * 6 - 3) / 3;
ev[i] = random.NextDouble() < 0.05 ? null : camera;
}
var options = new DeflickerOptions { Window = 3 + random.Next(40), Degree = 1 + random.Next(2), Strength = random.NextDouble() };
var a = DeflickerEngine.Compute(series, options);
var b = DeflickerEngine.Compute(series, options);
Assert.True(a.Target.All(double.IsFinite) && a.CorrectionEv.All(double.IsFinite), $"deflicker trial {trial}");
Assert.SequenceEqual(a.Target, b.Target);
var grail = HolyGrailEngine.Compute(series, ev, new HolyGrailOptions { Deflicker = options });
Assert.True(grail.Target.All(double.IsFinite) && grail.CorrectionEv.All(double.IsFinite), $"holy grail trial {trial}");
Assert.SequenceEqual(grail.Target, HolyGrailEngine.Compute(series, ev, new HolyGrailOptions { Deflicker = options }).Target);
var spectrum = FlickerSpectrum.Analyze(series);
Assert.True(spectrum.Autocorrelation.All(double.IsFinite));
Assert.Equal(1, spectrum.RecommendedWindow % 2);
var region = RegionDeflicker.Compute(series, RandomSeries(random, n, 0.2), options);
Assert.True(region.Land.CorrectionEv.All(double.IsFinite));
}
}
[Test]
public void WhiteBalanceAndLightAnalysisSurviveRandomMetadata()
{
var random = new Random(77);
for (var trial = 0; trial < 20; trial++)
{
var n = 1 + random.Next(200);
double Channel() => random.NextDouble() < 0.05 ? 0 : 0.01 + random.NextDouble();
var red = Enumerable.Range(0, n).Select(_ => Channel()).ToArray();
var green = Enumerable.Range(0, n).Select(_ => Channel()).ToArray();
var blue = Enumerable.Range(0, n).Select(_ => Channel()).ToArray();
var wb = WhiteBalanceSmoother.Smooth(red, green, blue, window: 1 + random.Next(40));
Assert.True(wb.Gains.All(g => double.IsFinite(g.Red) && g.Red > 0 && double.IsFinite(g.Blue) && g.Blue > 0), $"wb trial {trial}");
var start = new DateTime(2024, 1, 1);
var frames = Enumerable.Range(0, n).Select(i => new LightFrame
{
Index = i,
CapturedAt = random.NextDouble() < 0.05 ? null : start.AddSeconds(i * 7 + random.Next(-20, 20) + (random.NextDouble() < 0.02 ? 9000 : 0)),
ExposureTime = random.NextDouble() < 0.05 ? null : 1.0 / (1 + random.Next(3)),
FNumber = 2.8,
Iso = random.NextDouble() < 0.5 ? 100 : null,
Width = 100 + random.Next(2),
Height = 80,
Orientation = random.NextDouble() < 0.05 ? 6 : 1,
Latitude = random.NextDouble() < 0.5 ? -60 + 120 * random.NextDouble() : null,
Longitude = 170 * (random.NextDouble() - 0.5),
}).ToList();
var first = LightAnalyzer.Analyze(frames);
var second = LightAnalyzer.Analyze(frames);
Assert.SequenceEqual(first.Intervals, second.Intervals);
Assert.SequenceEqual(first.Findings.Select(f => f.Key), second.Findings.Select(f => f.Key));
Assert.Equal(n, first.Sessions.Sum(s => s.FrameCount));
Assert.True(first.CaptureSpan >= TimeSpan.Zero);
}
}
}