package space.animefu.starfallhaven;

import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.*;

public class AreaDesignationTest {
    @Test public void rectangleNormalizesReverseDragAndIncludesEveryTile() {
        AreaDesignation area=new AreaDesignation();
        area.begin(5,6,AreaDesignation.Shape.RECTANGLE);
        area.update(3,4);
        assertEquals(3,area.left()); assertEquals(4,area.top());
        assertEquals(5,area.right()); assertEquals(6,area.bottom());
        assertEquals(9,area.tiles().size());
        assertTrue(area.tiles().contains(new AreaDesignation.TilePoint(3,4)));
        assertTrue(area.tiles().contains(new AreaDesignation.TilePoint(5,6)));
    }

    @Test public void lineLocksToDominantAxisAndClampsToMap() {
        AreaDesignation area=new AreaDesignation();
        area.begin(2,2,AreaDesignation.Shape.LINE); area.update(7,4);
        assertEquals(Arrays.asList(
                new AreaDesignation.TilePoint(2,2),new AreaDesignation.TilePoint(3,2),
                new AreaDesignation.TilePoint(4,2),new AreaDesignation.TilePoint(5,2),
                new AreaDesignation.TilePoint(6,2),new AreaDesignation.TilePoint(7,2)),area.tiles());
        area.begin(-10,GameWorld.HEIGHT+4,AreaDesignation.Shape.LINE);
        assertEquals(new AreaDesignation.TilePoint(0,GameWorld.HEIGHT-1),area.tiles().get(0));
    }

    @Test public void clearRemovesPreview() {
        AreaDesignation area=new AreaDesignation(); area.begin(1,1,AreaDesignation.Shape.RECTANGLE);
        area.clear(); assertFalse(area.active()); assertTrue(area.tiles().isEmpty());
    }
}
