summaryrefslogtreecommitdiff
path: root/src/test/java/io/github/bculkin2442/TestUtils.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2019-07-02 18:05:22 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2019-07-02 18:05:22 -0400
commit843329de434bb334d90927c4d22345373a388530 (patch)
treeb0ad1f764bd29ff43841e1095a5b58194c20cb37 /src/test/java/io/github/bculkin2442/TestUtils.java
parentac36f171a3cebb0993cc28548635e3f654f8e325 (diff)
Rename package root
The package root is now bjc, not io.github.bculkin2442.
Diffstat (limited to 'src/test/java/io/github/bculkin2442/TestUtils.java')
-rw-r--r--src/test/java/io/github/bculkin2442/TestUtils.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/java/io/github/bculkin2442/TestUtils.java b/src/test/java/io/github/bculkin2442/TestUtils.java
new file mode 100644
index 0000000..80f7d96
--- /dev/null
+++ b/src/test/java/io/github/bculkin2442/TestUtils.java
@@ -0,0 +1,60 @@
+package io.github.bculkin2442;
+
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class TestUtils {
+ /**
+ * Assert an iterator provides a particular sequence of values.
+ *
+ * @param src
+ * The iterator to pull values from.
+ * @param vals
+ * The values to expect from the iterator.
+ */
+ @SafeVarargs
+ public static <T> void assertIteratorEquals(Iterator<T> src, T... vals) {
+ for (T val : vals) {
+ assertEquals(val, src.next());
+ }
+ }
+
+ /**
+ * Assert an iterator provides a particular sequence of values.
+ *
+ * @param src
+ * The iterator to pull values from.
+ * @param hasMore
+ * The expected value of hasNext for the iterator.
+ * @param vals
+ * The values to expect from the iterator.
+ */
+ @SafeVarargs
+ public static <T> void assertIteratorEquals(boolean hasMore, Iterator<T> 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("iterator not exhausted", hasMore, src.hasNext());
+ }
+
+ @SafeVarargs
+ public static <T> void assertListEquals(List<T> src, T... exps) {
+ assertEquals(exps.length, src.size());
+
+ int i = 0;
+ for (T act : src) {
+ T exp = exps[i++];
+
+ assertEquals(exp, act);
+ }
+ }
+}