0.83.1: no third in a row while another show waits, proven against the 0.81.4 baselines
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -305,12 +305,13 @@ class ChannelScheduleTest {
|
||||
assertEquals(entries.size, entries.map { it.mark }.distinct().size)
|
||||
}
|
||||
|
||||
@Test fun aFinishedShowWaitsForTheOthers() {
|
||||
@Test fun aFinishedShowWaitsButNeverForAThirdInARow() {
|
||||
val short = show("s", 1, 2)
|
||||
val long = show("l", 1, 6)
|
||||
val entries = extendSchedule(listOf(short, long), ScheduleCursor(), now, now + 8 * 45 * minute, finishTogether = true).entries
|
||||
assertEquals(listOf("s", "l", "s", "l", "l", "l", "l", "l"), entries.map { it.seriesId })
|
||||
assertEquals(EpisodeMark(1, 6), entries.last().mark)
|
||||
// The short show waits once, then starts its next round rather than let the long one run a third time.
|
||||
assertEquals(listOf("s", "l", "s", "l", "l", "s", "l", "s"), entries.map { it.seriesId })
|
||||
assertEquals((1..4).toList(), entries.filter { it.seriesId == "l" }.map { it.mark.episode })
|
||||
}
|
||||
|
||||
@Test fun onceEveryShowHasFinishedTheyAllStartAgain() {
|
||||
@@ -323,7 +324,11 @@ class ChannelScheduleTest {
|
||||
val pool = listOf(show("s", 1, 2), show("l", 1, 300))
|
||||
val first = topUpPlan(null, ScheduleCursor(), pool, now, finishTogether = true)!!
|
||||
val later = topUpPlan(first, ScheduleCursor(), pool, now + 2 * day, finishTogether = true)!!
|
||||
assertEquals(2, later.entries.count { it.seriesId == "s" } + first.entries.count { it.seriesId == "s" && it.endMs < now + day })
|
||||
// The long show's place carries across the top-up, and so does the rule against a third in a row.
|
||||
val longEpisodes = later.entries.filter { it.seriesId == "l" }.map { it.mark.episode }
|
||||
assertEquals(longEpisodes.sorted(), longEpisodes)
|
||||
val runs = later.entries.fold(Triple("", 0, 0)) { (prev, run, best), e -> val r = if (e.seriesId == prev) run + 1 else 1; Triple(e.seriesId, r, maxOf(best, r)) }.third
|
||||
assertTrue(runs <= 2)
|
||||
}
|
||||
|
||||
@Test fun takingTurnsSkipsOnlyWhatItMust() {
|
||||
|
||||
@@ -33,17 +33,17 @@ class PlanBaselineTest {
|
||||
}
|
||||
|
||||
private val day = 24 * hour
|
||||
private fun plans() = linkedMapOf(
|
||||
private fun plans(rule: Boolean = true) = linkedMapOf(
|
||||
"turns" to extendSchedule(shows, ScheduleCursor(), start, start + 3 * day),
|
||||
"finishTogether" to extendSchedule(shows, ScheduleCursor(), start, start + 4 * day, finishTogether = true),
|
||||
"dayParts" to extendSchedule(shows, ScheduleCursor(), start, start + 4 * day, finishTogether = true, dayParts = parts, zone = zone),
|
||||
"clash" to extendSchedule(shows, ScheduleCursor(), start, start + 3 * day, finishTogether = true, dayParts = parts, zone = zone, avoid = avoid),
|
||||
"everythingClashes" to extendSchedule(listOf(show("a", 2, 7, 22)), ScheduleCursor(), start, start + day, avoid = avoid),
|
||||
"shuffle" to extendSchedule(shows, ScheduleCursor(), start, start + 3 * day, finishTogether = true, dayParts = parts, zone = zone, avoid = avoid, shuffle = true),
|
||||
"finishTogether" to extendSchedule(shows, ScheduleCursor(), start, start + 4 * day, finishTogether = true, noThirdInARow = rule),
|
||||
"dayParts" to extendSchedule(shows, ScheduleCursor(), start, start + 4 * day, finishTogether = true, dayParts = parts, zone = zone, noThirdInARow = rule),
|
||||
"clash" to extendSchedule(shows, ScheduleCursor(), start, start + 3 * day, finishTogether = true, dayParts = parts, zone = zone, avoid = avoid, noThirdInARow = rule),
|
||||
"everythingClashes" to extendSchedule(listOf(show("a", 2, 7, 22)), ScheduleCursor(), start, start + day, avoid = avoid, noThirdInARow = rule),
|
||||
"shuffle" to extendSchedule(shows, ScheduleCursor(), start, start + 3 * day, finishTogether = true, dayParts = parts, zone = zone, avoid = avoid, shuffle = true, noThirdInARow = rule),
|
||||
"films" to extendSchedule(films, ScheduleCursor(), start, start + 5 * day, filmRestMs = 2 * day),
|
||||
"filmsClash" to extendSchedule(films + listOf(PoolSeries("a", "Show a", listOf(PoolEpisode("a", "src-a", EpisodeMark(1, 1), "Show a", 90 * minute)))), ScheduleCursor(), start, start + 3 * day,
|
||||
filmRestMs = day, dayParts = parts, zone = zone, avoid = avoid),
|
||||
"topUp" to topUpPlan(extendSchedule(shows, ScheduleCursor(), start, start + 2 * day), ScheduleCursor(), shows, start + day, finishTogether = true, dayParts = parts, zone = zone, avoid = avoid),
|
||||
filmRestMs = day, dayParts = parts, zone = zone, avoid = avoid, noThirdInARow = rule),
|
||||
"topUp" to topUpPlan(extendSchedule(shows, ScheduleCursor(), start, start + 2 * day), ScheduleCursor(), shows, start + day, finishTogether = true, dayParts = parts, zone = zone, avoid = avoid, noThirdInARow = rule),
|
||||
)
|
||||
|
||||
@Test fun everyNewProgrammeSaysWhy() {
|
||||
@@ -76,6 +76,19 @@ class PlanBaselineTest {
|
||||
// Taken from 0.81.4, before reasons were recorded.
|
||||
val expected = mapOf("turns" to "5cc4eee2cbfa29e6", "finishTogether" to "c357d2fae0d6a5df", "dayParts" to "764b7b7ac15a5b26", "clash" to "8d3c92c8c4beed8e",
|
||||
"everythingClashes" to "9f38ee7d889140c5", "shuffle" to "cee9b485bc705af2", "films" to "2f4f2786280d4589", "filmsClash" to "7fe17b8f3746e164", "topUp" to "40ce5b5f8e0e8ed3")
|
||||
assertEquals(expected, plans().mapValues { fingerprint(it.value) })
|
||||
// With the no-third-in-a-row rule off, planning is exactly as it was in 0.81.4.
|
||||
assertEquals(expected, plans(rule = false).mapValues { fingerprint(it.value) })
|
||||
}
|
||||
|
||||
@Test fun theRuleOnlyChangesPlansFromItsFirstEarlyRestart() {
|
||||
val before = plans(rule = false); val after = plans(rule = true)
|
||||
for ((name, plan) in after) {
|
||||
val old = before.getValue(name)!!.entries; val new = plan!!.entries
|
||||
val firstEarly = new.indexOfFirst { "started its next round early" in it.why }
|
||||
val same = if (firstEarly < 0) new.size else firstEarly
|
||||
assertEquals(name, old.take(same).map { it.seriesId to it.mark }, new.take(same).map { it.seriesId to it.mark })
|
||||
// And only where the old plan really had a third in a row at that point.
|
||||
if (firstEarly >= 0) assertTrue(name, old.drop(firstEarly - 2).take(3).map { it.seriesId }.distinct().size == 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
/** Finish-together once let one big show play dozens of times in a row while smaller ones waited. */
|
||||
class RunLengthTest {
|
||||
private val minute = 60_000L
|
||||
private val start = 1_793_700_000_000L
|
||||
private fun show(id: String, count: Int) = PoolSeries(id, "Show $id", (1..count).map { PoolEpisode("$id$it", "s", EpisodeMark(1, it), "E$it", 10 * minute) })
|
||||
private fun longestRun(plan: ChannelPlan) = plan.entries.fold(Triple("", 0, 0)) { (prev, run, best), e -> val r = if (e.seriesId == prev) run + 1 else 1; Triple(e.seriesId, r, maxOf(best, r)) }.third
|
||||
|
||||
@Test fun aBigShowNeverPlaysThreeInARowWhileOthersWait() {
|
||||
val pool = listOf(show("big", 40), show("a", 3), show("b", 4), show("c", 2))
|
||||
for (shuffle in listOf(false, true)) {
|
||||
val plan = extendSchedule(pool, ScheduleCursor(), start, start + 60 * 10 * minute, finishTogether = true, shuffle = shuffle)
|
||||
assertTrue("longest run ${longestRun(plan)}", longestRun(plan) <= 2)
|
||||
assertTrue(plan.entries.any { "started its next round early" in it.why })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun eachShowStillPlaysItsWholeRoundBeforeRepeatingAnEpisode() {
|
||||
val pool = listOf(show("big", 40), show("a", 3))
|
||||
val plan = extendSchedule(pool, ScheduleCursor(), start, start + 40 * 10 * minute, finishTogether = true)
|
||||
val big = plan.entries.filter { it.seriesId == "big" }.map { it.mark.episode }
|
||||
assertEquals(big.distinct(), big)
|
||||
}
|
||||
|
||||
@Test fun aBlockWithOneShowIsUnchanged() {
|
||||
val plan = extendSchedule(listOf(show("only", 30)), ScheduleCursor(), start, start + 20 * 10 * minute, finishTogether = true)
|
||||
assertEquals(20, longestRun(plan))
|
||||
}
|
||||
|
||||
@Test fun withoutFinishTogetherNothingChanges() {
|
||||
val pool = listOf(show("big", 40), show("a", 3))
|
||||
val plan = extendSchedule(pool, ScheduleCursor(), start, start + 20 * 10 * minute)
|
||||
assertEquals(listOf("big", "a"), plan.entries.take(2).map { it.seriesId })
|
||||
assertTrue(plan.entries.none { "early" in it.why })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user