diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/sorting/NameComparatorTest.java')
| -rw-r--r-- | tests/src/cgeo/geocaching/sorting/NameComparatorTest.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java new file mode 100644 index 0000000..8cd586d --- /dev/null +++ b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java @@ -0,0 +1,42 @@ +package cgeo.geocaching.sorting; + +import cgeo.geocaching.cgCache; + +import android.test.AndroidTestCase; + +public class NameComparatorTest extends AndroidTestCase { + + private static class NamedCache extends cgCache { + + public NamedCache(final String name) { + this.name = name; + } + } + + private NameComparator comp; + + @Override + protected void setUp() throws Exception { + super.setUp(); + comp = new NameComparator(); + } + + public void testLexical() { + assertSorted(new NamedCache("A"), new NamedCache("Z")); + assertNotSorted(new NamedCache("Z"), new NamedCache("A")); + } + + public void testNumericalNamePart() { + assertSorted(new NamedCache("AHR#2"), new NamedCache("AHR#11")); + assertSorted(new NamedCache("AHR#7 LP"), new NamedCache("AHR#11 Bonsaibuche")); + assertNotSorted(new NamedCache("2"), new NamedCache("11")); // there is no common prefix, therefore sort alphabetical + } + + private void assertSorted(final cgCache cache1, final cgCache cache2) { + assertTrue(comp.compare(cache1, cache2) < 0); + } + + private void assertNotSorted(final cgCache cache1, final cgCache cache2) { + assertTrue(comp.compare(cache1, cache2) > 0); + } +} |
