Add film rotation, Terra and After Dark, guide day jump and clearer switch (0.40.0, Phase B in testing)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -220,4 +220,80 @@ class ChannelScheduleTest {
|
||||
assertEquals("", guideDayPrefix(now, now))
|
||||
assertTrue(guideDayPrefix(now + 3 * day, now).isNotEmpty())
|
||||
}
|
||||
|
||||
private fun film(id: String, minutes: Long = 100) = PoolSeries(id, "Film $id", listOf(PoolEpisode(id, "src-$id", EpisodeMark(1, 1), "Film $id", minutes * minute)))
|
||||
private val films = (1..40).map { film("f$it", 80L + it) }
|
||||
private val rest = 48 * 60 * minute
|
||||
|
||||
@Test fun filmsKeepTheirRestPeriodWhenThePoolAllowsIt() {
|
||||
val entries = extendSchedule(films, ScheduleCursor(), now, now + 7 * day, rest).entries
|
||||
entries.groupBy { it.seriesId }.values.forEach { showings ->
|
||||
showings.zipWithNext().forEach { (a, b) -> assertTrue(b.startMs - a.startMs >= rest) }
|
||||
}
|
||||
assertTrue(entries.zipWithNext().all { (a, b) -> a.endMs == b.startMs })
|
||||
assertTrue(entries.all { it.media.item.type == "Movie" && !it.media.item.title.contains(" / ") })
|
||||
}
|
||||
|
||||
@Test fun aSmallFilmPoolStillFillsThePlanWithWhatHasWaitedLongest() {
|
||||
val two = listOf(film("a"), film("b"))
|
||||
val entries = extendSchedule(two, ScheduleCursor(), now, now + day, rest).entries
|
||||
assertEquals(listOf("a", "b", "a", "b").toSet(), entries.map { it.seriesId }.toSet())
|
||||
assertTrue(entries.zipWithNext().all { (x, y) -> x.seriesId != y.seriesId })
|
||||
}
|
||||
|
||||
@Test fun filmOrderIsNotASimpleLoopButIsReproducible() {
|
||||
val first = extendSchedule(films, ScheduleCursor(), now, now + 7 * day, rest).entries.map { it.seriesId }
|
||||
assertEquals(first, extendSchedule(films, ScheduleCursor(), now, now + 7 * day, rest).entries.map { it.seriesId })
|
||||
val cycle = first.take(40)
|
||||
assertNotEquals(films.map { it.id }, cycle)
|
||||
}
|
||||
|
||||
@Test fun filmRestSurvivesASaveAndAnExtension() {
|
||||
val store = store()
|
||||
val plan = topUpPlan(null, ScheduleCursor(), films, now, rest)!!
|
||||
store.savePlan(user, 102, plan)
|
||||
val read = store.loadPlan(user, 102)!!
|
||||
assertEquals(plan, read)
|
||||
val later = topUpPlan(read, ScheduleCursor(), films, now + 2 * day, rest)!!
|
||||
later.entries.groupBy { it.seriesId }.values.forEach { showings ->
|
||||
showings.zipWithNext().forEach { (a, b) -> assertTrue(b.startMs - a.startMs >= rest) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSavedPlanFromBeforeFilmsStillOpens() {
|
||||
val dir = folder.newFolder()
|
||||
val store = ScheduleStore(dir)
|
||||
store.savePlan(user, 152, topUpPlan(null, ScheduleCursor(), pool, now)!!)
|
||||
val file = java.io.File(dir, "schedule-152.json")
|
||||
val root = JSONObject(file.readText())
|
||||
root.getJSONObject("tail").remove("shown")
|
||||
file.writeText(root.toString())
|
||||
assertNotNull(store.loadPlan(user, 152))
|
||||
}
|
||||
|
||||
@Test fun airedFilmsAreRemembered() {
|
||||
val plan = extendSchedule(films, ScheduleCursor(), now, now + day, rest)
|
||||
val aired = airedCursor(ScheduleCursor(), plan.entries, plan.entries[2].startMs)
|
||||
assertEquals(plan.entries[2].startMs, aired.filmShown[plan.entries[2].seriesId])
|
||||
assertEquals(3, aired.filmShown.size)
|
||||
}
|
||||
|
||||
@Test fun onlyAnExactFilmTitleCounts() {
|
||||
val rows = JSONArray()
|
||||
.put(JSONObject().put("Id", "sequel").put("Type", "Movie").put("Name", "Halloween II").put("ProductionYear", 1981).put("RunTimeTicks", 60_000_000_000L)
|
||||
.put("MediaSources", JSONArray().put(JSONObject().put("Id", "s1").put("Container", "mkv"))))
|
||||
.put(JSONObject().put("Id", "remake").put("Type", "Movie").put("Name", "Halloween").put("ProductionYear", 2007).put("RunTimeTicks", 60_000_000_000L)
|
||||
.put("MediaSources", JSONArray().put(JSONObject().put("Id", "s2").put("Container", "mkv"))))
|
||||
.put(JSONObject().put("Id", "original").put("Type", "Movie").put("Name", "Halloween").put("ProductionYear", 1978).put("RunTimeTicks", 60_000_000_000L)
|
||||
.put("MediaSources", JSONArray().put(JSONObject().put("Id", "s3").put("Container", "mkv"))))
|
||||
val transport = EmbyTransport { EmbyReply(200, JSONObject().put("Items", rows).toString()) }
|
||||
assertEquals("original", findFilm(transport, user, { "t" }, "Halloween")?.id)
|
||||
assertNull(findFilm(transport, user, { "t" }, "Halloween Ends"))
|
||||
}
|
||||
|
||||
@Test fun aDayJumpStaysBetweenNowAndAWeekAhead() {
|
||||
assertEquals(now + day, guideDayJump(now, now, true))
|
||||
assertEquals(now, guideDayJump(now + 60 * minute, now, false))
|
||||
assertTrue(guideDayJump(now + 7 * day, now, true) < now + 7 * day)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user