summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/data
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2019-07-02 18:32:37 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2019-07-02 18:32:37 -0400
commit4d0a59a0023f2b4fca144a089a3f75acb4ebd62b (patch)
treeeed89369ceda7dd1b356dd5055ada9287738b092 /src/test/java/bjc/data
parent3a56e3ee3f2f6069de5cf8d2bee81052bbf346e6 (diff)
Move tests to new package
Diffstat (limited to 'src/test/java/bjc/data')
-rw-r--r--src/test/java/bjc/data/BooleanToggleTest.java38
-rw-r--r--src/test/java/bjc/data/CircularIteratorTest.java49
-rw-r--r--src/test/java/bjc/data/QueuedIteratorTest.java74
3 files changed, 161 insertions, 0 deletions
diff --git a/src/test/java/bjc/data/BooleanToggleTest.java b/src/test/java/bjc/data/BooleanToggleTest.java
new file mode 100644
index 0000000..b3d33eb
--- /dev/null
+++ b/src/test/java/bjc/data/BooleanToggleTest.java
@@ -0,0 +1,38 @@
+package bjc.data;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import bjc.data.BooleanToggle;
+
+/**
+ * Test for boolean toggles.
+ * @author bjculkin
+ *
+ */
+public class BooleanToggleTest {
+
+ /**
+ * Test that boolean toggles work right.
+ */
+ @Test
+ public void test() {
+ BooleanToggle tog = new BooleanToggle();
+
+ // Check initial value is false.
+ assertEquals(false, tog.peek());
+ // Check that 'get' returns the old value
+ assertEquals(false, tog.get());
+ // Check that 'get' swaps the value
+ assertEquals(true, tog.peek());
+ // Check that we can round-trip back.
+ assertEquals(true, tog.get());
+ assertEquals(false, tog.peek());
+
+ tog.set(true);
+
+ // Check set works
+ assertEquals(true, tog.peek());
+ }
+}
diff --git a/src/test/java/bjc/data/CircularIteratorTest.java b/src/test/java/bjc/data/CircularIteratorTest.java
new file mode 100644
index 0000000..82a08c6
--- /dev/null
+++ b/src/test/java/bjc/data/CircularIteratorTest.java
@@ -0,0 +1,49 @@
+package bjc.data;
+
+import static bjc.TestUtils.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+import bjc.data.CircularIterator;
+/**
+ * Test for circular iterators.,
+ *
+ * @author bjculkin
+ *
+ */
+public class CircularIteratorTest {
+ /**
+ * Test regular repetition of the entire iterator.
+ */
+ @Test
+ public void testRegular() {
+ List<String> lst = Arrays.asList("a", "b", "c");
+
+ CircularIterator<String> itr = new CircularIterator<>(lst);
+
+ // Check we get initial values correctly, and have more remaining
+ assertIteratorEquals(true, itr, "a", "b", "c");
+
+ // Check we repeat correctly, and can still repeat
+ assertIteratorEquals(true, itr, "a", "b", "c");
+ }
+
+ /**
+ * Test that the last element repeats correctly.
+ */
+ @Test
+ public void testRepLast() {
+ List<String> lst = Arrays.asList("a", "b", "c");
+
+ CircularIterator<String> itr = new CircularIterator<>(lst, false);
+
+ // Check we get initial values correctly, and have more remaining
+ assertIteratorEquals(true, itr, "a", "b", "c");
+
+ // Check we repeat correctly, and can still repeat
+ assertIteratorEquals(true, itr, "c", "c", "c");
+ }
+}
diff --git a/src/test/java/bjc/data/QueuedIteratorTest.java b/src/test/java/bjc/data/QueuedIteratorTest.java
new file mode 100644
index 0000000..69f37b8
--- /dev/null
+++ b/src/test/java/bjc/data/QueuedIteratorTest.java
@@ -0,0 +1,74 @@
+package bjc.data;
+
+import static java.util.Arrays.asList;
+
+import org.junit.Test;
+
+import bjc.data.QueuedIterator;
+
+import static bjc.TestUtils.*;
+import static bjc.data.QueuedIterator.queued;
+
+/**
+ * Test of QueuedIterator.
+ *
+ * @author bjculkin
+ *
+ */
+public class QueuedIteratorTest {
+
+ /**
+ * Test of functionality.
+ */
+ @Test
+ public void test() {
+ assertIteratorEquals(false, queued());
+
+ assertIteratorEquals(false, queued(1, 2, 3), 1, 2, 3);
+ assertIteratorEquals(false, queued(asList(1, 2, 3), asList(3, 2, 1)), 1, 2, 3, 3, 2, 1);
+
+ }
+
+ /**
+ * Test of before() method.
+ */
+ @Test
+ public void testBefore() {
+ QueuedIterator<Integer> itr = queued(1, 2, 3);
+
+ assertIteratorEquals(true, itr, 1, 2);
+
+ itr.before(1, 2, 3);
+
+ assertIteratorEquals(false, itr, 1, 2, 3, 3);
+ }
+
+ /**
+ * Test of after() method.
+ */
+ @Test
+ public void testAfter() {
+ QueuedIterator<Integer> itr = queued(1, 2, 3);
+
+ assertIteratorEquals(true, itr, 1, 2);
+
+ itr.after(1, 2, 3);
+
+ assertIteratorEquals(false, itr, 3, 1, 2, 3);
+ }
+
+ /**
+ * Test of last() method.
+ */
+ @Test
+ public void testLast() {
+ QueuedIterator<Integer> itr = queued(1, 2, 3);
+
+ assertIteratorEquals(true, itr, 1, 2);
+
+ itr.after(4);
+ itr.last(1, 2, 3);
+
+ assertIteratorEquals(false, itr, 3, 4, 1, 2, 3);
+ }
+}