-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinStackImplementationTest.java
More file actions
113 lines (90 loc) · 3.81 KB
/
MinStackImplementationTest.java
File metadata and controls
113 lines (90 loc) · 3.81 KB
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
110
111
112
113
package com.company.stack;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class MinStackImplementationTest {
@Test
public void getMin_whenMinStackContainsOneNumber_thenReturningTheValue() {
// Given
MinStack minStackImplementation = new MinStackImplementation();
int theOnlyOneNumber = 1;
minStackImplementation.push(theOnlyOneNumber);
// When
int min = minStackImplementation.getMin();
// Then
Assertions.assertThat(min).isEqualTo(theOnlyOneNumber);
}
@Test
public void getMin_whenLastInValueIsNotTheMinValue_andWhenTheLastInValueIsPushed_thenTheMinValuesIsEqualToTheValueBeforePushing() {
// Given
MinStack minStackImplementation = new MinStackImplementation();
int firstInValue = 1;
minStackImplementation.push(firstInValue);
int minValueBeforePush = minStackImplementation.getMin();
// When
int lastInValueButNeverBeingMin = 10;
minStackImplementation.push(lastInValueButNeverBeingMin);
int min = minStackImplementation.getMin();
// Then
Assertions.assertThat(min).isEqualTo(firstInValue);
}
@Test
public void getMin_whenLastInValueIsTheMinValue_andWhenTheLastInValueIsPushed_thenTheMinValuesShouldBeLastInValue() {
// Given
MinStack minStackImplementation = new MinStackImplementation();
int firstInValue = 10;
minStackImplementation.push(firstInValue);
// When
int lastInValueBeingMinValue = 1;
minStackImplementation.push(lastInValueBeingMinValue);
int min = minStackImplementation.getMin();
// Then
Assertions.assertThat(min).isEqualTo(lastInValueBeingMinValue);
}
@Test
public void getMin_whenTheTopValueIsMinValue_andWhenTheStackPopsTheValue_thenTheMinValuesShouldBeThePreviousMinValue() {
// Given
MinStack minStackImplementation = new MinStackImplementation();
int firstInValue = 10;
minStackImplementation.push(firstInValue);
int prevMinValue = minStackImplementation.getMin();
int lastInValueBeingMinValue = 1;
minStackImplementation.push(lastInValueBeingMinValue);
// When
minStackImplementation.pop();
int minValueAfterPopping = minStackImplementation.getMin();
// Then
Assertions.assertThat(minValueAfterPopping).isEqualTo(prevMinValue);
}
@Test
public void getMin_whenTheTopValueIsNotMinValue_andWhenTheStackPopsTheValue_thenTheMinValuesShouldNotChange() {
// Given
MinStack minStackImplementation = new MinStackImplementation();
int firstInValue = 1;
minStackImplementation.push(firstInValue);
int lastInValueBeingMinValue = 10;
minStackImplementation.push(lastInValueBeingMinValue);
// When
int minValueBeforePopping = minStackImplementation.getMin();
minStackImplementation.pop();
int minValueAfterPopping = minStackImplementation.getMin();
// Then
Assertions.assertThat(minValueAfterPopping).isEqualTo(minValueBeforePopping);
}
@Test
public void getMin_whenTheTopValueIsMinValue_andWhenTheStackPopsTheValue_thenTheMinValueShouldChangeToPreviousMinValue() {
// Given
MinStack minStackImplementation = new MinStackImplementation();
int firstInValue = 10;
minStackImplementation.push(firstInValue);
int lastInValueBeingMinValue = 1;
minStackImplementation.push(lastInValueBeingMinValue);
// When
minStackImplementation.pop();
int minValueAfterPopping = minStackImplementation.getMin();
// Then
Assertions.assertThat(minValueAfterPopping).isEqualTo(firstInValue);
}
}