summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/TestUtils.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2022-07-26 20:35:01 -0400
committerBen Culkin <scorpress@gmail.com>2022-07-26 20:35:01 -0400
commit629b6bc7444005915983ae8d86c89c4ae215729e (patch)
treeef50616792bfa4392ff9541218ebeaeca62458f0 /src/test/java/bjc/TestUtils.java
parent6ccd5d885084f983013584db35df60a22b76e521 (diff)
Restructure a bit
Diffstat (limited to 'src/test/java/bjc/TestUtils.java')
-rw-r--r--src/test/java/bjc/TestUtils.java141
1 files changed, 0 insertions, 141 deletions
diff --git a/src/test/java/bjc/TestUtils.java b/src/test/java/bjc/TestUtils.java
deleted file mode 100644
index 312ebaf..0000000
--- a/src/test/java/bjc/TestUtils.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package bjc;
-
-import java.util.*;
-
-import static org.junit.Assert.*;
-
-/**
- * Utility methods for doing testing
- *
- * @author Ben Culkin
- */
-public class TestUtils {
- /**
- * Assert an iterator provides a particular sequence of values.
- *
- * @param <T> The type of the 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 (int i = 0; i < vals.length; i++) {
- if (src.hasNext()) {
- assertEquals(vals[i], src.next());
- } else {
- String msg = String.format("not enough values: got %d, wanted %d", i,
- vals.length);
-
- assertTrue(msg, false);
- }
- }
- }
-
- /**
- * Assert an iterator provides a particular sequence of values.
- *
- * @param <T> The type of the 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());
- }
-
- /**
- * Assert an iterator provides a particular sequence of values.
- *
- * @param <T> The type of the values.
- * @param src The iterator to pull values from.
- * @param vals The values to expect from the iterator.
- */
- @SafeVarargs
- public static <T> void assertIteratorSet(Iterator<T> src, T... vals) {
- Set<T> s1 = new HashSet<>();
- Set<T> s2 = new HashSet<>();
-
- for (int i = 0; i < vals.length; i++) {
- if (src.hasNext()) {
- s1.add(vals[i]);
- s2.add(src.next());
- } else {
- String msg = String.format("not enough values: got %d, wanted %d", i,
- vals.length);
-
- assertTrue(msg, false);
- }
- }
-
- assertEquals(s1, s2);
- }
-
- /**
- * Assert an iterator provides a particular sequence of values.
- *
- * @param <T> The type of the 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 assertIteratorSet(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.
- */
- assertIteratorSet(src, vals);
-
- assertEquals("iterator not exhausted", hasMore, src.hasNext());
- }
-
- /**
- * Assert that a list contains a certain set of values.
- *
- * @param <T> The type of the values.
- * @param src The list to read values from.
- * @param exps The values to expect in the list.
- */
- @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);
- }
- }
-
- /**
- * Assert a stack has the given contents.
- *
- * @param <T>
- * The type of items in the stack.
- *
- * @param src
- * The stack to inspect.
- * @param exps
- * The values that are expected.
- */
- @SafeVarargs
- public static <T> void assertStackEquals(bjc.esodata.Stack<T> src, T... exps) {
- assertArrayEquals(exps, src.toArray());
- }
-}