package net.ranides.assira.time;

import org.junit.Test;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import static org.junit.Assert.*;

public class TimeFormatTest {

    @Test
    public void asText() {
        Duration a = Duration.ofSeconds(3600 + 45 * 60).plusSeconds(45).plusMillis(750).plusNanos(17800);
        Duration b = Duration.ofSeconds(3600 + 25 * 60).plusSeconds(45).plusMillis(750);
        Duration c = Duration.ofSeconds(7200 + 45 * 60);

        assertEquals("2h", TimeFormat.asText(a, ChronoUnit.HOURS));
        assertEquals("1h 46m", TimeFormat.asText(a, ChronoUnit.MINUTES));
        assertEquals("1h 45m 46s", TimeFormat.asText(a, ChronoUnit.SECONDS));
        assertEquals("1h 45m 45s 750ms", TimeFormat.asText(a));
        assertEquals("1h 45m 45s 750ms 18µs", TimeFormat.asText(a, ChronoUnit.MICROS));
        assertEquals("1h 45m 45s 750ms 17µs 800ns", TimeFormat.asText(a, ChronoUnit.NANOS));

        assertEquals("1h", TimeFormat.asText(b, ChronoUnit.HOURS));
        assertEquals("1h 26m", TimeFormat.asText(b, ChronoUnit.MINUTES));
        assertEquals("1h 25m 46s", TimeFormat.asText(b, ChronoUnit.SECONDS));
        assertEquals("1h 25m 45s 750ms", TimeFormat.asText(b));
        assertEquals("1h 25m 45s 750ms", TimeFormat.asText(b, ChronoUnit.MICROS));
        assertEquals("1h 25m 45s 750ms", TimeFormat.asText(b, ChronoUnit.NANOS));

        assertEquals("3h", TimeFormat.asText(c, ChronoUnit.HOURS));
        assertEquals("2h 45m", TimeFormat.asText(c, ChronoUnit.MINUTES));
        assertEquals("2h 45m", TimeFormat.asText(c, ChronoUnit.SECONDS));
        assertEquals("2h 45m", TimeFormat.asText(c));
        assertEquals("2h 45m", TimeFormat.asText(c, ChronoUnit.MICROS));
        assertEquals("2h 45m", TimeFormat.asText(c, ChronoUnit.NANOS));
    }
}