0.94.0: PPV Sunday on Ring X (opt-in event films, one a night, near 19:00)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.time.DayOfWeek
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
/** Ring X's PPV Sunday: one curated event each Sunday near 19:00, run to its end, every event once before any repeats. */
|
||||
class PpvSundayTest {
|
||||
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 ringX = SmartChannels.first { it.number == 401 }
|
||||
private fun show(title: String, count: Int, minutes: Long) = PoolSeries("s" + title.hashCode().toUInt(), title, (1..count).map {
|
||||
PoolEpisode("e${title.hashCode().toUInt()}-$it", "src", EpisodeMark(1, it), "E$it", (minutes + it % 3) * minute) })
|
||||
private fun event(i: Int, title: String, minutes: Long) = PoolSeries("ppv$i", FilmIdentity.of(title).title, listOf(PoolEpisode("ppv$i", "src$i", EpisodeMark(1, 1), title, minutes * minute)))
|
||||
// Ring X's real show names with typical lengths, and the 52 events with their catalogue runtimes.
|
||||
private val shows = listOf(show("WWE Raw", 300, 96), show("WCW Monday Nitro", 200, 100), show("IMPACT! Wrestling", 300, 86), show("All Elite Wrestling: Dynamite", 200, 113),
|
||||
show("WWE SmackDown", 300, 84), show("WCW Thunder", 150, 86), show("ECW Hardcore TV", 300, 50), show("Ring of Honor (2002) [imdb-] [tvdb-386985]", 150, 60),
|
||||
show("WWF Prime Time Wrestling", 195, 90), show("WWE Heat", 300, 45), show("WCW Clash of the Champions", 35, 90), show("WCW Saturday Night", 300, 84),
|
||||
show("WWE Main Event", 300, 45), show("WWE NXT", 300, 59), show("Hulk Hogan's Rock 'n' Wrestling", 26, 22), show("Dark Side of the Ring", 69, 44), show("WWE Rivals", 42, 45))
|
||||
private val library = JSONArray(javaClass.classLoader!!.getResource("ppv-sunday-library.json")!!.readText())
|
||||
private val events = PpvSunday.mapIndexed { i, entry ->
|
||||
val runtime = library.getJSONObject(i).getJSONArray("library").let { l -> (0 until l.length()).map { l.getJSONObject(it) } }
|
||||
.first { FilmIdentity.of(entry).year == null || it.optInt("year") == FilmIdentity.of(entry).year }.getLong("ms") / minute
|
||||
event(i, entry, runtime.coerceAtLeast(60))
|
||||
}
|
||||
private fun plan(pool: List<PoolSeries>, cursor: ScheduleCursor = ScheduleCursor(), from: Long = monday, until: Long = monday + 8 * week) =
|
||||
extendSchedule(pool, cursor, from, until, finishTogether = true, dayParts = ringX.dayParts, zone = zone)
|
||||
private fun local(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(zone)
|
||||
|
||||
@Test fun everyEventResolvesToItsExactIdentityInTheLibrary() {
|
||||
assertEquals(52, PpvSunday.size)
|
||||
assertEquals(52, PpvSunday.map { seriesKey(FilmIdentity.of(it).title) to FilmIdentity.of(it).year }.distinct().size)
|
||||
for (i in 0 until library.length()) {
|
||||
val row = library.getJSONObject(i)
|
||||
val candidates = row.getJSONArray("library").let { l -> (0 until l.length()).map { l.getJSONObject(it) } }.map {
|
||||
FilmCandidate(it.getString("id"), it.getString("name"), it.optInt("year").takeIf { y -> y > 0 }, it.optString("imdb").takeIf { s -> s.startsWith("tt") },
|
||||
listOf(org.json.JSONObject().put("Id", "src" + it.getString("id")).put("Container", "mkv")), 120 * minute * 10_000)
|
||||
}
|
||||
val found = resolveFilm(FilmIdentity.of(row.getString("entry")), candidates)
|
||||
assertNotNull(row.getString("entry") + ": " + found.note, found.film)
|
||||
if (!row.isNull("imdb")) assertEquals(row.getString("entry"), row.getString("imdb"), candidates.first { it.id == found.film!!.id }.imdb)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun oneEventEachSundayNearSevenRunToItsEnd() {
|
||||
val result = plan(shows + events)
|
||||
val ppv = result.entries.filter { it.seriesId.startsWith("ppv") }
|
||||
assertEquals(8, ppv.size)
|
||||
ppv.forEach { e ->
|
||||
val t = local(e.startMs)
|
||||
assertEquals(DayOfWeek.SUNDAY, t.dayOfWeek)
|
||||
assertTrue("starts near 19:00: $t", t.hour == 19 && t.minute <= 20)
|
||||
assertEquals(events.first { it.id == e.seriesId }.episodes.first().durationMs, e.media.durationMs)
|
||||
}
|
||||
assertTrue(result.entries.zipWithNext().all { (a, b) -> a.endMs == b.startMs })
|
||||
}
|
||||
|
||||
@Test fun eventsRotateInListOrderAcrossRestarts() {
|
||||
val first = plan(shows + events, until = monday + 3 * week)
|
||||
val store = ScheduleStore(kotlin.io.path.createTempDirectory().toFile())
|
||||
store.savePlan("u", 401, first)
|
||||
val again = plan(shows + events, store.loadPlan("u", 401)!!.tail, from = first.endMs, until = first.endMs + 3 * week)
|
||||
val aired = (first.entries + again.entries).filter { it.seriesId.startsWith("ppv") }.map { it.seriesId.removePrefix("ppv").toInt() }
|
||||
assertEquals((0 until aired.size).toList(), aired)
|
||||
}
|
||||
|
||||
@Test fun noEventsMeansAnOrdinarySundayWithNoGap() {
|
||||
val result = plan(shows)
|
||||
assertTrue(result.entries.zipWithNext().all { (a, b) -> a.endMs == b.startMs })
|
||||
assertTrue(result.entries.none { it.media.item.type == "Movie" })
|
||||
}
|
||||
|
||||
@Test fun eventsNeverAirOutsideTheirSundayWindow() {
|
||||
plan(shows + events).entries.filter { it.seriesId.startsWith("ppv") }.forEach { assertEquals(19, local(it.startMs).hour) }
|
||||
}
|
||||
|
||||
@Test fun theShowThatFitsIsNotAlwaysTheSameOne() {
|
||||
val before = plan(shows + events).entries.filter { "chosen to finish before" in it.why }.map { it.seriesId }
|
||||
assertTrue("fitted shows: $before", before.distinct().size > 1)
|
||||
}
|
||||
|
||||
@Test fun onlyRingXCarriesFilmsInAnEvent() {
|
||||
assertEquals(listOf(401), SmartChannels.filter { it.channelFilms.isNotEmpty() }.map { it.number })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user