fix(schedule): keep a requested song first when it is the only one in the slot

With only the requested song before the next news, the ad and moderator
break went in front of it. The swap message then showed the empty break
title and its start time, and the song played later than chosen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-26 09:41:32 +01:00
1 parent 459f8ea7f5
commit 3dcc81cc43
2 files changed
+3 -1

No files matched your search

@@ -194,7 +194,7 @@ public class ScheduleGenerator(ScheduleOptions options, Random random)
var pairs = Math.Max(adPieces.Count, moderatorPieces.Count);
// Hot swap: requested song stays first, breaks start after it.
var firstBreakSong = keepFirstSongFirst && songs.Count > 1 ? 1 : 0;
var firstBreakSong = keepFirstSongFirst ? 1 : 0; // also when it is the only song: breaks then follow it
var breakSlots = Math.Max(songs.Count - firstBreakSong, 1);
var breaks = Math.Min(pairs, breakSlots);
@@ -265,6 +265,8 @@ public class ScheduleGeneratorTests
try { swapped = Generator(seed).Replace(plan, index, Request, Library); }
catch (ScheduleException) { continue; } // too little time left before the news
// Also when only the requested song fits: breaks go after it, not before.
Assert.Equal(Request, swapped[index].Song);
Assert.Equal(plan[^1].End, swapped[^1].End);
for (var i = 1; i < swapped.Count; i++)
Assert.False(swapped[i - 1].Kind == ScheduleItemKind.Ad && swapped[i].Kind == ScheduleItemKind.Ad,