-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
java.lang.AssertionError: Expected :[(2.1909382939338684,41.433790281840835), (2.187376320362091,41.40634178640635)] Actual :[(2.1909382939338684,41.43379028184083), (2.187376320362091,41.40634178640635)] Compare with tolerance to avoid error on returned precision on mac
- Loading branch information
Showing
6 changed files
with
134 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/test/java/redis/clients/jedis/util/GeoRadiusResponseMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package redis.clients.jedis.util; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
import redis.clients.jedis.GeoCoordinate; | ||
import redis.clients.jedis.resps.GeoRadiusResponse; | ||
|
||
public class GeoRadiusResponseMatcher extends TypeSafeMatcher<GeoRadiusResponse> { | ||
private final GeoRadiusResponse expected; | ||
private final double coordinateTolerance; | ||
|
||
public static Matcher<GeoRadiusResponse> isEqualToGeoRadiusResponse(GeoRadiusResponse expected) { | ||
return new GeoRadiusResponseMatcher(expected, GeoCoordinateMatcher.DEFAULT_TOLERANCE); | ||
} | ||
|
||
public static Matcher<GeoRadiusResponse> isEqualToGeoRadiusResponse(GeoRadiusResponse expected, double tolerance) { | ||
return new GeoRadiusResponseMatcher(expected, tolerance); | ||
} | ||
|
||
public GeoRadiusResponseMatcher(GeoRadiusResponse expected, double coordinateTolerance) { | ||
this.expected = expected; | ||
this.coordinateTolerance = coordinateTolerance; | ||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(GeoRadiusResponse actual) { | ||
// Check if coordinates match within the tolerance | ||
GeoCoordinate expectedCoord = expected.getCoordinate(); | ||
GeoCoordinate actualCoord = actual.getCoordinate(); | ||
if (!GeoCoordinateMatcher.isEqualWithTolerance(expectedCoord, coordinateTolerance).matches(actualCoord)) { | ||
return false; | ||
} | ||
|
||
// Check if distance and rawScore match exactly | ||
if (Double.compare(expected.getDistance(), actual.getDistance()) != 0) { | ||
return false; | ||
} | ||
return expected.getRawScore() == actual.getRawScore(); | ||
} | ||
|
||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("a GeoRadiusResponse with coordinate ") | ||
.appendValue(expected.getCoordinate()) | ||
.appendText(", distance ") | ||
.appendValue(expected.getDistance()) | ||
.appendText(", and rawScore ") | ||
.appendValue(expected.getRawScore()); | ||
} | ||
|
||
@Override | ||
protected void describeMismatchSafely(GeoRadiusResponse actual, Description mismatchDescription) { | ||
mismatchDescription.appendText("was ") | ||
.appendValue(actual); | ||
} | ||
|
||
} |