Files
Chronos/tests/Titano.Core.Tests/Import/SessionSplitterTests.cs
T
Claude 8cb9672520 feat(core): card import planning and verified copy engine
Card scanning (DCIM and flat), session splitting with test-shot merging and
user splits/merges, per-body import plans named by templates with archive
duplicate detection, hash-verified resumable copy with per-file errors, a
plain-folder destination and a verified card erase with dry run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 12:30:14 +00:00

74 lines
3.0 KiB
C#

using Titano.Core.Import;
using Titano.Testing;
namespace Titano.Core.Tests.Import;
[Category("import")]
public sealed class SessionSplitterTests
{
private static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0);
private static readonly TimeSpan Gap = TimeSpan.FromMinutes(45);
/// <summary>Capture times from a compact description: runs of frames 10 s apart, separated by pauses in minutes.</summary>
private static List<DateTime> Times(params (int Frames, int PauseBeforeMinutes)[] runs)
{
var times = new List<DateTime>();
var t = Start;
foreach (var (frames, pause) in runs)
{
t = t.AddMinutes(pause);
for (var i = 0; i < frames; i++)
{
times.Add(t);
t = t.AddSeconds(10);
}
}
return times;
}
private static string Describe(IReadOnlyList<SessionRange> ranges) => string.Join(",", ranges.Select(r => r.Count));
[Theory]
[Case(new[] { 30 }, new[] { 0 }, "30", Name = "one session")]
[Case(new[] { 30, 40 }, new[] { 0, 60 }, "30,40", Name = "pause longer than the gap splits")]
[Case(new[] { 30, 40 }, new[] { 0, 44 }, "70", Name = "pause shorter than the gap does not")]
[Case(new[] { 3, 30 }, new[] { 0, 90 }, "33", Name = "leading test shots join the next session")]
[Case(new[] { 30, 3 }, new[] { 0, 90 }, "33", Name = "trailing test shots join the previous session")]
[Case(new[] { 30, 2, 30 }, new[] { 0, 90, 90 }, "32,30", Name = "small middle group joins the previous session")]
[Case(new[] { 2, 3 }, new[] { 0, 90 }, "5", Name = "only small groups make one session")]
public void AutomaticSessions(int[] frames, int[] pauses, string expected)
{
var times = Times(frames.Zip(pauses).ToArray());
Assert.Equal(expected, Describe(SessionSplitter.Split(times, Gap, 8)));
}
[Test]
public void APauseOfExactlyTheGapDoesNotSplit()
{
var times = new List<DateTime> { Start };
for (var i = 1; i < 10; i++) times.Add(Start.AddSeconds(i));
for (var i = 0; i < 10; i++) times.Add(times[9] + Gap + TimeSpan.FromSeconds(i));
Assert.Equal("20", Describe(SessionSplitter.Split(times, Gap, 8)));
}
[Test]
public void UserSplitsAndMergesOverrideTheRules()
{
var times = Times((30, 0), (40, 60));
// Split before frame 25 (a 5-frame group the user wants on its own) and merge the automatic break at 30.
var ranges = SessionSplitter.Split(times, Gap, 8, i => i == 25 ? true : i == 30 ? false : null);
Assert.Equal("25,45", Describe(ranges));
Assert.Equal(25, ranges[1].Start);
}
[Test]
public void AForcedSmallSessionIsNotMergedAway()
{
var times = Times((30, 0));
Assert.Equal("28,2", Describe(SessionSplitter.Split(times, Gap, 8, i => i == 28 ? true : null)));
}
[Test]
public void NoFramesNoSessions() => Assert.Empty(SessionSplitter.Split([], Gap, 8));
}