From d1d01769e7c55f7f62dc01cadf420d5f63424584 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 14 Oct 2018 14:07:00 -0400 Subject: Testing --- .../java/bjc/utils/data/BooleanToggleTest.java | 36 ++++++++++++++++ .../java/bjc/utils/data/CircularIteratorTest.java | 50 ++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 base/src/test/java/bjc/utils/data/BooleanToggleTest.java create mode 100644 base/src/test/java/bjc/utils/data/CircularIteratorTest.java (limited to 'base/src/test/java/bjc/utils') diff --git a/base/src/test/java/bjc/utils/data/BooleanToggleTest.java b/base/src/test/java/bjc/utils/data/BooleanToggleTest.java new file mode 100644 index 0000000..f2b4994 --- /dev/null +++ b/base/src/test/java/bjc/utils/data/BooleanToggleTest.java @@ -0,0 +1,36 @@ +package bjc.utils.data; + +import static org.junit.Assert.*; + +import org.junit.Test; + +/** + * 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/base/src/test/java/bjc/utils/data/CircularIteratorTest.java b/base/src/test/java/bjc/utils/data/CircularIteratorTest.java new file mode 100644 index 0000000..c08bbb1 --- /dev/null +++ b/base/src/test/java/bjc/utils/data/CircularIteratorTest.java @@ -0,0 +1,50 @@ +package bjc.utils.data; + +import static org.junit.Assert.*; +import static bjc.utils.funcutils.TestUtils.*; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +/** + * Test for circular iterators., + * + * @author bjculkin + * + */ +public class CircularIteratorTest { + + /** + * Test regular repetition of the entire iterator. + */ + @Test + public void testRegular() { + List lst = Arrays.asList("a", "b", "c"); + + CircularIterator itr = new CircularIterator<>(lst); + + // Check we get initial values correctly, and have more remaining + assertIteratorEquals(itr, true, "a", "b", "c"); + + // Check we repeat correctly, and can still repeat + assertIteratorEquals(itr, true, "a", "b", "c"); + } + + /** + * Test that the last element repeats correctly. + */ + @Test + public void testRepLast() { + List lst = Arrays.asList("a", "b", "c"); + + CircularIterator itr = new CircularIterator<>(lst, false); + + // Check we get initial values correctly, and have more remaining + assertIteratorEquals(itr, true, "a", "b", "c"); + + // Check we repeat correctly, and can still repeat + assertIteratorEquals(itr, true, "c", "c", "c"); + } +} -- cgit v1.2.3