-
Notifications
You must be signed in to change notification settings - Fork 0
/
PilhaComArrayTest.java
109 lines (96 loc) · 1.94 KB
/
PilhaComArrayTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package estruturas_estaticas;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import estruturas_estaticas.ArrayStack;
import interfaces.Stack;
/**
* Teste de unidade responsável por verificar os métodos da classe
* PilhaComArray.
*
* @author Helder Chaves Leite Junior
* @see ArrayStack
*/
class PilhaComArrayTest
{
private Stack<Integer> stack;
@BeforeEach
void criaPilhaComArray()
{
this.stack = new ArrayStack<>();
}
@Test
void testNovaPilha()
{
assertNotNull(this.stack);
assertTrue(this.stack.isEmpty());
}
@Test
void testAdicionarElementos()
{
this.stack.push(32);
this.stack.push(16);
assertFalse(this.stack.isEmpty());
assertEquals(this.stack.peek(), 16);
}
@Test
void testRemoverElementos()
{
this.stack.push(49);
assertFalse(this.stack.isEmpty());
this.stack.pop();
assertTrue(this.stack.isEmpty());
}
@Test
void testAdicionarEmPilhaCheia()
{
try
{
Stack<Integer> pilha = new ArrayStack<Integer>(2);
pilha.push(23);
pilha.push(31);
pilha.push(9);
}
catch(RuntimeException re)
{
System.out.println(re.getMessage());
}
}
@Test
void testRemoverEmPilhaVazia()
{
try
{
Stack<Integer> pilha = new ArrayStack<Integer>(2);
pilha.pop();
}
catch (RuntimeException re)
{
System.out.println(re.getMessage());
}
}
@Test
void testTamanhoPilha()
{
this.stack.push(58);
this.stack.push(291);
this.stack.push(-25);
assertEquals(this.stack.size(), 3);
}
@Test
void testAdicionaElementoAposRemocao()
{
this.stack.push(33);
this.stack.push(56);
this.stack.pop();
this.stack.push(14);
assertEquals(this.stack.peek(), 14);
}
@Test
void testElementoRemovido()
{
this.stack.push(78);
this.stack.push(-65);
assertEquals(this.stack.pop(), -65);
}
}