diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2013-07-28 21:18:23 +0200 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2013-07-28 21:18:23 +0200 |
| commit | 19b8392a73ed4655e6c6aa03b511ba7c70c7b177 (patch) | |
| tree | 0464dd862423e5b72f21de92c0074c0d8b6c1e8e /tests/src | |
| parent | 24413415dd85f5c4da3f86c98ec6c78fec0f257d (diff) | |
| download | cgeo-19b8392a73ed4655e6c6aa03b511ba7c70c7b177.zip cgeo-19b8392a73ed4655e6c6aa03b511ba7c70c7b177.tar.gz cgeo-19b8392a73ed4655e6c6aa03b511ba7c70c7b177.tar.bz2 | |
fix #3061: name sorting wrong for certain number combinations
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/cgeo/geocaching/GeocacheTest.java | 6 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/sorting/NameComparatorTest.java | 25 |
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) { |
