aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/sorting
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2011-10-15 17:03:15 +0200
committerBananeweizen <bananeweizen@gmx.de>2011-10-15 17:03:15 +0200
commit41e1965db638aa3b8109dc28b5f4a0eff4e0371f (patch)
treed4e9b535c9e2de03fac38d502831ac29d1d0d803 /tests/src/cgeo/geocaching/sorting
parent6952e708e7526079067561906e381864b2ba8fb5 (diff)
downloadcgeo-41e1965db638aa3b8109dc28b5f4a0eff4e0371f.zip
cgeo-41e1965db638aa3b8109dc28b5f4a0eff4e0371f.tar.gz
cgeo-41e1965db638aa3b8109dc28b5f4a0eff4e0371f.tar.bz2
new: sort cache series numerically correct when sorting by name
Diffstat (limited to 'tests/src/cgeo/geocaching/sorting')
-rw-r--r--tests/src/cgeo/geocaching/sorting/NameComparatorTest.java42
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);
+ }
+}