aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-04-13 21:21:06 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-04-13 21:21:06 +0200
commit8cd9b2afb2f620bb3c2a0df565f8d9ff483fcfaf (patch)
treeb20d5077c0d5ab8e801fc3908ef8c0943366a36c /tests
parente1832f8943f53a50dd6cd50482753779e12cd31a (diff)
downloadcgeo-8cd9b2afb2f620bb3c2a0df565f8d9ff483fcfaf.zip
cgeo-8cd9b2afb2f620bb3c2a0df565f8d9ff483fcfaf.tar.gz
cgeo-8cd9b2afb2f620bb3c2a0df565f8d9ff483fcfaf.tar.bz2
buffer lets you split a list into smaller max-size ones
Diffstat (limited to 'tests')
-rw-r--r--tests/src/cgeo/geocaching/utils/MiscUtilsTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java b/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java
new file mode 100644
index 0000000..2ee99c4
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java
@@ -0,0 +1,54 @@
+package cgeo.geocaching.utils;
+
+import junit.framework.TestCase;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class MiscUtilsTest extends TestCase {
+
+ public static void testBufferEmpty() {
+ for (final List<String> s: MiscUtils.buffer(new LinkedList<String>(), 10)) {
+ fail("empty collection should not iterate");
+ }
+ }
+
+ public static void testMultiple() {
+ final List<Integer> list = new LinkedList<Integer>();
+ for (int i = 0; i < 50; i++) {
+ list.add(i);
+ }
+ int count = 0;
+ for (final List<Integer> subList: MiscUtils.buffer(list, 10)) {
+ assertEquals("each sublist has the right size", 10, subList.size());
+ assertEquals("sublist has the right content", count * 10, (int) subList.get(0));
+ count++;
+ }
+ assertEquals("there are the right number of sublists", 5, count);
+ }
+
+ public static void testNonMultiple() {
+ final List<Integer> list = new LinkedList<Integer>();
+ for (int i = 0; i < 48; i++) {
+ list.add(i);
+ }
+ int count = 0;
+ for (final List<Integer> subList: MiscUtils.buffer(list, 10)) {
+ assertTrue("each sublist has no more than the allowed number of arguments", subList.size() <= 10);
+ count += subList.size();
+ }
+ assertEquals("all the elements were seen", 48, count);
+ }
+
+ public static void testArguments() {
+ try {
+ MiscUtils.buffer(new LinkedList<Integer>(), 0);
+ fail("an exception should be raised");
+ } catch (final IllegalArgumentException e) {
+ // Ok
+ } catch (final Exception e) {
+ fail("bad exception raised: " + e);
+ }
+ }
+
+}