diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-10-14 14:07:00 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-10-14 14:07:00 -0400 |
| commit | d1d01769e7c55f7f62dc01cadf420d5f63424584 (patch) | |
| tree | 5415f41c405622441840d5dd81b91ea8d7e7de31 /base/src/test/java/bjc/utils/data | |
| parent | a78d2f10f8142af6a4e557588c06546e2231eb3f (diff) | |
Testing
Diffstat (limited to 'base/src/test/java/bjc/utils/data')
| -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"); + } +} |
