From 41fe4ca770875842f4d17531506c4bc74dc90501 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 10 Jun 2016 16:02:06 +0500 Subject: Geofences --- test/org/traccar/geofence/GeofenceCircleTest.java | 36 ++++++++++++++++++++ test/org/traccar/geofence/GeofencePolygonTest.java | 38 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/org/traccar/geofence/GeofenceCircleTest.java create mode 100644 test/org/traccar/geofence/GeofencePolygonTest.java (limited to 'test/org/traccar/geofence') diff --git a/test/org/traccar/geofence/GeofenceCircleTest.java b/test/org/traccar/geofence/GeofenceCircleTest.java new file mode 100644 index 000000000..820f34e34 --- /dev/null +++ b/test/org/traccar/geofence/GeofenceCircleTest.java @@ -0,0 +1,36 @@ +package org.traccar.geofence; + +import java.text.ParseException; + +import org.junit.Assert; +import org.junit.Test; + +public class GeofenceCircleTest { + + @Test + public void testCircleWKT() { + String test = "CIRCLE (55.75414 37.6204, 100)"; + GeofenceGeometry geofenceGeometry = new GeofenceCircle(); + try { + geofenceGeometry.fromWKT(test); + } catch (ParseException e){ + Assert.assertTrue("ParseExceprion: " + e.getMessage(), true); + } + Assert.assertEquals(geofenceGeometry.toWKT(), test); + } + + @Test + public void testContainsCircle() { + String test = "CIRCLE (55.75414 37.6204, 100)"; + GeofenceGeometry geofenceGeometry = new GeofenceCircle(); + try { + geofenceGeometry.fromWKT(test); + } catch (ParseException e){ + Assert.assertTrue("ParseExceprion: " + e.getMessage(), true); + } + + Assert.assertTrue(geofenceGeometry.containsPoint(55.75477, 37.62025)); + + Assert.assertTrue(!geofenceGeometry.containsPoint(55.75545, 37.61921)); + } +} diff --git a/test/org/traccar/geofence/GeofencePolygonTest.java b/test/org/traccar/geofence/GeofencePolygonTest.java new file mode 100644 index 000000000..cc0ed77ad --- /dev/null +++ b/test/org/traccar/geofence/GeofencePolygonTest.java @@ -0,0 +1,38 @@ +package org.traccar.geofence; + +import java.text.ParseException; + +import org.junit.Assert; +import org.junit.Test; + +public class GeofencePolygonTest { + + @Test + public void testPolygonWKT() { + String test = "POLYGON (55.75474 37.61823, 55.75513 37.61888, 55.7535 37.6222, 55.75315 37.62165)"; + GeofenceGeometry geofenceGeometry = new GeofencePolygon(); + try { + geofenceGeometry.fromWKT(test); + } catch (ParseException e){ + Assert.assertTrue("ParseExceprion: " + e.getMessage(), true); + } + Assert.assertEquals(geofenceGeometry.toWKT(), test); + } + + @Test + public void testContainsPolygon() { + String test = "POLYGON (55.75474 37.61823, 55.75513 37.61888, 55.7535 37.6222, 55.75315 37.62165)"; + GeofenceGeometry geofenceGeometry = new GeofencePolygon(); + try { + geofenceGeometry.fromWKT(test); + } catch (ParseException e){ + Assert.assertTrue("ParseExceprion: " + e.getMessage(), true); + } + + Assert.assertTrue(geofenceGeometry.containsPoint(55.75476, 37.61915)); + + Assert.assertTrue(!geofenceGeometry.containsPoint(55.75545, 37.61921)); + + } + +} -- cgit v1.2.3