Skip to content

Commit 14016f8

Browse files
author
Isaac Brodsky
committed
Fix tests and javadocs
1 parent 4c9708d commit 14016f8

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

src/main/java/com/uber/h3core/H3Core.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ public double cellArea(String h3Address, AreaUnit unit) {
980980
/**
981981
* Calculates the area of the given H3 cell.
982982
*
983-
* @param h3Address Cell to find the area of.
984-
* @param unit Unit to calculate the area in.
983+
* @param h3 Cell to find the area of.
984+
* @param unit Unit to calculate the area in.
985985
* @return Cell area in the given units.
986986
*/
987987
public double cellArea(long h3, AreaUnit unit) {
@@ -1020,30 +1020,30 @@ else if (unit == LengthUnit.m)
10201020
}
10211021

10221022
/**
1023-
* Calculate the edge length of the given H3 cell.
1023+
* Calculate the edge length of the given H3 edge.
10241024
*
1025-
* @param h3Address Cell to find the edge length of.
1026-
* @param unit Unit of measure to use.
1027-
* @return Edge length of the given cell.
1025+
* @param edgeAddress Edge to find the edge length of.
1026+
* @param unit Unit of measure to use.
1027+
* @return Length of the given edge.
10281028
*/
1029-
public double exactEdgeLength(String h3Address, LengthUnit unit) {
1030-
return exactEdgeLength(stringToH3(h3Address), unit);
1029+
public double exactEdgeLength(String edgeAddress, LengthUnit unit) {
1030+
return exactEdgeLength(stringToH3(edgeAddress), unit);
10311031
}
10321032

10331033
/**
1034-
* Calculate the edge length of the given H3 cell.
1034+
* Calculate the edge length of the given H3 edge.
10351035
*
1036-
* @param h3Address Cell to find the edge length of.
1037-
* @param unit Unit of measure to use.
1038-
* @return Edge length of the given cell.
1036+
* @param edge Edge to find the edge length of.
1037+
* @param unit Unit of measure to use.
1038+
* @return Length of the given edge.
10391039
*/
1040-
public double exactEdgeLength(long h3, LengthUnit unit) {
1040+
public double exactEdgeLength(long edge, LengthUnit unit) {
10411041
if (unit == LengthUnit.rads)
1042-
return h3Api.exactEdgeLengthRads(h3);
1042+
return h3Api.exactEdgeLengthRads(edge);
10431043
else if (unit == LengthUnit.km)
1044-
return h3Api.exactEdgeLengthKm(h3);
1044+
return h3Api.exactEdgeLengthKm(edge);
10451045
else if (unit == LengthUnit.m)
1046-
return h3Api.exactEdgeLengthM(h3);
1046+
return h3Api.exactEdgeLengthM(edge);
10471047
else
10481048
throw new IllegalArgumentException(String.format("Invalid unit: %s", unit));
10491049
}

src/test/java/com/uber/h3core/TestH3Core.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,28 @@ public void testCellArea() {
151151
@Test
152152
public void testExactEdgeLength() {
153153
for (int res = 0; res <= 15; res++) {
154-
String cellAddress = h3.geoToH3Address(0, 0, res);
155154
long cell = h3.geoToH3(0, 0, res);
156155

157-
double areaAddressM = h3.exactEdgeLength(cellAddress, LengthUnit.m);
158-
double areaAddressKm = h3.exactEdgeLength(cellAddress, LengthUnit.km);
159-
double areaAddressRads = h3.exactEdgeLength(cellAddress, LengthUnit.rads);
160-
double areaM = h3.exactEdgeLength(cell, LengthUnit.m);
161-
double areaKm = h3.exactEdgeLength(cell, LengthUnit.km);
162-
double areaRads = h3.exactEdgeLength(cell, LengthUnit.rads);
163-
164-
// Only asserts some properties of the functions that the edge lengths
165-
// should have certain relationships to each other, test isn't specific
166-
// to a cell's actual values.
167-
assertTrue("edge length should match expectation", areaAddressRads > 0);
168-
assertEquals("rads edge length should agree", areaAddressRads, areaRads, EPSILON);
169-
assertEquals("km edge length should agree", areaAddressKm, areaKm, EPSILON);
170-
assertEquals("m edge length should agree", areaAddressM, areaM, EPSILON);
171-
assertTrue("m length greater than km length", areaM > areaKm);
172-
assertTrue("km length greater than rads length", areaKm > areaRads);
156+
for (long edge : h3.getH3UnidirectionalEdgesFromHexagon(cell)) {
157+
String edgeAddress = h3.h3ToString(edge);
158+
159+
double areaAddressM = h3.exactEdgeLength(edgeAddress, LengthUnit.m);
160+
double areaAddressKm = h3.exactEdgeLength(edgeAddress, LengthUnit.km);
161+
double areaAddressRads = h3.exactEdgeLength(edgeAddress, LengthUnit.rads);
162+
double areaM = h3.exactEdgeLength(edge, LengthUnit.m);
163+
double areaKm = h3.exactEdgeLength(edge, LengthUnit.km);
164+
double areaRads = h3.exactEdgeLength(edge, LengthUnit.rads);
165+
166+
// Only asserts some properties of the functions that the edge lengths
167+
// should have certain relationships to each other, test isn't specific
168+
// to a cell's actual values.
169+
assertTrue("edge length should match expectation", areaAddressRads > 0);
170+
assertEquals("rads edge length should agree", areaAddressRads, areaRads, EPSILON);
171+
assertEquals("km edge length should agree", areaAddressKm, areaKm, EPSILON);
172+
assertEquals("m edge length should agree", areaAddressM, areaM, EPSILON);
173+
assertTrue("m length greater than km length", areaM > areaKm);
174+
assertTrue("km length greater than rads length", areaKm > areaRads);
175+
}
173176
}
174177
}
175178

0 commit comments

Comments
 (0)