|
1 | 1 | package com.thealgorithms.stacks;
|
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 6 | + |
3 | 7 | import org.junit.jupiter.api.BeforeEach;
|
4 | 8 | import org.junit.jupiter.api.Test;
|
5 | 9 |
|
6 | 10 | import java.util.NoSuchElementException;
|
7 | 11 |
|
8 |
| -import static org.junit.jupiter.api.Assertions.*; |
9 |
| - |
10 | 12 | public class GreatestElementConstantTimeTest {
|
11 | 13 |
|
12 |
| - private GreatestElementConstantTime gect; |
| 14 | + private GreatestElementConstantTime constantTime; |
13 | 15 |
|
14 | 16 | @BeforeEach
|
15 |
| - public void setGect() { |
16 |
| - gect = new GreatestElementConstantTime(); |
| 17 | + public void setConstantTime() { |
| 18 | + constantTime = new GreatestElementConstantTime(); |
17 | 19 | }
|
18 | 20 |
|
19 | 21 | @Test
|
20 | 22 | public void testMaxAtFirst() {
|
21 |
| - gect.push(1); |
22 |
| - gect.push(10); |
23 |
| - gect.push(20); |
24 |
| - gect.push(5); |
25 |
| - assertEquals(20, gect.getMaximumElement()); |
| 23 | + constantTime.push(1); |
| 24 | + constantTime.push(10); |
| 25 | + constantTime.push(20); |
| 26 | + constantTime.push(5); |
| 27 | + assertEquals(20, constantTime.getMaximumElement()); |
26 | 28 | }
|
27 | 29 |
|
28 | 30 | @Test
|
29 | 31 | public void testMinTwo() {
|
30 |
| - gect.push(5); |
31 |
| - gect.push(10); |
32 |
| - gect.push(20); |
33 |
| - gect.push(1); |
34 |
| - assertEquals(20, gect.getMaximumElement()); |
35 |
| - gect.pop(); |
36 |
| - gect.pop(); |
37 |
| - assertEquals(10, gect.getMaximumElement()); |
| 32 | + constantTime.push(5); |
| 33 | + constantTime.push(10); |
| 34 | + constantTime.push(20); |
| 35 | + constantTime.push(1); |
| 36 | + assertEquals(20, constantTime.getMaximumElement()); |
| 37 | + constantTime.pop(); |
| 38 | + constantTime.pop(); |
| 39 | + assertEquals(10, constantTime.getMaximumElement()); |
38 | 40 | }
|
39 | 41 |
|
40 | 42 | @Test
|
41 | 43 | public void testNullMax() {
|
42 |
| - gect.push(10); |
43 |
| - gect.push(20); |
44 |
| - gect.pop(); |
45 |
| - gect.pop(); |
46 |
| - assertNull(gect.getMaximumElement()); |
| 44 | + constantTime.push(10); |
| 45 | + constantTime.push(20); |
| 46 | + constantTime.pop(); |
| 47 | + constantTime.pop(); |
| 48 | + assertNull(constantTime.getMaximumElement()); |
47 | 49 | }
|
48 | 50 |
|
49 | 51 | @Test
|
50 | 52 | public void testBlankHandle() {
|
51 |
| - gect.push(10); |
52 |
| - gect.push(1); |
53 |
| - gect.pop(); |
54 |
| - gect.pop(); |
55 |
| - assertThrows(NoSuchElementException.class, () -> gect.pop()); |
| 53 | + constantTime.push(10); |
| 54 | + constantTime.push(1); |
| 55 | + constantTime.pop(); |
| 56 | + constantTime.pop(); |
| 57 | + assertThrows(NoSuchElementException.class, () -> constantTime.pop()); |
56 | 58 | }
|
57 | 59 | }
|
0 commit comments