package com.ponzischeme89.memby.ui.player

import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Pins the trace section names to the literals `:benchmark` looks for.
 *
 * `PlaybackBenchmark` cannot import [PlaybackTraceSections] — it is a `com.android.test`
 * module that drives the app from outside rather than linking against it — so the two
 * copies of these strings are kept in step by hand. That is exactly the arrangement that
 * rots silently: rename the constant, and `TraceSectionMetric` simply finds no slices and
 * reports zero, which reads as "playback got infinitely fast" rather than as a broken
 * benchmark. This test turns that into a failure at the moment of the rename.
 *
 * If you are here because this test failed: change `PlaybackBenchmark` too, then update
 * the literals below.
 */
class PlaybackTraceNamesTest {

    @Test
    fun `launch section name matches the benchmark`() {
        assertEquals("Memby.playbackLaunch", PlaybackTraceSections.LAUNCH)
    }

    @Test
    fun `first frame section name matches the benchmark`() {
        assertEquals("Memby.playbackFirstFrame", PlaybackTraceSections.FIRST_FRAME)
    }

    /** Overlapping launches share a name, so the cookies must not collide. */
    @Test
    fun `cookies are unique`() {
        val cookies = List(100) { PlaybackTraceSections.nextCookie() }

        assertEquals(cookies.size, cookies.distinct().size)
    }
}
