package solutions.tretter.mindmachine

import solutions.tretter.mindmachine.session.TimelineEditorState
import solutions.tretter.mindmachine.session.TimelineParameters
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class TimelineParametersTest {

    @Test
    fun `log scale normalize-denormalize roundtrip is stable`() {
        val curves = listOf(
            TimelineEditorState.ActiveCurve.VISUAL_RIGHT,
            TimelineEditorState.ActiveCurve.AUDIO_LEFT,
            TimelineEditorState.ActiveCurve.AUDIO_RIGHT,
        )

        for (c in curves) {
            val n = 0.37f
            val v = TimelineParameters.denormalize(c, n)
            val n2 = TimelineParameters.normalize(c, v)
            assertTrue("Expected normalized roundtrip close for $c but got $n2", kotlin.math.abs(n - n2) < 1e-3f)
        }
    }

    @Test
    fun `brightness percent helper stays in range`() {
        assertEquals(0, TimelineParameters.brightnessPercentFromNormalized(0f))
        assertEquals(100, TimelineParameters.brightnessPercentFromNormalized(1f))
        val mid = TimelineParameters.brightnessPercentFromNormalized(0.5f)
        assertTrue(mid in 1..99)
    }
}
