aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java6
-rw-r--r--tests/src/cgeo/geocaching/sorting/NameComparatorTest.java25
2 files changed, 30 insertions, 1 deletions
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index 4052917..91497f1 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -206,4 +206,10 @@ public class GeocacheTest extends AndroidTestCase {
assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1);
assertEquals("Zoomlevel not merged correctly", 12, livemap.getZoomLevel());
}
+
+ public static void testNameForSorting() {
+ Geocache cache = new Geocache();
+ cache.setName("GR8 01-01");
+ assertEquals("GR000008 000001-000001", cache.getNameForSorting());
+ }
}
diff --git a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
index 18db4b7..8e020c4 100644
--- a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
+++ b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java
@@ -4,6 +4,9 @@ import cgeo.geocaching.Geocache;
import android.test.AndroidTestCase;
+import java.util.ArrayList;
+import java.util.Collections;
+
public class NameComparatorTest extends AndroidTestCase {
private static class NamedCache extends Geocache {
@@ -26,9 +29,29 @@ public class NameComparatorTest extends AndroidTestCase {
assertSorted(new NamedCache("2"), new NamedCache("11"));
}
+ public void testDuplicateNumericalParts() {
+ assertSortedNames("GR8 01-01", "GR8 01-02", "GR8 01-03", "GR8 01-04", "GR8 01-05", "GR8 01-06", "GR8 01-07", "GR8 01-08", "GR8 01-09");
+ }
+
+ /**
+ * Assert that a given collection of names is already sorted correctly.
+ *
+ * @param names
+ */
+ private void assertSortedNames(String... names) {
+ ArrayList<Geocache> caches = new ArrayList<Geocache>(names.length);
+ for (String name : names) {
+ caches.add(new NamedCache(name));
+ }
+ Collections.sort(caches, comp);
+ for (int i = 0; i < caches.size(); i++) {
+ assertEquals(names[i], caches.get(i).getName());
+ }
+ }
+
public void testNumericalWithSuffix() {
assertSorted(new NamedCache("abc123def"), new NamedCache("abc123xyz"));
- assertEquals("abc000123def456", (new NamedCache("abc123def456")).getNameForSorting());
+ assertEquals("abc000123def000456", (new NamedCache("abc123def456")).getNameForSorting());
}
private void assertSorted(final Geocache cache1, final Geocache cache2) {