File tree Expand file tree Collapse file tree
main/java/io/github/makbn/jlmap/model
test/java/io/github/makbn/jlmap/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88/**
99 * Represents a geographical point with a certain latitude and longitude.
10- * by: Mehdi Akbarian Rastaghi (@makbn)
10+ * @author Mehdi Akbarian Rastaghi (@makbn)
1111 */
1212@ Getter
1313@ Setter
1414@ Builder
1515@ AllArgsConstructor
16- @ ToString
1716public class JLLatLng {
1817 /** geographical given latitude in degrees */
1918 private final double lat ;
@@ -72,4 +71,9 @@ public boolean equals(Object o, int maxMargin) {
7271 public int hashCode () {
7372 return Objects .hash (lat , lng );
7473 }
74+
75+ @ Override
76+ public String toString () {
77+ return String .format ("[%f, %f]" , lat , lng );
78+ }
7579}
Original file line number Diff line number Diff line change 1+ package io .github .makbn .jlmap .model ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .Test ;
5+
6+ class JLLatLngTest {
7+
8+ @ Test
9+ void testEquals () {
10+ JLLatLng pointA = JLLatLng .builder ()
11+ .lat (10 )
12+ .lng (20 )
13+ .build ();
14+
15+ JLLatLng pointB = JLLatLng .builder ()
16+ .lat (10.000 )
17+ .lng (20.00 )
18+ .build ();
19+ Assertions .assertEquals (pointA , pointB );
20+ }
21+
22+ @ Test
23+ void testNotEquals () {
24+ JLLatLng pointA = JLLatLng .builder ()
25+ .lat (10 )
26+ .lng (20 )
27+ .build ();
28+
29+ JLLatLng pointB = JLLatLng .builder ()
30+ .lat (20 )
31+ .lng (10 )
32+ .build ();
33+
34+ Assertions .assertNotEquals (pointA , pointB );
35+ }
36+
37+ @ Test
38+ void testDistanceCalculation_lng () {
39+ JLLatLng pointA = JLLatLng .builder ()
40+ .lat (10 )
41+ .lng (20 )
42+ .build ();
43+
44+ JLLatLng pointB = JLLatLng .builder ()
45+ .lat (10 )
46+ .lng (50 )
47+ .build ();
48+
49+ Assertions .assertTrue (Math .abs (3282 - Math .round (pointA .distanceTo (pointB )/ 1000 )) < 0.01 );
50+ }
51+
52+ @ Test
53+ void testDistanceCalculation_lat () {
54+ JLLatLng pointA = JLLatLng .builder ()
55+ .lat (50 )
56+ .lng (10 )
57+ .build ();
58+
59+ JLLatLng pointB = JLLatLng .builder ()
60+ .lat (20 )
61+ .lng (10 )
62+ .build ();
63+
64+ Assertions .assertTrue (Math .abs (3334 - Math .round (pointA .distanceTo (pointB )/ 1000 )) < 0.01 );
65+ }
66+
67+ @ Test
68+ void testDistanceCalculation_latLng () {
69+ JLLatLng pointA = JLLatLng .builder ()
70+ .lat (50 )
71+ .lng (80 )
72+ .build ();
73+
74+ JLLatLng pointB = JLLatLng .builder ()
75+ .lat (30 )
76+ .lng (10 )
77+ .build ();
78+
79+ Assertions .assertTrue (Math .abs (6113 - Math .round (pointA .distanceTo (pointB )/ 1000 )) < 0.01 );
80+ }
81+ }
You can’t perform that action at this time.
0 commit comments