diff --git a/group02/727171008/src/com/github/HarryHook/coding2017/stack/QuickMinStackTest.java b/group02/727171008/src/com/github/HarryHook/coding2017/stack/QuickMinStackTest.java new file mode 100644 index 0000000000..1c2f88e96f --- /dev/null +++ b/group02/727171008/src/com/github/HarryHook/coding2017/stack/QuickMinStackTest.java @@ -0,0 +1,53 @@ +package com.github.HarryHook.coding2017.stack; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class QuickMinStackTest { + QuickMinStack stack; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void test() { + stack = new QuickMinStack(); + // 栈为空,抛出异常 + expectedEx.expect(Exception.class); + stack.pop(); + + stack.push(5); + stack.push(3); + stack.push(2); + stack.push(4); + stack.push(1); + assertEquals(1, stack.findMin()); + assertEquals(1, stack.pop()); + assertEquals(2, stack.findMin()); + assertEquals(4, stack.pop()); + assertEquals(2, stack.findMin()); + assertEquals(2, stack.pop()); + assertEquals(3, stack.findMin()); + assertEquals(3, stack.pop()); + assertEquals(5, stack.findMin()); + assertEquals(5, stack.pop()); + + expectedEx.expect(Exception.class); + stack.pop(); + + } + +} diff --git a/group02/727171008/src/com/github/HarryHook/coding2017/stack/StackWithTwoQueuesTest.java b/group02/727171008/src/com/github/HarryHook/coding2017/stack/StackWithTwoQueuesTest.java new file mode 100644 index 0000000000..87038ab3df --- /dev/null +++ b/group02/727171008/src/com/github/HarryHook/coding2017/stack/StackWithTwoQueuesTest.java @@ -0,0 +1,47 @@ +package com.github.HarryHook.coding2017.stack; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import sun.java2d.StateTrackable; + +public class StackWithTwoQueuesTest { + StackWithTwoQueues stack; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void test() { + stack = new StackWithTwoQueues(); + // 栈为空,抛出异常 + expectedEx.expect(Exception.class); + stack.pop(); + + stack.push(1); + stack.push(2); + stack.push(3); + assertEquals(3, stack.pop()); + stack.push(43); + assertEquals(43, stack.pop()); + assertEquals(2, stack.pop()); + assertEquals(1, stack.pop()); + + expectedEx.expect(Exception.class); + stack.pop(); + } + +} diff --git a/group02/727171008/src/com/github/HarryHook/coding2017/stack/TwoStackInOneArrayTest.java b/group02/727171008/src/com/github/HarryHook/coding2017/stack/TwoStackInOneArrayTest.java new file mode 100644 index 0000000000..d37c39d156 --- /dev/null +++ b/group02/727171008/src/com/github/HarryHook/coding2017/stack/TwoStackInOneArrayTest.java @@ -0,0 +1,79 @@ +package com.github.HarryHook.coding2017.stack; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class TwoStackInOneArrayTest { + TwoStackInOneArray stack; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void test() { + stack = new TwoStackInOneArray(); + stack.push1(3); + stack.push1(5); + stack.push1(6); + stack.push1(11); + assertEquals(11, stack.peek1()); + assertEquals(11, stack.pop1()); + assertEquals(6, stack.pop1()); + stack.push1(61); + assertEquals(61, stack.pop1()); + assertEquals(5, stack.pop1()); + assertEquals(3, stack.peek1()); + assertEquals(3, stack.pop1()); + // 栈1为空,抛出异常 + expectedEx.expect(Exception.class); + stack.pop1(); + + stack.push2(123); + stack.push2(1); + stack.push2(4); + + stack.push1(3); + stack.push1(5); + stack.push1(6); + + stack.push2(123); + stack.push2(1); + stack.push2(4); + stack.push2(12); + stack.push2(2); + stack.push2(8); + + assertEquals(6, stack.pop1()); + assertEquals(5, stack.peek1()); + assertEquals(5, stack.pop1()); + assertEquals(3, stack.pop1()); + + assertEquals(8, stack.pop2()); + assertEquals(2, stack.pop2()); + assertEquals(12, stack.pop2()); + assertEquals(4, stack.pop2()); + assertEquals(1, stack.pop2()); + assertEquals(123, stack.pop2()); + assertEquals(4, stack.pop2()); + assertEquals(1, stack.pop2()); + assertEquals(123, stack.pop2()); + // 栈2为空,抛出异常 + expectedEx.expect(Exception.class); + stack.pop2(); + + } + +}