forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHistoryTest.java
66 lines (54 loc) · 2.15 KB
/
HistoryTest.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
package seedu.address.logic.history;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.commons.util.CopyableInt.COPYABLE_ONE;
import static seedu.address.commons.util.CopyableInt.COPYABLE_THREE;
import static seedu.address.commons.util.CopyableInt.COPYABLE_TWO;
import static seedu.address.commons.util.CopyableInt.COPYABLE_ZERO;
import org.junit.jupiter.api.Test;
import seedu.address.commons.util.CopyableInt;
public class HistoryTest {
private Historyable<CopyableInt> history = new History<>();
protected HistoryTest() {
history.push(COPYABLE_ZERO);
history.push(COPYABLE_ONE);
history.push(COPYABLE_TWO);
}
@Test
void size_success() {
assertEquals(3, history.size());
}
@Test
void go_validInput_success() {
CopyableInt copyableOne = history.go(-1);
assertEquals(COPYABLE_ONE.getNumber(), copyableOne.getNumber());
}
@Test
void go_tooLargeInput_success() {
CopyableInt copyableTwo = history.go(100); // Should return the last pushed item.
assertEquals(COPYABLE_TWO.getNumber(), copyableTwo.getNumber());
}
@Test
void go_tooSmallInput_success() {
CopyableInt copyableZero = history.go(-100); // Should return the first pushed item.
assertEquals(COPYABLE_ZERO.getNumber(), copyableZero.getNumber());
}
@Test
void push_expected_success() {
history.push(COPYABLE_THREE);
CopyableInt currentCopyableInt = history.getCurrentState();
assertNotEquals(COPYABLE_THREE, currentCopyableInt);
assertEquals(COPYABLE_THREE.getNumber(), currentCopyableInt.getNumber());
}
@Test
void push_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> history.push(null));
}
@Test
void pop_success() {
CopyableInt poppedCopyableInt = history.pop();
assertNotEquals(COPYABLE_TWO, poppedCopyableInt);
assertEquals(COPYABLE_TWO.getNumber(), poppedCopyableInt.getNumber());
}
}