use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-wikipedia by wikimedia.
the class NearbyUnitTest method testCompare.
@Test
public void testCompare() throws Throwable {
final Location location = null;
NearbyPage nullLocPage = new NearbyPage("nowhere", location);
calcDistances(nearbyPages);
nullLocPage.setDistance(getDistance(nullLocPage.getLocation()));
assertThat(Integer.MAX_VALUE, is(nullLocPage.getDistance()));
NearbyDistanceComparator comp = new NearbyDistanceComparator();
assertThat(A, is(comp.compare(nearbyPages.get(1), nearbyPages.get(2))));
assertThat(-1 * A, is(comp.compare(nearbyPages.get(2), nearbyPages.get(1))));
assertThat(Integer.MAX_VALUE - A, is(comp.compare(nullLocPage, nearbyPages.get(2))));
// - (max - a)
assertThat((Integer.MIN_VALUE + 1) + A, is(comp.compare(nearbyPages.get(2), nullLocPage)));
assertThat(0, is(comp.compare(nullLocPage, nullLocPage)));
}
use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-wikipedia by wikimedia.
the class NearbyUnitTest method testSortWithNullLocations.
@Test
public void testSortWithNullLocations() throws Throwable {
final Location location = null;
nearbyPages.add(new NearbyPage("d", location));
nearbyPages.add(new NearbyPage("e", location));
calcDistances(nearbyPages);
Collections.sort(nearbyPages, new NearbyDistanceComparator());
assertThat("a", is(nearbyPages.get(0).getTitle().getDisplayText()));
assertThat("b", is(nearbyPages.get(1).getTitle().getDisplayText()));
assertThat("c", is(nearbyPages.get(2).getTitle().getDisplayText()));
// the two null location values come last but in the same order as from the original list:
assertThat("d", is(nearbyPages.get(3).getTitle().getDisplayText()));
assertThat("e", is(nearbyPages.get(4).getTitle().getDisplayText()));
}
use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-wikipedia by wikimedia.
the class NearbyResult method add.
public synchronized void add(@NonNull List<NearbyPage> newPages) {
final double epsilon = 0.00000001;
String primaryLang = WikipediaApp.getInstance().language().getAppLanguageCode();
for (NearbyPage newPage : newPages) {
boolean exists = false;
Iterator<NearbyPage> i = pages.iterator();
while (i.hasNext()) {
NearbyPage page = i.next();
if (Math.abs(page.getLocation().getLatitude() - newPage.getLocation().getLatitude()) < epsilon && Math.abs(page.getLocation().getLongitude() - newPage.getLocation().getLongitude()) < epsilon) {
if (newPage.getTitle().getWikiSite().languageCode().equals(primaryLang)) {
i.remove();
} else {
exists = true;
}
break;
}
}
if (!exists) {
pages.add(newPage);
}
}
}
use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-commons by commons-app.
the class NearbyUnitTest method testCompare.
@Test
public void testCompare() {
final Location location = null;
NearbyPage nullLocPage = new NearbyPage(new PageTitle("nowhere", TEST_WIKI_SITE), location);
calcDistances(nearbyPages);
nullLocPage.setDistance(getDistance(nullLocPage.getLocation()));
assertThat(Integer.MAX_VALUE, is(nullLocPage.getDistance()));
NearbyDistanceComparator comp = new NearbyDistanceComparator();
assertThat(A, is(comp.compare(nearbyPages.get(1), nearbyPages.get(2))));
assertThat(-1 * A, is(comp.compare(nearbyPages.get(2), nearbyPages.get(1))));
assertThat(Integer.MAX_VALUE - A, is(comp.compare(nullLocPage, nearbyPages.get(2))));
// - (max - a)
assertThat((Integer.MIN_VALUE + 1) + A, is(comp.compare(nearbyPages.get(2), nullLocPage)));
assertThat(0, is(comp.compare(nullLocPage, nullLocPage)));
}
Aggregations