diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-01-01 18:43:43 +0100 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-01-01 18:43:43 +0100 |
commit | 9498308fb97fec929f0eac1480b7de7849702af3 (patch) | |
tree | 5c675b7762c114a599b4f51379f0857e1c5e2d1c /tests/src/cgeo | |
parent | 704117f19b163083eef86afbf12bad908c05eec1 (diff) | |
download | cgeo-9498308fb97fec929f0eac1480b7de7849702af3.zip cgeo-9498308fb97fec929f0eac1480b7de7849702af3.tar.gz cgeo-9498308fb97fec929f0eac1480b7de7849702af3.tar.bz2 |
#922: Deleting of automatic generated waypoints
Diffstat (limited to 'tests/src/cgeo')
-rw-r--r-- | tests/src/cgeo/geocaching/cgBaseTest.java | 49 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java | 42 |
2 files changed, 66 insertions, 25 deletions
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java index 3aee275..db0c984 100644 --- a/tests/src/cgeo/geocaching/cgBaseTest.java +++ b/tests/src/cgeo/geocaching/cgBaseTest.java @@ -97,23 +97,48 @@ public class cgBaseTest extends AndroidTestCase { final cgCache cache = createCache(); assertNotNull(cache); - assertWaypointsFromNote(cache, 0, " "); - assertWaypointsFromNote(cache, 0, "some random strings 1 with n 2 numbers"); - assertWaypointsFromNote(cache, 0, "Station3 some coords"); - assertWaypointsFromNote(cache, 1, "Station3: N51 21.523 / E07 02.680"); - assertWaypointsFromNote(cache, 1, "N51 21.523 / E07 02.680"); - assertWaypointsFromNote(cache, 0, "N51 21.523"); - assertWaypointsFromNote(cache, 1, " n 51° 21.523 - E07 02.680"); - assertWaypointsFromNote(cache, 2, "Station3: N51 21.523 / E07 02.680\n\r Station4: N52 21.523 / E012 02.680"); - assertWaypointsFromNote(cache, 0, "51 21 523 / 07 02 680"); - assertWaypointsFromNote(cache, 0, "N51"); + final Geopoint[] empty = new Geopoint[] {}; + final Geopoint[] one = new Geopoint[] { new Geopoint("N51 21.523", "E7 2.680") }; + assertWaypointsFromNote(cache, empty, " "); + assertWaypointsFromNote(cache, empty, "some random strings 1 with n 2 numbers"); + assertWaypointsFromNote(cache, empty, "Station3 some coords"); + assertWaypointsFromNote(cache, one, "Station3: N51 21.523 / E07 02.680"); + assertWaypointsFromNote(cache, one, "N51 21.523 / E07 02.680"); + assertWaypointsFromNote(cache, empty, "N51 21.523"); + assertWaypointsFromNote(cache, one, " n 51° 21.523 - E07 02.680"); + assertWaypointsFromNote(cache, new Geopoint[] { + new Geopoint("N51 21.523", "E7 2.680"), + new Geopoint("N52 21.523", "E12 2.680") }, + "Station3: N51 21.523 / E07 02.680\r\n Station4: N52 21.523 / E012 02.680"); + assertWaypointsFromNote(cache, empty, "51 21 523 / 07 02 680"); + assertWaypointsFromNote(cache, empty, "N51"); + assertWaypointsFromNote(cache, empty, "N 821 O 321"); // issue 922 + assertWaypointsFromNote(cache, empty, "N 821-211 O 322+11"); + assertWaypointsFromNote(cache, empty, "von 240 meter"); + assertWaypointsFromNote(cache, new Geopoint[] { + new Geopoint("N 51 19.844", "E 7 03.625") }, + "A=7 bis B=12 Quellen\r\nC= 66 , Quersumme von 240 m NN\r\nD= 67 , Quersumme von 223 m NN\r\nParken:\r\nN 51 19.844\r\nE 7 03.625"); + assertWaypointsFromNote(cache, new Geopoint[] { + new Geopoint("N51 21.444", "E07 02.600"), + new Geopoint("N51 21.789", "E07 02.800"), + new Geopoint("N51 21.667", "E07 02.800"), + new Geopoint("N51 21.444", "E07 02.706"), + new Geopoint("N51 21.321", "E07 02.700"), + new Geopoint("N51 21.123", "E07 02.477"), + new Geopoint("N51 21.734", "E07 02.500"), + new Geopoint("N51 21.733", "E07 02.378"), + new Geopoint("N51 21.544", "E07 02.566") }, + "Station3: N51 21.444 / E07 02.600\r\nStation4: N51 21.789 / E07 02.800\r\nStation5: N51 21.667 / E07 02.800\r\nStation6: N51 21.444 / E07 02.706\r\nStation7: N51 21.321 / E07 02.700\r\nStation8: N51 21.123 / E07 02.477\r\nStation9: N51 21.734 / E07 02.500\r\nStation10: N51 21.733 / E07 02.378\r\nFinal: N51 21.544 / E07 02.566"); } - private static void assertWaypointsFromNote(final cgCache cache, int waypoints, String note) { + private static void assertWaypointsFromNote(final cgCache cache, Geopoint[] expected, String note) { cache.setPersonalNote(note); cache.setWaypoints(new ArrayList<cgWaypoint>()); cache.parseWaypointsFromNote(); - assertEquals(waypoints, cache.getWaypoints().size()); + assertEquals(expected.length, cache.getWaypoints().size()); + for (int i = 0; i < expected.length; i++) { + assertTrue(expected[i].isEqualTo(cache.getWaypoint(i).getCoords())); + } } private static cgCache createCache() { diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java index 95100c9..b6d7c66 100644 --- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java +++ b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java @@ -1,8 +1,8 @@ package cgeo.geocaching.geopoint; -import android.test.AndroidTestCase; +import cgeo.geocaching.geopoint.GeopointParser.ParseException; -import junit.framework.Assert; +import android.test.AndroidTestCase; public class GeoPointParserTest extends AndroidTestCase { @@ -10,18 +10,16 @@ public class GeoPointParserTest extends AndroidTestCase { private static final double refLatitude = 49.0 + 56.031 / 60.0; public static void testParseLatitude() { - - Assert.assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56.031"), 1e-8); + assertEquals(refLatitude, GeopointParser.parseLatitude("N 49° 56.031"), 1e-8); } public static void testParseLongitude() { - - Assert.assertEquals(refLongitude, GeopointParser.parseLongitude("E 8° 38.564"), 1e-8); + assertEquals(refLongitude, GeopointParser.parseLongitude("E 8° 38.564"), 1e-8); } public static void testFullCoordinates() { final Geopoint goal = new Geopoint(refLatitude, refLongitude); - Assert.assertTrue(goal.isEqualTo(GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), 1e-6)); + assertTrue(goal.isEqualTo(GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), 1e-6)); } public static void testCoordinateMissingPart() { @@ -29,28 +27,46 @@ public class GeoPointParserTest extends AndroidTestCase { Geopoint point = null; try { point = GeopointParser.parse("N 49° 56.031"); - } catch (Exception e) { + } catch (ParseException e) { // expected } - Assert.assertEquals(null, point); + assertEquals(null, point); } public static void testSouth() { - Assert.assertEquals(-refLatitude, GeopointParser.parseLatitude("S 49° 56.031"), 1e-8); + assertEquals(-refLatitude, GeopointParser.parseLatitude("S 49° 56.031"), 1e-8); } public static void testWest() { - Assert.assertEquals(-refLongitude, GeopointParser.parseLongitude("W 8° 38.564"), 1e-8); + assertEquals(-refLongitude, GeopointParser.parseLongitude("W 8° 38.564"), 1e-8); } public static void testLowerCase() { - Assert.assertEquals(refLongitude, GeopointParser.parseLongitude("e 8° 38.564"), 1e-8); + assertEquals(refLongitude, GeopointParser.parseLongitude("e 8° 38.564"), 1e-8); } public static void testVariousFormats() { final Geopoint goal1 = GeopointParser.parse("N 49° 43' 57\" | E 2 12' 35"); final Geopoint goal2 = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); - Assert.assertTrue(goal1.isEqualTo(goal2, 1e-6)); + assertTrue(goal1.isEqualTo(goal2, 1e-6)); + } + + public static void testInSentence() { + final Geopoint p1 = GeopointParser.parse("Station3: N51 21.523 / E07 02.680"); + final Geopoint p2 = GeopointParser.parse("N51 21.523", "E07 02.680"); + assertNotNull(p1); + assertNotNull(p2); + assertTrue(p1.isEqualTo(p2)); + } + + public static void testUnrelatedParts() { + Geopoint point = null; + try { + point = GeopointParser.parse("N51 21.523 and some words in between, so there is no relation E07 02.680"); + } catch (ParseException e) { + // expected + } + assertEquals(null, point); } } |