summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/esodata
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2019-07-10 17:10:51 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2019-07-10 17:10:51 -0400
commite401fb037c555eb18db54708037a796523258c32 (patch)
tree78aa519089a71fe056524abdc28af4894e2640cd /src/test/java/bjc/esodata
parent4d0a59a0023f2b4fca144a089a3f75acb4ebd62b (diff)
General improvements to stack
Diffstat (limited to 'src/test/java/bjc/esodata')
-rw-r--r--src/test/java/bjc/esodata/StackTest.java152
-rw-r--r--src/test/java/bjc/esodata/ThresholdSetTest.java60
2 files changed, 199 insertions, 13 deletions
diff --git a/src/test/java/bjc/esodata/StackTest.java b/src/test/java/bjc/esodata/StackTest.java
new file mode 100644
index 0000000..568e6ea
--- /dev/null
+++ b/src/test/java/bjc/esodata/StackTest.java
@@ -0,0 +1,152 @@
+package bjc.esodata;
+
+import org.junit.Test;
+
+import bjc.TestUtils;
+
+import java.util.*;
+
+import static bjc.TestUtils.*;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests of Stack.
+ *
+ * @author Ben Culkin
+ */
+public class StackTest {
+ @Test
+ public void testBasic() {
+ Stack<String> st = new SimpleStack<>();
+
+ assertEquals(0, st.size());
+
+ st.push("a");
+ assertEquals(1, st.size());
+
+ assertEquals("a", st.top());
+ assertEquals(1, st.size());
+
+ assertEquals("a", st.pop());
+ assertEquals(0, st.size());
+ assertTrue(st.isEmpty());
+ }
+
+ @Test
+ public void testSpaghetti() {
+ Stack<String> st = new SimpleStack<>();
+
+ st.pushAll("a", "b", "c");
+
+ Stack<String> spst1 = st.spaghettify();
+ Stack<String> spst2 = st.spaghettify();
+
+ // st should be [a, b, c]
+ // spst1 should be [[a, b, c]]
+ // spst2 should be [[a, b, c]]
+
+ assertEquals("c", st.top());
+ assertEquals("c", spst1.top());
+ assertEquals("c", spst2.top());
+
+ assertEquals(3, st.size());
+ assertEquals(3, spst1.size());
+ assertEquals(3, spst2.size());
+
+ st.push("d");
+ spst1.push("e");
+ spst2.push("f");
+
+ // st should be [a, b, c, d]
+ // spst1 should be [[a, b, c, d], e]
+ // spst2 should be [[a, b, c, d], f]
+
+ assertEquals("d", st.top());
+ assertEquals("e", spst1.top());
+ assertEquals("f", spst2.top());
+
+ assertEquals(4, st.size());
+ assertEquals(5, spst1.size());
+ assertEquals(5, spst2.size());
+
+ spst1.pop();
+
+ // st should be [a, b, c]
+ // spst1 should be [[a, b, c]]
+ // spst2 should be [[a, b, c], f]
+
+ assertEquals("d", spst1.pop());
+ assertEquals("c", st.top());
+
+ assertEquals(3, st.size());
+ assertEquals(3, spst1.size());
+ assertEquals(4, spst2.size());
+ }
+
+ @Test
+ public void testBasicComb() {
+ Stack<String> st = new SimpleStack<>();
+
+ st.pushAll("a", "b", "c", "d");
+
+ st.drop();
+
+ // stack should be [a, b, c]
+
+ assertEquals("c", st.top());
+ assertEquals(3, st.size());
+
+ st.drop(2);
+
+ // stack should be [a]
+
+ assertEquals("a", st.top());
+ assertEquals(1, st.size());
+
+ st.pushAll("b", "c", "d");
+
+ st.nip();
+ st.nip();
+
+ // stack should be [a, d]
+ assertEquals("d", st.top());
+ assertEquals(2, st.size());
+
+ st.pop();
+
+ assertEquals("a", st.top());
+ assertEquals(1, st.size());
+
+ st.multidup(1, 1);
+
+ // stack should be [a, a]
+ assertEquals("a", st.top());
+ assertEquals(2, st.size());
+
+ st.pushAll("b", "c");
+
+ st.multidup(3, 1);
+
+ // stack should be [a, a, b, c, a, b, c]
+ assertEquals("c", st.top());
+ assertEquals(7, st.size());
+
+ st.pop();
+ assertEquals("b", st.pop());
+ assertEquals("a", st.pop());
+ assertEquals("c", st.top());
+
+ // stack should be [a, a, b, c]
+
+ st.dup();
+ assertEquals("c", st.top());
+ assertEquals(5, st.size());
+
+ // stack should be [a, a, b, c, c]
+ assertEquals("c", st.pop());
+ assertEquals(4, st.size());
+
+ // stack should be [a, a, b, c]
+ }
+}
diff --git a/src/test/java/bjc/esodata/ThresholdSetTest.java b/src/test/java/bjc/esodata/ThresholdSetTest.java
index b37f866..6995ad8 100644
--- a/src/test/java/bjc/esodata/ThresholdSetTest.java
+++ b/src/test/java/bjc/esodata/ThresholdSetTest.java
@@ -3,11 +3,13 @@ package bjc.esodata;
import org.junit.Test;
import bjc.TestUtils;
-import bjc.esodata.ThresholdSet;
-import java.util.Iterator;
+import java.util.*;
import static bjc.TestUtils.*;
+
+import static bjc.esodata.ThresholdSet.*;
+
import static org.junit.Assert.*;
/**
@@ -18,29 +20,61 @@ import static org.junit.Assert.*;
public class ThresholdSetTest {
@Test
public void testAdd() {
- ThresholdSet<String> thst = new ThresholdSet<>();
-
- thst.addKeys("a", "b");
+ ThresholdSet<String> thst = TS("a", "b");
- assertIteratorEquals(false, thst.setView().iterator(), "a", "b");
+ assertIteratorSet(false, thst.setView().iterator(), "a", "b");
+ assertEquals(thst.setSize(), 2);
}
@Test
public void testAddMulti() {
- ThresholdSet<String> thst = new ThresholdSet<>();
+ ThresholdSet<String> thst = TS("a", "b", "a");
- thst.addKeys("a", "b", "a");
+ assertIteratorSet(false, thst.setView().iterator(), "b");
+ assertEquals(thst.setSize(), 1);
+ }
- assertIteratorEquals(false, thst.setView().iterator(), "b");
+ @Test
+ public void testAddMulti2() {
+ ThresholdSet<String> thst = TS("a", "b");
+ thst.add("a");
+
+ assertIteratorSet(false, thst.setView().iterator(), "b");
+ assertEquals(thst.setSize(), 1);
+ }
+
+ @Test
+ public void testContains() {
+ ThresholdSet<String> thst = TS("1", "2", "2", "x", "z");
+
+ int[] exps = new int[] {1, 2, -1};
+ assertArrayEquals(exps, thst.containsKeys("1", "2", "y"));
}
@Test
public void testRemoveMulti() {
- ThresholdSet<String> thst = new ThresholdSet<>();
+ ThresholdSet<String> thst = TS("a", "a", "b");
+
+ thst.remove("a");
+
+ assertIteratorSet(false, thst.setView().iterator(), "a", "b");
+ assertEquals(2, thst.setSize());
+
+ thst.remove("a");
+
+ assertIteratorSet(false, thst.setView().iterator(), "b");
+ assertEquals(1, thst.setSize());
+ }
+
+ @Test
+ public void testSetTransparency() {
+ ThresholdSet<String> thst = TS("a", "b", "c");
- thst.addKeys("a", "a", "b");
- thst.removeKeys("a");
+ thst.setView().add("b");
+ assertIteratorSet(false, thst.setView().iterator(), "a", "c");
+ assertEquals(2, thst.setView().size());
- assertIteratorEquals(false, thst.setView().iterator(), "a", "b");
+ thst.setView().remove("c");
+ assertIteratorSet(false, thst.setView().iterator(), "a");
}
}