package no.valg.valgnatt.backend.rapport;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class FormatTest {

    @Test
    public void enDesimal() {
        assertEquals("1.2", Format.enDesimal(1.234d));
    }

    @Test
    public void pst() {
        assertEquals("50.0", Format.pst(0.5f));
        assertEquals("-50.0", Format.pst(-0.5f));
        assertEquals("71.3", Format.pst(0.7125f));
        assertEquals("0.0", Format.pst(0f));
    }

    @Test
    public void pstNN_float() {
        assertNull(Format.pstNN(null));
        assertEquals("50.0", Format.pstNN(0.5f));
        assertEquals("71.3", Format.pstNN(0.7125f));
    }

    @Test
    public void pstNN_tellerOgNevner() {
        assertNull(Format.pstNN(5, 0));
        assertEquals("50.0", Format.pstNN(5, 10));
        assertEquals("-50.0", Format.pstNN(-5, 10));
    }

    @Test
    public void pstNN5_tellerOgNevner() {
        assertNull(Format.pstNN5(5, 0));
        assertEquals("50.00000", Format.pstNN5(5, 10));
        assertEquals("-50.00000", Format.pstNN5(-5, 10));
    }

    @Test
    public void pstEndringNN_FloatFloat() {
        assertNull(Format.pstEndringNN(null, null));
        assertNull(Format.pstEndringNN(null, 0.5f));
        assertNull(Format.pstEndringNN(0.5f, null));
        assertEquals("-10.0", Format.pstEndringNN(0.5f, 0.6f));
    }

    @Test
    public void pstEndringNN_tellerOgNevner() {
        assertNull(Format.pstEndringNN(5, 0, 7, 0));
        assertEquals("+20.0", Format.pstEndringNN(7, 10, 5, 10));
        assertEquals("-20.0", Format.pstEndringNN(5, 10, 7, 10));
    }

    @Test
    public void pstEndringNN5_tellerOgNevner() {
        assertNull(Format.pstEndringNN5(5, 0, 7, 0));
        assertEquals("+20.00000", Format.pstEndringNN5(7, 10, 5, 10));
        assertEquals("-20.00000", Format.pstEndringNN5(5, 10, 7, 10));
    }

    @Test
    public void kvotient() {
        assertEquals("0.012345678901234", Format.kvotient(0.01234567890123431234d));
    }
}
