forked from next-step/java-ladder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineTest.java
99 lines (77 loc) · 2.61 KB
/
LineTest.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
package nextstep.ladder;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
public class LineTest {
@Test
@DisplayName("사다리 라인 생성 테스트: 길이 양쪽에 생길 수 없다.")
void createTest() {
var playerCount = 5;
var trueLine = new Line(playerCount, new TrueRandom());
Assertions.assertThat(trueLine.getPoints()).isEqualTo(List.of(true, false, true, false));
}
static class TrueRandom extends Random {
@Override
public boolean nextBoolean() {
return true;
}
}
@Test
@DisplayName("cursor가 0일 때 오른쪽으로 이동")
void calculateNextPosition_cursorAtStart_movesRight() {
// given
var points = List.of(true, false, false);
var line = new Line(points);
// when
int nextPosition = line.calculateNextPosition(0);
// then
assertThat(nextPosition).isEqualTo(1);
}
@Test
@DisplayName("cursor가 마지막 위치일 때 왼쪽으로 이동")
void calculateNextPosition_cursorAtEnd_movesLeft() {
// given
var points = List.of(false, false, true);
var line = new Line(points);
// when
int nextPosition = line.calculateNextPosition(2);
// then
assertThat(nextPosition).isEqualTo(1);
}
@Test
@DisplayName("cursor가 중간에 있을 때 왼쪽으로 이동")
void calculateNextPosition_cursorInMiddle_movesLeft() {
// given
var points = List.of(false, true, false);
var line = new Line(points);
// when
int nextPosition = line.calculateNextPosition(2);
// then
assertThat(nextPosition).isEqualTo(1);
}
@Test
@DisplayName("cursor가 중간에 있을 때 오른쪽으로 이동")
void calculateNextPosition_cursorInMiddle_movesRight() {
// given
var points = List.of(false, false, true);
var line = new Line(points);
// when
int nextPosition = line.calculateNextPosition(1);
// then
assertThat(nextPosition).isEqualTo(2);
}
@Test
@DisplayName("cursor가 이동하지 않음")
void calculateNextPosition_cursorDoesNotMove() {
// given
var points = List.of(false, false, false);
var line = new Line(points);
// when
int nextPosition = line.calculateNextPosition(1);
// then
assertThat(nextPosition).isEqualTo(1);
}
}