package com.onthelevel.core.sensors

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

class DisplayDeadbandTest {

    @Test
    fun `quantizes to tenths of a degree`() {
        val band = DisplayDeadband()
        assertEquals(0.1, band.update(0.14), 1e-9)
    }

    @Test
    fun `noise on a boundary does not flicker the readout`() {
        val band = DisplayDeadband()
        val first = band.update(0.05) // boundary between 0.0 and 0.1
        // Jitter of ±0.02° around the boundary must hold the displayed value.
        assertEquals(first, band.update(0.06), 1e-9)
        assertEquals(first, band.update(0.04), 1e-9)
        assertEquals(first, band.update(0.05), 1e-9)
    }

    @Test
    fun `a real change moves the readout`() {
        val band = DisplayDeadband()
        band.update(0.0)
        assertEquals(0.2, band.update(0.2), 1e-9)
    }
}
