From 4d0a59a0023f2b4fca144a089a3f75acb4ebd62b Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 2 Jul 2019 18:32:37 -0400 Subject: Move tests to new package --- src/test/java/io/github/bculkin2442/TestUtils.java | 60 ------------------ .../github/bculkin2442/data/BooleanToggleTest.java | 38 ----------- .../bculkin2442/data/CircularIteratorTest.java | 49 -------------- .../bculkin2442/data/QueuedIteratorTest.java | 74 ---------------------- .../bculkin2442/esodata/ThresholdSetTest.java | 46 -------------- 5 files changed, 267 deletions(-) delete mode 100644 src/test/java/io/github/bculkin2442/TestUtils.java delete mode 100644 src/test/java/io/github/bculkin2442/data/BooleanToggleTest.java delete mode 100644 src/test/java/io/github/bculkin2442/data/CircularIteratorTest.java delete mode 100644 src/test/java/io/github/bculkin2442/data/QueuedIteratorTest.java delete mode 100644 src/test/java/io/github/bculkin2442/esodata/ThresholdSetTest.java (limited to 'src/test/java/io/github/bculkin2442') diff --git a/src/test/java/io/github/bculkin2442/TestUtils.java b/src/test/java/io/github/bculkin2442/TestUtils.java deleted file mode 100644 index 80f7d96..0000000 --- a/src/test/java/io/github/bculkin2442/TestUtils.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.github.bculkin2442; - -import java.util.Iterator; -import java.util.List; - -import static org.junit.Assert.*; - -public class TestUtils { - /** - * Assert an iterator provides a particular sequence of values. - * - * @param src - * The iterator to pull values from. - * @param vals - * The values to expect from the iterator. - */ - @SafeVarargs - public static void assertIteratorEquals(Iterator src, T... vals) { - for (T val : vals) { - assertEquals(val, src.next()); - } - } - - /** - * Assert an iterator provides a particular sequence of 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 void assertIteratorEquals(boolean hasMore, Iterator 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()); - } - - @SafeVarargs - public static void assertListEquals(List src, T... exps) { - assertEquals(exps.length, src.size()); - - int i = 0; - for (T act : src) { - T exp = exps[i++]; - - assertEquals(exp, act); - } - } -} diff --git a/src/test/java/io/github/bculkin2442/data/BooleanToggleTest.java b/src/test/java/io/github/bculkin2442/data/BooleanToggleTest.java deleted file mode 100644 index 8211117..0000000 --- a/src/test/java/io/github/bculkin2442/data/BooleanToggleTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.bculkin2442.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/io/github/bculkin2442/data/CircularIteratorTest.java b/src/test/java/io/github/bculkin2442/data/CircularIteratorTest.java deleted file mode 100644 index 80fbb54..0000000 --- a/src/test/java/io/github/bculkin2442/data/CircularIteratorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.bculkin2442.data; - -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; - -import bjc.data.CircularIterator; - -import static io.github.bculkin2442.TestUtils.*; -/** - * 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(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 lst = Arrays.asList("a", "b", "c"); - - CircularIterator 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/io/github/bculkin2442/data/QueuedIteratorTest.java b/src/test/java/io/github/bculkin2442/data/QueuedIteratorTest.java deleted file mode 100644 index 0c1144b..0000000 --- a/src/test/java/io/github/bculkin2442/data/QueuedIteratorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.github.bculkin2442.data; - -import static java.util.Arrays.asList; - -import org.junit.Test; - -import bjc.data.QueuedIterator; - -import static bjc.data.QueuedIterator.queued; -import static io.github.bculkin2442.TestUtils.*; - -/** - * 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 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 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 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); - } -} diff --git a/src/test/java/io/github/bculkin2442/esodata/ThresholdSetTest.java b/src/test/java/io/github/bculkin2442/esodata/ThresholdSetTest.java deleted file mode 100644 index c8f2bd3..0000000 --- a/src/test/java/io/github/bculkin2442/esodata/ThresholdSetTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.github.bculkin2442.esodata; - -import org.junit.Test; - -import bjc.esodata.ThresholdSet; -import io.github.bculkin2442.TestUtils; - -import java.util.Iterator; - -import static org.junit.Assert.*; -import static io.github.bculkin2442.TestUtils.*; - -/** - * Tests for ThresholdSet - * - * @author Ben Culkin. - */ -public class ThresholdSetTest { - @Test - public void testAdd() { - ThresholdSet thst = new ThresholdSet<>(); - - thst.addAll("a", "b"); - - assertIteratorEquals(false, thst.setView().iterator(), "a", "b"); - } - - @Test - public void testAddMulti() { - ThresholdSet thst = new ThresholdSet<>(); - - thst.addAll("a", "b", "a"); - - assertIteratorEquals(false, thst.setView().iterator(), "b"); - } - - @Test - public void testRemoveMulti() { - ThresholdSet thst = new ThresholdSet<>(); - - thst.addAll("a", "a", "b"); - thst.removeAll("a"); - - assertIteratorEquals(false, thst.setView().iterator(), "a", "b"); - } -} -- cgit v1.2.3