diff --git a/src/Radiosender/Services/Scheduling/ScheduleGenerator.cs b/src/Radiosender/Services/Scheduling/ScheduleGenerator.cs index aa9f248..5e71a20 100644 --- a/src/Radiosender/Services/Scheduling/ScheduleGenerator.cs +++ b/src/Radiosender/Services/Scheduling/ScheduleGenerator.cs @@ -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); diff --git a/tests/Radiosender.Tests/ScheduleGeneratorTests.cs b/tests/Radiosender.Tests/ScheduleGeneratorTests.cs index 0ffe45c..226b904 100644 --- a/tests/Radiosender.Tests/ScheduleGeneratorTests.cs +++ b/tests/Radiosender.Tests/ScheduleGeneratorTests.cs @@ -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,