package lc.mecha.range;

import lc.mecha.log.MechaLogger;
import lc.mecha.log.MechaLoggerFactory;
import lc.mecha.math.IntInterval;
import org.junit.Test;

import java.util.Set;

import static org.junit.Assert.*;

public class IntIntervalTest {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(IntIntervalTest.class);

    @Test
    public void testContains() {
        IntInterval r = new IntInterval(10, 20);
        assertFalse(r.contains(9));
        assertTrue(r.contains(10));
        assertTrue(r.contains(15));
        assertTrue(r.contains(20));
        assertFalse(r.contains(21));
    }

    @Test
    public void testRemove() {
        IntInterval r = new IntInterval(10, 20);
        Set<IntInterval> replacement = r.remove(15);
        logger.info("replacement: {}", replacement);

        replacement = r.remove(10);
        logger.info("replacement: {}", replacement);

        replacement = r.remove(20);
        logger.info("replacement: {}", replacement);
    }

    @Test
    public void testAsString() {
        IntInterval r1 = new IntInterval(100, 100);
        assertEquals("100", r1.asString());

        IntInterval r2 = new IntInterval(200, 250);
        assertEquals("[200..250]", r2.asString());
    }

    @Test
    public void testFromString() {
        IntInterval r1 = new IntInterval("50");
        assertEquals(50, r1.getStartIndex());
        assertEquals(50, r1.getStopIndex());

        IntInterval r2 = new IntInterval("[123...456]");
        assertEquals(123, r2.getStartIndex());
        assertEquals(456, r2.getStopIndex());
    }

    @Test
    public void testSize() {
        IntInterval r1 = new IntInterval("50");
        assertEquals(1, r1.size());

        IntInterval r2 = new IntInterval("0");
        assertEquals(1, r2.size());

        IntInterval r3 = new IntInterval("[10..19]");
        assertEquals(10, r3.size());

        IntInterval r4 = new IntInterval("[0..4]");
        assertEquals(5, r4.size());
    }
}
