Search in sources :

Example 6 with NearbyPage

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)));
}
Also used : NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) Location(android.location.Location) Test(org.junit.Test)

Example 7 with NearbyPage

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()));
}
Also used : NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) Location(android.location.Location) Test(org.junit.Test)

Example 8 with NearbyPage

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);
        }
    }
}
Also used : NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage)

Example 9 with NearbyPage

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)));
}
Also used : PageTitle(org.wikipedia.page.PageTitle) NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) Location(android.location.Location) Test(org.junit.Test)

Aggregations

NearbyPage (org.wikipedia.dataclient.mwapi.NearbyPage)9 Location (android.location.Location)6 Test (org.junit.Test)4 PageTitle (org.wikipedia.page.PageTitle)3 SymbolManager (com.mapbox.mapboxsdk.plugins.annotation.SymbolManager)1 SymbolOptions (com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions)1 ArrayList (java.util.ArrayList)1 HistoryEntry (org.wikipedia.history.HistoryEntry)1