diff options
Diffstat (limited to 'base/src/test')
| -rw-r--r-- | base/src/test/java/bjc/utils/data/BooleanToggleTest.java | 36 | ||||
| -rw-r--r-- | base/src/test/java/bjc/utils/data/CircularIteratorTest.java | 50 |
2 files changed, 86 insertions, 0 deletions
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<String> lst = Arrays.asList("a", "b", "c"); + + CircularIterator<String> 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<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(itr, true, "a", "b", "c"); + + // Check we repeat correctly, and can still repeat + assertIteratorEquals(itr, true, "c", "c", "c"); + } +} |
