Skip to content

Commit

Permalink
adding toString method and the related test
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Sep 9, 2023
1 parent 38d07b9 commit 7ff1fc9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/io/github/makbn/jlmap/model/JLLatLng.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

/**
* Represents a geographical point with a certain latitude and longitude.
* by: Mehdi Akbarian Rastaghi (@makbn)
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
@Getter
@Setter
@Builder
@AllArgsConstructor
@ToString
public class JLLatLng {
/** geographical given latitude in degrees */
private final double lat;
Expand Down Expand Up @@ -72,4 +71,9 @@ public boolean equals(Object o, int maxMargin) {
public int hashCode() {
return Objects.hash(lat, lng);
}

@Override
public String toString() {
return String.format("[%f, %f]", lat, lng);
}
}
81 changes: 81 additions & 0 deletions src/test/java/io/github/makbn/jlmap/model/JLLatLngTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.github.makbn.jlmap.model;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class JLLatLngTest {

@Test
void testEquals() {
JLLatLng pointA = JLLatLng.builder()
.lat(10)
.lng(20)
.build();

JLLatLng pointB = JLLatLng.builder()
.lat(10.000)
.lng(20.00)
.build();
Assertions.assertEquals(pointA, pointB);
}

@Test
void testNotEquals() {
JLLatLng pointA = JLLatLng.builder()
.lat(10)
.lng(20)
.build();

JLLatLng pointB = JLLatLng.builder()
.lat(20)
.lng(10)
.build();

Assertions.assertNotEquals(pointA, pointB);
}

@Test
void testDistanceCalculation_lng() {
JLLatLng pointA = JLLatLng.builder()
.lat(10)
.lng(20)
.build();

JLLatLng pointB = JLLatLng.builder()
.lat(10)
.lng(50)
.build();

Assertions.assertTrue(Math.abs(3282 - Math.round(pointA.distanceTo(pointB)/ 1000)) < 0.01);
}

@Test
void testDistanceCalculation_lat() {
JLLatLng pointA = JLLatLng.builder()
.lat(50)
.lng(10)
.build();

JLLatLng pointB = JLLatLng.builder()
.lat(20)
.lng(10)
.build();

Assertions.assertTrue(Math.abs(3334 - Math.round(pointA.distanceTo(pointB)/ 1000)) < 0.01);
}

@Test
void testDistanceCalculation_latLng() {
JLLatLng pointA = JLLatLng.builder()
.lat(50)
.lng(80)
.build();

JLLatLng pointB = JLLatLng.builder()
.lat(30)
.lng(10)
.build();

Assertions.assertTrue(Math.abs(6113 - Math.round(pointA.distanceTo(pointB)/ 1000)) < 0.01);
}
}

0 comments on commit 7ff1fc9

Please sign in to comment.