-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathSmallestElementConstantTimeTest.java
69 lines (59 loc) · 1.63 KB
/
SmallestElementConstantTimeTest.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
package com.thealgorithms.stacks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class SmallestElementConstantTimeTest {
private SmallestElementConstantTime sect;
@BeforeEach
public void setSect() {
sect = new SmallestElementConstantTime();
}
@Test
public void testMinAtFirst() {
sect.push(1);
sect.push(10);
sect.push(20);
sect.push(5);
assertEquals(1, sect.getMinimumElement());
}
@Test
public void testMinTwo() {
sect.push(5);
sect.push(10);
sect.push(20);
sect.push(1);
assertEquals(1, sect.getMinimumElement());
sect.pop();
assertEquals(5, sect.getMinimumElement());
}
@Test
public void testNullMin() {
sect.push(10);
sect.push(20);
sect.pop();
sect.pop();
assertNull(sect.getMinimumElement());
}
@Test
public void testBlankHandle() {
sect.push(10);
sect.push(1);
sect.pop();
sect.pop();
assertThrows(NoSuchElementException.class, () -> sect.pop());
}
@Test
public void testPushPopAfterEmpty() {
sect.push(10);
sect.push(1);
sect.pop();
sect.pop();
sect.push(5);
assertEquals(5, sect.getMinimumElement());
sect.push(1);
assertEquals(1, sect.getMinimumElement());
}
}