package com.ponzischeme89.memby.ui.player

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

/**
 * The figure inside the countdown ring.
 *
 * Pure, and worth pinning separately from the view that draws it: the ring is about 30dp
 * across, so the difference between "118" and "1:58" is the difference between a figure
 * that fits and one that prints over its own arc.
 */
class SkipIntroCountdownTest {

    @Test
    fun `seconds under a minute, minutes and seconds over it`() {
        assertEquals("59", formatRemaining(59_000L))
        assertEquals("1:00", formatRemaining(60_000L))
        assertEquals("1:58", formatRemaining(118_000L))
        assertEquals("2:13", formatRemaining(133_000L))
    }

    @Test
    fun `a part second still counts as a second until it is gone`() {
        // Rounded up, so the ring never shows a figure the viewer has already spent. "0"
        // belongs to the moment the offer lapses and to nothing before it.
        assertEquals("7", formatRemaining(6_400L))
        assertEquals("1", formatRemaining(1L))
        assertEquals("0", formatRemaining(0L))
    }

    @Test
    fun `a position past the end never draws a negative figure`() {
        // The playhead legitimately overshoots between ticks, and a ring reading "-1"
        // would be the last thing a viewer saw of this feature.
        assertEquals("0", formatRemaining(-500L))
        assertEquals("0", formatRemaining(-90_000L))
    }
}
