From 19b8392a73ed4655e6c6aa03b511ba7c70c7b177 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 28 Jul 2013 21:18:23 +0200 Subject: fix #3061: name sorting wrong for certain number combinations --- .../geocaching/sorting/NameComparatorTest.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'tests/src/cgeo/geocaching/sorting/NameComparatorTest.java') 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 caches = new ArrayList(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) { -- cgit v1.1