package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.GeoBounds
import de.arxsilex.maptools.converter.core.elevation.ElevationPreviewRaster
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue

class ElevationPreviewRendererTest {
    @Test
    fun `renders no-data transparently and valid terrain opaquely`() {
        val raster = ElevationPreviewRaster(
            bounds = GeoBounds(8.0, 50.0, 8.03, 50.03),
            width = 3,
            height = 3,
            elevations = floatArrayOf(
                Float.NaN, 100f, 200f,
                50f, 150f, 300f,
                0f, 75f, 250f,
            ),
            minimumElevationMeters = 0f,
            maximumElevationMeters = 300f,
            populatedCells = 8,
        )

        val pixels = ElevationPreviewRenderer.rgbaPixels(raster)

        assertEquals(0, pixels[3].toInt() and 0xFF)
        assertEquals(255, pixels[7].toInt() and 0xFF)
        assertNotEquals(
            pixels.sliceArray(4 until 7).toList(),
            pixels.sliceArray(20 until 23).toList(),
        )
    }

    @Test
    fun `hypsometric palette distinguishes low and high terrain`() {
        val low = ElevationPreviewRenderer.hypsometricColor(0f, 0f, 2_000f)
        val high = ElevationPreviewRenderer.hypsometricColor(2_000f, 0f, 2_000f)

        assertNotEquals(low, high)
        assertTrue((low ushr 24 and 0xFF) == 255)
        assertTrue((high ushr 24 and 0xFF) == 255)
    }
}
