Files
Chronos/tests/Chronos.App.Tests/Visuals/CurveMathTests.cs
T
Alby96andClaude Opus 5.5 5f27a86406
CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
refactor!: rename Titano to Chronos and move CI and releases to Gitea
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. 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) and
  pe-check.

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>
2026-10-23 11:34:48 +02:00

112 lines
4.8 KiB
C#

using Chronos.Testing;
using Chronos.Ui.Visuals;
namespace Chronos.App.Tests.Visuals;
public sealed class CurveMathTests
{
private const double Gap = CurveMath.DefaultMinGap;
[Test]
public void DraggedPointCannotPassItsNeighbours()
{
double[] xs = [0, 0.3, 0.6, 1];
Assert.Approximately(0.6 - Gap, CurveMath.ConstrainX(xs, 1, 0.9, Gap, pinEnds: true), 1e-12);
Assert.Approximately(0 + Gap, CurveMath.ConstrainX(xs, 1, -0.4, Gap, pinEnds: true), 1e-12);
Assert.Approximately(0.45, CurveMath.ConstrainX(xs, 1, 0.45, Gap, pinEnds: true), 1e-12);
}
[Test]
public void PinnedEndsStayAtZeroAndOne()
{
double[] xs = [0, 0.5, 1];
Assert.Approximately(0, CurveMath.ConstrainX(xs, 0, 0.2, Gap, pinEnds: true), 0);
Assert.Approximately(1, CurveMath.ConstrainX(xs, 2, 0.7, Gap, pinEnds: true), 0);
}
[Test]
public void FreeEndsMoveInsideTheUnitInterval()
{
double[] xs = [0.1, 0.5, 0.9];
Assert.Approximately(0, CurveMath.ConstrainX(xs, 0, -3, Gap, pinEnds: false), 0);
Assert.Approximately(0.5 - Gap, CurveMath.ConstrainX(xs, 0, 0.8, Gap, pinEnds: false), 1e-12);
Assert.Approximately(1, CurveMath.ConstrainX(xs, 2, 4, Gap, pinEnds: false), 0);
}
[Test]
public void AnySequenceOfDragsKeepsXStrictlyIncreasing()
{
var random = new Random(11);
double[] xs = [0, 0.2, 0.4, 0.6, 0.8, 1];
for (var step = 0; step < 10_000; step++)
{
var i = random.Next(xs.Length);
xs[i] = CurveMath.ConstrainX(xs, i, random.NextDouble() * 1.4 - 0.2, Gap, pinEnds: true);
for (var k = 1; k < xs.Length; k++) Assert.True(xs[k] - xs[k - 1] >= Gap - 1e-12, $"x[{k - 1}]={xs[k - 1]} x[{k}]={xs[k]}");
Assert.Approximately(0, xs[0], 0);
Assert.Approximately(1, xs[^1], 0);
}
}
[Test]
public void InsertionKeepsOrderAndRespectsGapAndPins()
{
double[] xs = [0, 0.5, 1];
Assert.Equal(1, CurveMath.InsertionIndex(xs, 0.25, Gap, pinEnds: true));
Assert.Equal(2, CurveMath.InsertionIndex(xs, 0.75, Gap, pinEnds: true));
Assert.Equal(-1, CurveMath.InsertionIndex(xs, 0.5 + Gap / 2, Gap, pinEnds: true));
Assert.Equal(-1, CurveMath.InsertionIndex(xs, 1.2, Gap, pinEnds: false));
double[] free = [0.2, 0.6];
Assert.Equal(0, CurveMath.InsertionIndex(free, 0.1, Gap, pinEnds: false));
Assert.Equal(2, CurveMath.InsertionIndex(free, 0.9, Gap, pinEnds: false));
Assert.Equal(-1, CurveMath.InsertionIndex(free, 0.1, Gap, pinEnds: true));
}
[Test]
public void RemovalKeepsTwoPointsAndPinnedEnds()
{
Assert.False(CurveMath.CanRemove(2, 1, pinEnds: false));
Assert.True(CurveMath.CanRemove(3, 0, pinEnds: false));
Assert.False(CurveMath.CanRemove(3, 0, pinEnds: true));
Assert.True(CurveMath.CanRemove(3, 1, pinEnds: true));
Assert.False(CurveMath.CanRemove(3, 2, pinEnds: true));
}
[Test]
public void KeyboardInsertionUsesThePlayheadWhenAPointFitsThere()
{
double[] xs = [0, 0.4, 1];
Assert.Approximately(0.7, CurveMath.KeyboardInsertionX(xs, 1, 0.7, Gap, pinEnds: true), 0);
// On a point, past a pinned end or unset: the middle of the gap after the selection (before it for the last point).
Assert.Approximately(0.7, CurveMath.KeyboardInsertionX(xs, 1, 0.4, Gap, pinEnds: true), 1e-12);
Assert.Approximately(0.2, CurveMath.KeyboardInsertionX(xs, 0, double.NaN, Gap, pinEnds: true), 1e-12);
Assert.Approximately(0.7, CurveMath.KeyboardInsertionX(xs, 2, double.NaN, Gap, pinEnds: true), 1e-12);
Assert.Approximately(0.2, CurveMath.KeyboardInsertionX(xs, -1, double.NaN, Gap, pinEnds: true), 1e-12);
Assert.Approximately(0.5, CurveMath.KeyboardInsertionX([], -1, double.NaN, Gap, pinEnds: false), 0);
Assert.Approximately(0.6, CurveMath.KeyboardInsertionX([0.2], 0, double.NaN, Gap, pinEnds: false), 1e-12);
}
[Test]
public void InterpolationFollowsTheSegmentsAndIsFlatBeyondTheEnds()
{
double[] xs = [0.2, 0.6, 1];
double[] ys = [0.1, 0.5, 0.3];
Assert.Approximately(0.3, CurveMath.Interpolate(xs, ys, 0.4), 1e-12);
Assert.Approximately(0.4, CurveMath.Interpolate(xs, ys, 0.8), 1e-12);
Assert.Approximately(0.1, CurveMath.Interpolate(xs, ys, 0), 0);
Assert.Approximately(0.3, CurveMath.Interpolate(xs, ys, 1), 0);
Assert.Approximately(0.25, CurveMath.Interpolate([], [], 0.25), 0);
}
[Test]
public void HitTestPicksTheNearestPointWithinRadius()
{
double[] xs = [10, 50, 54];
double[] ys = [10, 10, 10];
Assert.Equal(2, CurveMath.HitTest(xs, ys, 53, 11, 6));
Assert.Equal(1, CurveMath.HitTest(xs, ys, 51, 10, 6));
Assert.Equal(-1, CurveMath.HitTest(xs, ys, 30, 10, 6));
}
}