Build Orbit Drive-In with real events and three scenes (0.67.0)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m51s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m28s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-02 12:05:43 +00:00
co-authored by Claude Opus 5.5
parent dfb729ca86
commit 089b934e48
24 changed files with 563 additions and 22 deletions
@@ -0,0 +1,102 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
import java.time.DayOfWeek
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime
class DriveInTest {
private val london = ZoneId.of("Europe/London")
private val hour = 60 * 60_000L
private fun film(title: String, hours: Long = 2) = title.replace(Regex("[^A-Za-z0-9]"), "").let { id -> PoolSeries(id, title, listOf(PoolEpisode(id, "s$id", EpisodeMark(1, 1), title, hours * hour))) }
private fun at(day: Int, h: Int, m: Int = 0) = ZonedDateTime.of(2026, 11, day, h, m, 0, 0, london).toInstant().toEpochMilli()
private val big = (1..30).map { film("Big $it") }
private val late = (1..30).map { film("Late $it") }
private val bills = listOf(film("Alien"), film("Aliens"), film("Back to the Future"), film("Back to the Future Part II"), film("Back to the Future Part III"))
private fun local(ms: Long) = Instant.ofEpochMilli(ms).atZone(london)
@Test fun fridayIsADoubleBillAndSaturdayATriple() {
val plan = planDriveIn(null, big, late, bills, at(2, 10), london)!!
val all = driveInBills(plan, london)
val double = all.first { it.kind == DriveInKind.Double }
assertEquals(DayOfWeek.FRIDAY, local(double.startMs).dayOfWeek)
assertEquals(20, local(double.startMs).hour)
assertEquals(listOf("Alien", "Aliens"), double.films)
val triple = all.first { it.kind == DriveInKind.Triple }
assertEquals(DayOfWeek.SATURDAY, local(triple.startMs).dayOfWeek)
assertEquals(19, local(triple.startMs).hour)
assertEquals(3, triple.films.size)
}
@Test fun otherNightsHaveAMarqueeThenALateShowWithNoOverlap() {
val plan = planDriveIn(null, big, late, bills, at(2, 10), london)!!
val monday = driveInBills(plan, london).filter { it.startMs in at(2, 6)..at(3, 5) }
assertEquals(listOf(DriveInKind.Marquee, DriveInKind.LateShow), monday.map { it.kind })
assertEquals(20, local(monday[0].startMs).hour)
assertEquals(23, local(monday[1].startMs).hour)
plan.entries.zipWithNext { a, b -> assertTrue(a.endMs <= b.startMs) }
}
@Test fun aLongFeaturePushesTheLateShowBack() {
val plan = planDriveIn(null, listOf(film("Epic", 4), film("Epic Two", 4)), late, bills, at(2, 10), london)!!
val monday = driveInBills(plan, london).filter { it.startMs in at(2, 6)..at(3, 5) }
assertEquals(at(3, 0, 15), monday[1].startMs)
}
@Test fun whatIsBookedStaysBooked() {
val first = planDriveIn(null, big, late, bills, at(2, 10), london)!!
val later = planDriveIn(first, big, late, bills, at(3, 10), london)!!
val kept = first.entries.filter { it.endMs >= at(3, 10) - SCHEDULE_KEEP_PAST_MS }
assertEquals(kept.map { it.media.item.id to it.startMs }, later.entries.take(kept.size).map { it.media.item.id to it.startMs })
assertTrue(later.endMs > first.endMs)
}
@Test fun nothingNewIsNeededOnceAWeekIsBooked() {
val first = planDriveIn(null, big, late, bills, at(2, 10), london)!!
assertTrue(driveInBookedAhead(first, at(2, 11), london))
assertFalse(driveInBookedAhead(first, at(3, 11), london))
assertFalse(driveInBookedAhead(null, at(2, 11), london))
}
@Test fun aBillWithAFilmMissingGivesWayToAMarquee() {
val plan = planDriveIn(null, big, late, listOf(film("Alien")), at(2, 10), london)!!
assertTrue(driveInBills(plan, london).none { it.kind == DriveInKind.Double || it.kind == DriveInKind.Triple })
}
@Test fun aBillAvoidsAFilmOnAnotherChannelAtTheSameTime() {
val clash: ProgrammeClash = { show, _, _ -> show.title == "Aliens" }
val plan = planDriveIn(null, big, late, bills, at(2, 10), london, clash)!!
assertTrue(plan.entries.none { it.media.item.title == "Aliens" })
}
@Test fun anEmptyLibraryBooksNothing() {
assertNull(planDriveIn(null, emptyList(), late, bills, at(2, 10), london))
}
@Test fun theLineupIsTheNextOfEachKind() {
val plan = planDriveIn(null, big, late, bills, at(2, 10), london)!!
val lineup = driveInLineup(driveInBills(plan, london), at(2, 10))
assertEquals(DriveInKind.values().toList(), lineup.map { it.kind })
}
@Test fun dayNamesCountTheSmallHoursAsTheNightBefore() {
val plan = planDriveIn(null, big, late, bills, at(2, 10), london)!!
val tonight = driveInBills(plan, london).first { it.kind == DriveInKind.Marquee }
assertEquals("Tonight", driveInDay(tonight, at(2, 10), london))
assertEquals("Now showing", driveInDay(tonight, tonight.startMs, london))
assertEquals("Tonight", driveInDay(tonight, at(2, 19), london))
}
@Test fun airingIsFalseBetweenShows() {
val plan = planDriveIn(null, big, late, bills, at(2, 10), london)!!
assertTrue(driveInAiring(plan, at(2, 21)))
assertFalse(driveInAiring(plan, at(2, 15)))
assertNotNull(driveInChannel(plan))
}
@Test fun theDriveInIsBranded() {
assertEquals("Orbit Drive-In", ChannelBrands.forNumber(DRIVE_IN_NUMBER)!!.displayName)
}
}