-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathCarTest.java
More file actions
62 lines (51 loc) · 1.58 KB
/
CarTest.java
File metadata and controls
62 lines (51 loc) · 1.58 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
package model;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
class CarTest {
private Car car;
@BeforeEach
void setCar(){
car = new Car("test");
}
@Test
@DisplayName("이름이 제대로 입력 되는지 테스트")
void getName(){
assertEquals("test", car.getName());
}
@RepeatedTest(100)
@DisplayName("자동차가 한칸씩 전진하는지 테스트")
void moveForward_한칸_전진() {
// given
int beforeDistance = car.getDistance();
// when
car.moveForward();
// then
assertTrue(car.getDistance() - beforeDistance == 1 || car.getDistance() == beforeDistance);
}
@Test
@DisplayName("자동차가 한번에 두칸 이상 전진 테스트")
void moveForward_한번에_두칸_이상_전진(){
// given
int beforeDistance = car.getDistance();
// when
car.moveForward();
// then
assertFalse(car.getDistance() - beforeDistance > 1);
}
@Test
@DisplayName("자동차 여러번 전진 테스트")
void moveForward_여러번_전진() {
// given
int beforeDistance = car.getDistance();
int repeat = 100;
// when
for (int i = 0; i < repeat; i++) {
car.moveForward();
}
// then
assertTrue(car.getDistance() - beforeDistance >= 0 && car.getDistance() - beforeDistance <= repeat);
}
}