|
| 1 | +import org.junit.jupiter.api.Test; |
| 2 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 3 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 4 | + |
| 5 | +import static org.junit.jupiter.api.Assertions.*; |
| 6 | +import static org.mockito.Mockito.*; |
| 7 | +import java.util.*; |
| 8 | + |
| 9 | +@ExtendWith(MockitoExtension.class) |
| 10 | +class GameTest { |
| 11 | + @Test |
| 12 | + void 자동차_전진_테스트() { |
| 13 | + RacingGame game = new RacingGame(new Random()); |
| 14 | + game.initializeGame(new String[]{"neo", "brie"}, 5); |
| 15 | + |
| 16 | + RacingCar neo = game.getRacingCars().get(0); |
| 17 | + neo.move(4); |
| 18 | + assertEquals(1, neo.getForwardCount()); |
| 19 | + |
| 20 | + neo.move(3); |
| 21 | + assertEquals(1, neo.getForwardCount()); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + void 우승자_선택_테스트() { |
| 26 | + RacingGame game = new RacingGame(new Random()); |
| 27 | + game.initializeGame(new String[]{"neo", "brie"}, 5); |
| 28 | + |
| 29 | + game.getRacingCars().get(0).move(5); |
| 30 | + game.getRacingCars().get(1).move(3); |
| 31 | + |
| 32 | + List<String> winners = game.findWinners(); |
| 33 | + assertEquals(Collections.singletonList("neo"), winners); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void 랜덤_전진_테스트() { |
| 38 | + Random mockRandom = mock(Random.class); |
| 39 | + when(mockRandom.nextInt(10)).thenReturn(4, 2, 7, 8, 3); |
| 40 | + |
| 41 | + RacingGame game = new RacingGame(mockRandom); |
| 42 | + game.initializeGame(new String[]{"pobi", "crong"}, 5); |
| 43 | + |
| 44 | + game.playRound(); // 1라운드 실행 |
| 45 | + assertEquals(1, game.getRacingCars().get(0).getForwardCount()); |
| 46 | + assertEquals(0, game.getRacingCars().get(1).getForwardCount()); |
| 47 | + |
| 48 | + game.playRound(); |
| 49 | + assertEquals(2, game.getRacingCars().get(0).getForwardCount()); |
| 50 | + assertEquals(1, game.getRacingCars().get(1).getForwardCount()); |
| 51 | + } |
| 52 | +} |
0 commit comments