From 08765d627801a6c12562eb53ed83733a9d23d8cc Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Wed, 26 Jun 2024 20:00:14 +0530 Subject: [PATCH] Added LineString Unit Test (#2518) * added linestring unit test * hardcoded string * order reverse --- .../ground/model/geometry/GeometryTest.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ground/src/test/java/com/google/android/ground/model/geometry/GeometryTest.kt b/ground/src/test/java/com/google/android/ground/model/geometry/GeometryTest.kt index 149feb76d2..2f610e0dfb 100644 --- a/ground/src/test/java/com/google/android/ground/model/geometry/GeometryTest.kt +++ b/ground/src/test/java/com/google/android/ground/model/geometry/GeometryTest.kt @@ -68,13 +68,14 @@ class GeometryTest { @Test fun testPointIsEmpty() { val point = point(x, y) - assertThat(POINT_IS_EMPTY).isEqualTo(point.isEmpty()) + + assertThat(point.isEmpty()).isEqualTo(false) } @Test fun testPointArea() { val point = point(x, y) - assertThat(POINT_AREA).isEqualTo(point.area) + assertThat(point.area).isEqualTo(0.0) } @Test @@ -123,6 +124,17 @@ class GeometryTest { assertThat(LineString(CLOSED_LOOP).isClosed()).isTrue() } + @Test + fun testCenterOfLineString() { + assertThat(LineString(CLOSED_LOOP).center()).isEqualTo(COORDINATE_2) + assertThat(LineString(OPEN_LOOP).center()).isEqualTo(COORDINATE_2) + } + + @Test + fun testAreaOfLineString() { + assertThat(LineString(CLOSED_LOOP).area).isEqualTo(0.0) + } + private fun point(x: Double, y: Double) = Point(Coordinates(x, y)) private fun linearRing(path: Path) = LinearRing(toCoordinateList(path)) @@ -143,8 +155,5 @@ class GeometryTest { private val OPEN_LOOP = listOf(COORDINATE_1, COORDINATE_2, COORDINATE_3) private val CLOSED_LOOP = listOf(COORDINATE_1, COORDINATE_2, COORDINATE_3, COORDINATE_1) - - private const val POINT_AREA = 0.0 - private const val POINT_IS_EMPTY = false } }