0.92.0: Joe Bob Saturdays (opt-in series on a film channel, After Dark only)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m52s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m24s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-03 15:04:25 +00:00
co-authored by Claude Opus 5.5
parent 1449628890
commit 06912c33a1
10 changed files with 141 additions and 12 deletions
@@ -0,0 +1,68 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
import java.time.ZoneId
import java.time.ZonedDateTime
/** After Dark carrying The Last Drive-In: one whole hosted episode each Saturday night, in order, and never as a film. */
class LastDriveInTest {
private val zone = ZoneId.of("Europe/London")
private val minute = 60_000L
private val week = 7 * 24 * 60 * minute
private val monday = ZonedDateTime.of(2026, 11, 9, 0, 0, 0, 0, zone).toInstant().toEpochMilli()
private val after = SmartChannels.first { it.number == AFTER_DARK_NUMBER }
private fun film(i: Int, minutes: Long = 95) = PoolSeries("film$i", "Film $i", listOf(PoolEpisode("film$i", "src$i", EpisodeMark(1, 1), "Film $i", minutes * minute)))
private val films = (1..60).map { film(it, 85L + it % 40) }
private val joeBob = PoolSeries("joebob", LAST_DRIVE_IN, (1..13).map { PoolEpisode("jb$it", "jbsrc$it", EpisodeMark(1, it), "Episode $it", (120L + it * 4) * minute) })
private fun plan(pool: List<PoolSeries>, cursor: ScheduleCursor = ScheduleCursor(), from: Long = monday, until: Long = monday + 3 * week) =
extendSchedule(pool, cursor, from, until, after.filmRestMs, dayParts = after.dayParts, zone = zone)
private fun local(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(zone)
@Test fun oneWholeEpisodeEachSaturdayInOrder() {
val episodes = plan(films + joeBob).entries.filter { it.seriesId == "joebob" }
assertEquals(listOf(1, 2, 3), episodes.map { it.mark.episode })
episodes.forEach { e ->
val start = local(e.startMs)
assertEquals(java.time.DayOfWeek.SATURDAY, start.dayOfWeek)
assertTrue("starts in the first slot after 20:00, so around 21:00: $start", start.hour in 20..21)
assertEquals("played whole", joeBob.episodes[e.mark.episode - 1].durationMs, e.media.durationMs)
}
}
@Test fun neverInTheOrdinaryFilmRotationAndNeverCountedAsAFilmScreening() {
val result = plan(films + joeBob)
val outside = result.entries.filter { it.seriesId == "joebob" && local(it.startMs).dayOfWeek != java.time.DayOfWeek.SATURDAY }
assertTrue(outside.isEmpty())
assertTrue(result.entries.filter { it.seriesId == "joebob" }.all { it.media.item.type == "Episode" })
}
@Test fun theNextWeekCarriesOnAfterARestart() {
val first = plan(films + joeBob, until = monday + week)
val store = ScheduleStore(kotlin.io.path.createTempDirectory().toFile())
store.savePlan("u", AFTER_DARK_NUMBER, first)
val restored = store.loadPlan("u", AFTER_DARK_NUMBER)!!
val next = plan(films + joeBob, restored.tail, from = first.endMs, until = first.endMs + week)
assertEquals(listOf(2), next.entries.filter { it.seriesId == "joebob" }.map { it.mark.episode })
}
@Test fun withoutTheSeriesSaturdayNightIsFilmsWithNoGap() {
val result = plan(films)
assertTrue(result.entries.zipWithNext().all { (a, b) -> a.endMs == b.startMs })
assertTrue(result.entries.all { it.media.item.type == "Movie" })
}
@Test fun aFilmRunningPastNineStillLeadsIntoTheEpisode() {
// A long film before the window: the episode starts when it ends, still on Saturday night.
val long = PoolSeries("long", "Long Film", listOf(PoolEpisode("long", "srclong", EpisodeMark(1, 1), "Long Film", 200 * minute)))
val saturdayEvening = ZonedDateTime.of(2026, 11, 14, 19, 30, 0, 0, zone).toInstant().toEpochMilli()
val result = extendSchedule(listOf(long) + joeBob, ScheduleCursor(), saturdayEvening, saturdayEvening + 12 * 60 * minute, after.filmRestMs, dayParts = after.dayParts, zone = zone)
val episode = result.entries.first { it.seriesId == "joebob" }
assertEquals(result.entries.first().endMs, episode.startMs)
assertEquals(1, result.entries.count { it.seriesId == "joebob" })
}
@Test fun onlyAfterDarkCarriesASeries() {
assertEquals(listOf(AFTER_DARK_NUMBER), SmartChannels.filter { it.filmSeries.isNotEmpty() }.map { it.number })
}
}