diff --git a/src/main/java/racingcar/IOTest.java b/src/main/java/racingcar/IOTest.java new file mode 100644 index 00000000000..973923d6bc0 --- /dev/null +++ b/src/main/java/racingcar/IOTest.java @@ -0,0 +1,10 @@ +package racingcar; + +import java.io.ByteArrayInputStream; + +public abstract class IOTest { + + protected void systemIn(byte[] inputBytes) { + System.setIn(new ByteArrayInputStream(inputBytes)); + } +} \ No newline at end of file diff --git a/src/main/java/racingcar/InputView.java b/src/main/java/racingcar/InputView.java new file mode 100644 index 00000000000..ac5053cb8da --- /dev/null +++ b/src/main/java/racingcar/InputView.java @@ -0,0 +1,19 @@ +package racingcar; + +import java.util.Scanner; + +import static racingcar.RacingCar.toInts; + +public class InputView { + public static int numberOfCar(){ + System.out.println("자동차 대수는 몇 대 인가요?\n"); + return toInts((new Scanner(System.in)).nextLine()); + + } + + public static int numberOfRound(){ + System.out.println("시도할 회수는 몇 회 인가요?\n"); + return toInts((new Scanner(System.in)).nextLine()); + } + +} \ No newline at end of file diff --git a/src/main/java/racingcar/OutputView.java b/src/main/java/racingcar/OutputView.java new file mode 100644 index 00000000000..2c2a45093b6 --- /dev/null +++ b/src/main/java/racingcar/OutputView.java @@ -0,0 +1,15 @@ +package racingcar; + +public class OutputView { + public void racingResult(RacingCar racingCar){ + System.out.println(racingCar.resultOfRacing()); + } + + public void resultTitle(){ + System.out.println("실행 결과"); + } + + public void oneRoundEnd(){ + System.out.println(); + } +} diff --git a/src/main/java/racingcar/RacingCar.java b/src/main/java/racingcar/RacingCar.java new file mode 100644 index 00000000000..37120243d82 --- /dev/null +++ b/src/main/java/racingcar/RacingCar.java @@ -0,0 +1,49 @@ +package racingcar; + +import java.util.Random; + +public class RacingCar { + + private int position =0; + private String HYPHEN = "-"; + private int TEN = 10; + + private static final int THRESHOLD = 4; + + public RacingCar() { + } + + public void moveRacingCar(int randomNum){ + if (randomNum >= THRESHOLD){ + this.position ++; + } + } + + public int genRandomNum(){ + return new Random().nextInt(TEN); + } + + public String resultOfRacing(){ + String result = ""; + for (int i=0;i records = new ArrayList<>(); + + public void carRegister(int carNum){ + for (int i=0;i { + numberOfCar(); + }); + } + + @DisplayName("게임 횟수 음수나 숫자가 아니면 에러") + @ParameterizedTest + @CsvSource(value = {"-1: -1", "1#2#3: 1#2#3", "0:0"}, delimiter = ':') + void round_check(String numOfCar, String numOfRound) { + systemIn(numOfRound.getBytes()); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + numberOfRound(); + }); + + } +}