From 074393ed8abda6003f31b97496fa8195c4627753 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 29 Oct 2018 20:07:42 -0400 Subject: More testing. Add some more testing utilities --- .../java/bjc/utils/funcutils/IteratorUtils.java | 33 ++++++++++++++++++++++ .../main/java/bjc/utils/funcutils/TestUtils.java | 18 ++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 base/src/main/java/bjc/utils/funcutils/IteratorUtils.java (limited to 'base/src/main/java/bjc/utils/funcutils') diff --git a/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java new file mode 100644 index 0000000..55e5985 --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java @@ -0,0 +1,33 @@ +package bjc.utils.funcutils; + +import java.util.Iterator; + +/** + * Utility methods for dealing with iterators. + * + * @author bjculkin + * + */ +public class IteratorUtils { + /** + * Convert an iterator to an iterable. + * + * @param itr + * The iterator to convert. + * @return An iterable that gives back that iterator. + */ + public static Iterable I(Iterator itr) { + return () -> itr; + } + + /** + * Convert an iterable to an iterator. + * + * @param itr + * The iterable to convert. + * @return The iterator from that iterable + */ + public static Iterator I(Iterable itr) { + return itr.iterator(); + } +} diff --git a/base/src/main/java/bjc/utils/funcutils/TestUtils.java b/base/src/main/java/bjc/utils/funcutils/TestUtils.java index 124389e..586d366 100644 --- a/base/src/main/java/bjc/utils/funcutils/TestUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/TestUtils.java @@ -38,20 +38,28 @@ public class TestUtils { * The values to expect from the iterator. */ @SafeVarargs - public static void assertIteratorEquals(Iterator src, boolean hasMore, T... vals) { + public static void assertIteratorEquals(boolean hasMore, Iterator src, T... vals) { + /* + * @NOTE + * + * Even though it's awkward, the boolean has to come first. + * Otherwise, there are cases where the compiler will get + * confused as to what the right value for T is, and be unable + * to pick an overload. + */ assertIteratorEquals(src, vals); - + assertEquals(hasMore, src.hasNext()); } - + @SafeVarargs public static void assertListEquals(List src, T... exps) { assertEquals(exps.length, src.size()); - + int i = 0; for (T act : src) { T exp = exps[i++]; - + assertEquals(exp, act); } } -- cgit v1.2.3