package com.gxwebsoft.shop.util;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class GeoFenceUtilTest {

    @Test
    void parsePoints_semicolonPairs() {
        List<GeoFenceUtil.Point> pts = GeoFenceUtil.parsePolygonPoints("0,0;10,0;10,10;0,10");
        assertEquals(4, pts.size());
        assertEquals(0.0, pts.get(0).lng, 1e-9);
        assertEquals(0.0, pts.get(0).lat, 1e-9);
    }

    @Test
    void parsePoints_jsonArray() {
        List<GeoFenceUtil.Point> pts = GeoFenceUtil.parsePolygonPoints("[[0,0],[10,0],[10,10],[0,10]]");
        assertEquals(4, pts.size());
        assertEquals(10.0, pts.get(2).lng, 1e-9);
        assertEquals(10.0, pts.get(2).lat, 1e-9);
    }

    @Test
    void containsInclusive_insideOutsideAndBoundary() {
        List<GeoFenceUtil.Point> square = GeoFenceUtil.parsePolygonPoints("0,0;10,0;10,10;0,10");
        assertTrue(GeoFenceUtil.containsInclusive(square, 5, 5), "inside");
        assertFalse(GeoFenceUtil.containsInclusive(square, 15, 5), "outside");
        assertTrue(GeoFenceUtil.containsInclusive(square, 0, 5), "on edge");
        assertTrue(GeoFenceUtil.containsInclusive(square, 0, 0), "on vertex");
    }
}

