Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.*;
- import java.util.EmptyStackException;
- import org.junit.Test;
- public class testsStack {
- @Test
- public void TestIsEmpty()
- {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- assertEquals(true,stack.isEmpty());
- }
- @Test
- public void TestPushOneElement() {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.push(10);
- assertEquals(false,stack.isEmpty());
- }
- @Test
- public void TestPushMoreElements(int x) {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- for(int i=0; i<x; i++) {
- stack.push(x);
- }
- assertEquals(false,stack.isEmpty());
- }
- @Test(expected=IllegalArgumentException.class)
- public void stackDoesntAcceptNullAndThrowExcpetion() {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.push(null);
- }
- @Test
- public void TestPopOneElement( ){
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.push(10);
- stack.pop();
- assertEquals(true,stack.isEmpty());
- }
- @Test
- public void TestPopMoreElements( int x){
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- for(int i=0; i<x; i++) {
- stack.push(x);
- }
- for(int i=0; i<x; i++) {
- stack.pop();
- }
- assertEquals(true,stack.isEmpty());
- }
- @Test(expected=EmptyStackException.class)
- public void TestPopEmptyStack( ){
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.pop();
- }
- @Test
- public void TestPeek() {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.push(10);
- assertEquals(new Integer( 10 ),stack.peek());
- }
- @Test(expected=EmptyStackException.class)
- public void TestPeekpEmptyStack( ){
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.peek();
- }
- @Test
- public void TestSize() {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- stack.push(10);
- assertEquals(1,stack.size());
- }
- @Test
- public void TestSizeEmpty() {
- LinkedStack<Integer> stack=new LinkedStack<Integer>();
- assertEquals(0,stack.size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement