package space.nstart.pcp.pcp_request_service.service

import ballistics.types.Orientation
import ballistics.types.PointViewParams
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class SatelliteServiceDeterminismTest {

    @Test
    fun `sortPointViews orders mpl points deterministically`() {
        val service = SatelliteService()

        val sorted = service.sortPointViews(
            listOf(
                pointView(traverz = 120.0, vit = 3, pointNumb = 2, pv = 1, kren = 0.3),
                pointView(traverz = 100.0, vit = 4, pointNumb = 1, pv = 0, kren = 0.5),
                pointView(traverz = 100.0, vit = 3, pointNumb = 2, pv = 0, kren = 0.4),
                pointView(traverz = 100.0, vit = 3, pointNumb = 1, pv = 1, kren = 0.2)
            )
        )

        assertEquals(
            listOf(
                100.0 to 3,
                100.0 to 3,
                100.0 to 4,
                120.0 to 3
            ),
            sorted.map { it.traverz to it.vit }
        )
        assertEquals(listOf(1, 2, 1, 2), sorted.map { it.pointNumb })
    }

    private fun pointView(
        traverz: Double,
        vit: Int,
        pointNumb: Int,
        pv: Int,
        kren: Double
    ) = PointViewParams(
        objON = 0,
        objN = 0,
        objUUID = "",
        pointNumb = pointNumb,
        vit = vit,
        traverz = traverz,
        latTraverz = 0.0,
        longTraverz = 0.0,
        orientation = Orientation(0.0, kren, 0.0),
        range = 0.0,
        sunAngle = 0.0,
        sightAngle = 0.0,
        pv = pv
    )
}
