package de.arxsilex.maptools.converter.core.elevation

import kotlin.test.Test
import kotlin.test.assertEquals

class ElevationExecutionPolicyTest {
    @Test
    fun `keeps a four GiB system within one bounded worker`() {
        val gib = 1024L * 1024L * 1024L

        val options = ElevationExecutionPolicy.from(
            availableProcessors = 2,
            totalMemoryBytes = 4L * gib,
            freeMemoryBytes = 1L * gib,
            heapHeadroomBytes = gib / 2L,
        )

        assertEquals(1, options.workerCount)
        assertEquals(4 * 1024 * 1024, options.bufferBytesPerWorker)
    }

    @Test
    fun `uses additional processors and buffers on a large workstation`() {
        val gib = 1024L * 1024L * 1024L

        val options = ElevationExecutionPolicy.from(
            availableProcessors = 48,
            totalMemoryBytes = 64L * gib,
            freeMemoryBytes = 32L * gib,
            heapHeadroomBytes = 16L * gib,
        )

        assertEquals(16, options.workerCount)
        assertEquals(8 * 1024 * 1024, options.bufferBytesPerWorker)
    }
}
