Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2.  
  3. import java.util.EmptyStackException;
  4.  
  5. import org.junit.Test;
  6.  
  7. public class testsStack {
  8.  
  9. @Test
  10. public void TestIsEmpty()
  11. {
  12. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  13. assertEquals(true,stack.isEmpty());
  14. }
  15.  
  16. @Test
  17. public void TestPushOneElement() {
  18. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  19. stack.push(10);
  20. assertEquals(false,stack.isEmpty());
  21. }
  22.  
  23. @Test
  24. public void TestPushMoreElements(int x) {
  25. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  26. for(int i=0; i<x; i++) {
  27. stack.push(x);
  28. }
  29. assertEquals(false,stack.isEmpty());
  30. }
  31.  
  32. @Test(expected=IllegalArgumentException.class)
  33. public void stackDoesntAcceptNullAndThrowExcpetion() {
  34. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  35. stack.push(null);
  36. }
  37.  
  38. @Test
  39. public void TestPopOneElement( ){
  40. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  41. stack.push(10);
  42. stack.pop();
  43. assertEquals(true,stack.isEmpty());
  44. }
  45.  
  46. @Test
  47. public void TestPopMoreElements( int x){
  48. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  49. for(int i=0; i<x; i++) {
  50. stack.push(x);
  51. }
  52. for(int i=0; i<x; i++) {
  53. stack.pop();
  54. }
  55. assertEquals(true,stack.isEmpty());
  56. }
  57.  
  58. @Test(expected=EmptyStackException.class)
  59. public void TestPopEmptyStack( ){
  60. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  61. stack.pop();
  62. }
  63.  
  64.  
  65. @Test
  66. public void TestPeek() {
  67. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  68. stack.push(10);
  69. assertEquals(new Integer( 10 ),stack.peek());
  70. }
  71.  
  72. @Test(expected=EmptyStackException.class)
  73. public void TestPeekpEmptyStack( ){
  74. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  75. stack.peek();
  76. }
  77.  
  78. @Test
  79. public void TestSize() {
  80. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  81. stack.push(10);
  82. assertEquals(1,stack.size());
  83. }
  84.  
  85. @Test
  86. public void TestSizeEmpty() {
  87. LinkedStack<Integer> stack=new LinkedStack<Integer>();
  88. assertEquals(0,stack.size());
  89. }
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement