-
Notifications
You must be signed in to change notification settings - Fork 830
Expand file tree
/
Copy pathGameTest.java
More file actions
66 lines (48 loc) · 1.75 KB
/
Copy pathGameTest.java
File metadata and controls
66 lines (48 loc) · 1.75 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
package racingcar;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class GameTest {
@DisplayName("Car 객체 리스트 생성 테스트")
@Test
void addCars() {
Game game = new Game();
List<String> carNames = Arrays.asList("pobi", "woni", "crong");
List<Car> result = game.addCars(carNames);
assertEquals("pobi", result.get(0).getName());
assertEquals("woni", result.get(1).getName());
assertEquals("crong", result.get(2).getName());
}
@DisplayName("우승자 테스트")
@Test
void winnersTest(){
Game game = new Game();
List<Car> cars = new ArrayList<>();
List<String> expected = new ArrayList<>();
List<String> result = new ArrayList<>();
cars.add(new Car("win1", 4));
cars.add(new Car("win2", 4));
cars.add(new Car("lose", 2));
expected = List.of("win1", "win2");
result = game.winners(cars);
assertEquals(expected,result);
}
@DisplayName("우승자 출력 테스트")
@Test
void printWinners() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
System.setOut(printStream);
Game game = new Game();
List<String> winners = new ArrayList<>();
winners = List.of("win1", "win2");
game.printWinners(winners);
assertEquals("최종 우승자 : win1, win2\n", outputStream.toString());
}
}