diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/baseball/App.java b/src/main/java/baseball/App.java new file mode 100644 index 0000000..a392cc1 --- /dev/null +++ b/src/main/java/baseball/App.java @@ -0,0 +1,17 @@ +package baseball; + +import baseball.controller.GameController; +import baseball.game.Game; + +import java.util.Scanner; + +public class App { + public static void main(String[] args) { + Game game = new Game(); + Scanner scanner = new Scanner(System.in); + + GameController gameController = new GameController(game, scanner); + + gameController.run(); + } +} diff --git a/src/main/java/baseball/checker/BallChecker.java b/src/main/java/baseball/checker/BallChecker.java new file mode 100644 index 0000000..d5deace --- /dev/null +++ b/src/main/java/baseball/checker/BallChecker.java @@ -0,0 +1,32 @@ +package baseball.checker; + +import baseball.matcher.NumberMatcher; +import baseball.matcher.PositionMatcher; +import baseball.config.Constants; +import java.util.List; + +public class BallChecker { + private final NumberMatcher numberMatcher; + private final PositionMatcher positionMatcher; + + public BallChecker() { + this.numberMatcher = new NumberMatcher(); + this.positionMatcher = new PositionMatcher(); + } + + public int countBalls(List guess, List answer) { + int ballCount = Constants.ZERO; + for (int i = 0; i < Constants.NUMBER_COUNT; i++) { + if (isBall(guess.get(i), answer, i)) { + ballCount++; + } + } + return ballCount; + } + + private boolean isBall(int guessedNumber, List answer, int index) { + // 볼 조건: 위치가 맞지 않고 숫자가 정답에 포함된 경우 + return !positionMatcher.isPositionMatching(answer, guessedNumber, index) + && answer.contains(guessedNumber); + } +} diff --git a/src/main/java/baseball/checker/StrikeChecker.java b/src/main/java/baseball/checker/StrikeChecker.java new file mode 100644 index 0000000..fc6ccc6 --- /dev/null +++ b/src/main/java/baseball/checker/StrikeChecker.java @@ -0,0 +1,32 @@ +package baseball.checker; + +import baseball.matcher.NumberMatcher; +import baseball.matcher.PositionMatcher; +import baseball.config.Constants; +import java.util.List; + +// 스트라이크 개수 계산 +public class StrikeChecker { + private final NumberMatcher numberMatcher; + private final PositionMatcher positionMatcher; + + public StrikeChecker() { + this.numberMatcher = new NumberMatcher(); + this.positionMatcher = new PositionMatcher(); + } + + public int countStrikes(List guess, List answer) { + int strikeCount = Constants.ZERO; + for (int i = 0; i < Constants.NUMBER_COUNT; i++) { + if (isStrike(guess.get(i), answer, i)) { + strikeCount++; + } + } + return strikeCount; + } + + private boolean isStrike(int guessedNumber, List answer, int index) { + return numberMatcher.isMatching(guessedNumber, answer.get(index)) + && positionMatcher.isPositionMatching(answer, guessedNumber, index); + } +} diff --git a/src/main/java/baseball/config/Constants.java b/src/main/java/baseball/config/Constants.java new file mode 100644 index 0000000..1b972b5 --- /dev/null +++ b/src/main/java/baseball/config/Constants.java @@ -0,0 +1,9 @@ +package baseball.config; + +public class Constants { + public static final int NUMBER_COUNT = 3; // 숫자 개수 + public static final int MIN_NUMBER = 1; // 최소 숫자 + public static final int MAX_NUMBER = 9; // 최대 숫자 + public static final int ZERO = 0; + public static final int WINNING_STRIKES = 3; +} diff --git a/src/main/java/baseball/controller/GameController.java b/src/main/java/baseball/controller/GameController.java new file mode 100644 index 0000000..36f4306 --- /dev/null +++ b/src/main/java/baseball/controller/GameController.java @@ -0,0 +1,32 @@ +package baseball.controller; + +import baseball.game.Game; +import baseball.io.Message; + +import java.util.Scanner; + +public class GameController { + private final Game game; + private final Scanner scanner; + + // 의존성 주입: 외부에서 객체를 주입받도록 생성자 수정 + public GameController(Game game, Scanner scanner) { + this.game = game; + this.scanner = scanner; + } + + public void run() { + boolean isRunning = true; + while (isRunning) { + game.start(); + isRunning = promptRestart(); + } + Message.printMessage(Message.GAME_END); + } + + private boolean promptRestart() { + Message.printMessage(Message.RESTART_PROMPT); + String choice = scanner.nextLine().trim(); + return choice.equals("1"); + } +} diff --git a/src/main/java/baseball/game/Game.java b/src/main/java/baseball/game/Game.java new file mode 100644 index 0000000..ccc0974 --- /dev/null +++ b/src/main/java/baseball/game/Game.java @@ -0,0 +1,60 @@ +package baseball.game; + +import baseball.validation.Validator; +import baseball.io.InputView; +import baseball.io.ResultView; +import baseball.model.Result; + +import java.util.List; + +public class Game { + private List answer; + private Validator validator; + private RandomNumberGenerator randomNumberGenerator; + private GuessChecker guessChecker; + + public Game() { + this.randomNumberGenerator = new RandomNumberGenerator(); + this.answer = randomNumberGenerator.generate(); + this.validator = new Validator(); + this.guessChecker = new GuessChecker(answer); + } + + public Game(List answer) { + this.answer = answer; + this.validator = new Validator(); + this.guessChecker = new GuessChecker(answer); + } + + // 주석으로 바꾸면 RED + public List getAnswer() { + return answer; + } + // 주석으로 바꾸면 RED + public Result checkGuess(List guess) { + validator.validate(guess); // 유효성 검사 + return guessChecker.check(guess); // 스트라이크와 볼 계산 후 Result 반환 + } + + public void start() { + boolean isCorrect = false; + while (!isCorrect) { + try { + List guess = InputView.getUserInput(); + validator.validate(guess); + + // GuessChecker로부터 얻는 결과를 StrikeAndBall로 변경 + Result strikeAndBall = guessChecker.check(guess); + + // StrikeAndBall 객체를 ResultView로 전달 + ResultView.printResult(strikeAndBall); + + // 스트라이크가 3개일 때 isCorrect를 true로 설정 + isCorrect = strikeAndBall.getStrike() == 3; + } catch (IllegalArgumentException e) { + System.out.println("입력 오류: " + e.getMessage()); + } + } + System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); + } +} diff --git a/src/main/java/baseball/game/GuessChecker.java b/src/main/java/baseball/game/GuessChecker.java new file mode 100644 index 0000000..9520a14 --- /dev/null +++ b/src/main/java/baseball/game/GuessChecker.java @@ -0,0 +1,26 @@ +package baseball.game; + +import baseball.checker.BallChecker; +import baseball.checker.StrikeChecker; +import baseball.model.Result; +import baseball.model.Result; + +import java.util.List; + +class GuessChecker { + private List answer; + private StrikeChecker strikeChecker; + private BallChecker ballChecker; + + public GuessChecker(List answer) { + this.answer = answer; + this.strikeChecker = new StrikeChecker(); + this.ballChecker = new BallChecker(); + } + + public Result check(List guess) { + int strike = strikeChecker.countStrikes(guess, answer); + int ball = ballChecker.countBalls(guess, answer); + return new Result(strike, ball); + } +} diff --git a/src/main/java/baseball/game/RandomNumberGenerator.java b/src/main/java/baseball/game/RandomNumberGenerator.java new file mode 100644 index 0000000..368aeda --- /dev/null +++ b/src/main/java/baseball/game/RandomNumberGenerator.java @@ -0,0 +1,22 @@ +package baseball.game; + +import baseball.config.Constants; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class RandomNumberGenerator { + + public List generate() { + List numbers = new ArrayList<>(); + Random random = new Random(); + while (numbers.size() < Constants.NUMBER_COUNT) { + int num = random.nextInt(Constants.MAX_NUMBER) + Constants.MIN_NUMBER; + if (!numbers.contains(num)) { + numbers.add(num); + } + } + return numbers; + } +} diff --git a/src/main/java/baseball/io/InputView.java b/src/main/java/baseball/io/InputView.java new file mode 100644 index 0000000..d148229 --- /dev/null +++ b/src/main/java/baseball/io/InputView.java @@ -0,0 +1,67 @@ +package baseball.io; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class InputView { + + private static final Scanner scanner = new Scanner(System.in); + + public static List getUserInput() { + while (true) { + try { + String input = getInputFromUser(); + validateRawInput(input); + List numbers = extractNumbers(input); + validateNumbers(numbers); + return numbers; + } catch (IllegalArgumentException e) { + System.out.println("ERROR : " + e.getMessage()); + } + } + } + + private static String getInputFromUser() { + System.out.print("숫자를 입력해 주세요(1에서 9 사이의 숫자 3개): "); + return scanner.nextLine().trim(); + } + + static void validateRawInput(String input) { + if (input.isEmpty()) { + throw new IllegalArgumentException("입력값이 비어있습니다. 숫자 3개를 입력하세요."); + } + if (input.length() != 3) { + throw new IllegalArgumentException("입력값은 정확히 3자리여야 합니다."); + } + if (!input.matches("[1-9]+")) { // 숫자가 아닌 문자나 특수기호를 처리 + throw new IllegalArgumentException("입력값에는 1에서 9 사이의 숫자만 포함되어야 합니다."); + } + } + + static List extractNumbers(String input) { + List numbers = new ArrayList<>(); + + // 입력에서 숫자만 추출하고 공백은 무시 + for (char c : input.toCharArray()) { + if (Character.isDigit(c)) { + int num = Character.getNumericValue(c); + numbers.add(num); + } + } + + return numbers; + } + + static void validateNumbers(List numbers) { + if (numbers.size() != 3) { + throw new IllegalArgumentException("숫자 3개를 정확히 입력해야 합니다."); + } + if (numbers.stream().distinct().count() != 3) { + throw new IllegalArgumentException("각 숫자는 중복되지 않아야 합니다."); + } + if (!numbers.stream().allMatch(n -> n >= 1 && n <= 9)) { + throw new IllegalArgumentException("모든 숫자는 1에서 9 사이여야 합니다."); + } + } +} diff --git a/src/main/java/baseball/io/Message.java b/src/main/java/baseball/io/Message.java new file mode 100644 index 0000000..bd90579 --- /dev/null +++ b/src/main/java/baseball/io/Message.java @@ -0,0 +1,12 @@ +package baseball.io; + +public class Message { + + public static final String RESTART_PROMPT = "게임을 새로 시작은 1, 종료 2를 입력하세요."; + public static final String GAME_END = "게임 종료"; + public static final String GAME_COMPLETE = "3개의 숫자를 모두 맞히셨습니다! 게임 종료한다요~~~~~~~~~"; + + public static void printMessage(String message) { + System.out.println(message); + } +} diff --git a/src/main/java/baseball/io/ResultView.java b/src/main/java/baseball/io/ResultView.java new file mode 100644 index 0000000..7a9d6a8 --- /dev/null +++ b/src/main/java/baseball/io/ResultView.java @@ -0,0 +1,13 @@ +package baseball.io; + +import baseball.model.Result; + +public class ResultView { + public static void printResult(Result strikeAndBall) { + if (strikeAndBall.getStrike() == 0 && strikeAndBall.getBall() == 0) { + System.out.println("낫싱"); + } else { + System.out.println(strikeAndBall.getBall() + "볼 " + strikeAndBall.getStrike() + "스트라이크"); + } + } +} diff --git a/src/main/java/baseball/matcher/NumberMatcher.java b/src/main/java/baseball/matcher/NumberMatcher.java new file mode 100644 index 0000000..55bbe5d --- /dev/null +++ b/src/main/java/baseball/matcher/NumberMatcher.java @@ -0,0 +1,15 @@ +package baseball.matcher; + +import java.util.List; + +// 숫자가 일치 하는지 비교 하고 싶은데.... +public class NumberMatcher { + + public boolean isMatching(int guessedNumber, int answerNumber) { + return guessedNumber == answerNumber; + } + // 숫자가 정답 리스트에 포함되어 있는지 확인하는 메서드 + public boolean isNumberMatching(List answer, int guessedNumber) { + return answer.contains(guessedNumber); + } +} diff --git a/src/main/java/baseball/matcher/PositionMatcher.java b/src/main/java/baseball/matcher/PositionMatcher.java new file mode 100644 index 0000000..3c175e8 --- /dev/null +++ b/src/main/java/baseball/matcher/PositionMatcher.java @@ -0,0 +1,11 @@ +package baseball.matcher; + +import java.util.List; + +//숫자가 위치가 일치 하는지 비교 +public class PositionMatcher { + + public boolean isPositionMatching(List answer, int guessedNumber, int index) { + return answer.get(index) == guessedNumber; + } +} diff --git a/src/main/java/baseball/model/Result.java b/src/main/java/baseball/model/Result.java new file mode 100644 index 0000000..e414c60 --- /dev/null +++ b/src/main/java/baseball/model/Result.java @@ -0,0 +1,36 @@ +package baseball.model; + +import baseball.config.Constants; +import baseball.validation.Validator; + +public class Result { + private final int strike; + private final int ball; + + // 생성자 + public Result(int strike, int ball) { + Validator.validateStrikeAndBall(strike, ball); // 유효성 검증 + this.strike = strike; + this.ball = ball; + } + + // 스트라이크 개수 반환 + public int getStrike() { + return strike; + } + + // 볼 개수 반환 + public int getBall() { + return ball; + } + + // 정답 여부 확인 + public boolean isCorrect() { + return strike == Constants.WINNING_STRIKES; // 상수로 대체 + } + + @Override + public String toString() { + return String.format("결과: %d 스트라이크, %d 볼!", strike, ball); + } +} diff --git a/src/main/java/baseball/validation/Validator.java b/src/main/java/baseball/validation/Validator.java new file mode 100644 index 0000000..2c018c1 --- /dev/null +++ b/src/main/java/baseball/validation/Validator.java @@ -0,0 +1,38 @@ +package baseball.validation; + +import baseball.config.Constants; + +import java.util.List; + +public class Validator { + + public void validate(List guess) { + validateSize(guess); + validateDuplicates(guess); + validateRange(guess); + } + + private void validateSize(List guess) { + if (guess.size() != Constants.NUMBER_COUNT) { + throw new IllegalArgumentException("숫자 " + Constants.NUMBER_COUNT + "개를 정확히 입력해야 합니다."); + } + } + + private void validateDuplicates(List guess) { + if (guess.stream().distinct().count() != Constants.NUMBER_COUNT) { + throw new IllegalArgumentException("각 숫자는 중복되지 않아야 합니다."); + } + } + + private void validateRange(List guess) { + if (!guess.stream().allMatch(n -> n >= Constants.MIN_NUMBER && n <= Constants.MAX_NUMBER)) { + throw new IllegalArgumentException("모든 숫자는 " + Constants.MIN_NUMBER + "에서 " + Constants.MAX_NUMBER + " 사이여야 합니다."); + } + } + + public static void validateStrikeAndBall(int strike, int ball) { + if (strike < 0 || ball < 0) { + throw new IllegalArgumentException("스트라이크랑 볼 개수는 음수일 수 없음!"); + } + } +} diff --git a/src/test/java/baseball/AppTest.java b/src/test/java/baseball/AppTest.java new file mode 100644 index 0000000..1d95e8a --- /dev/null +++ b/src/test/java/baseball/AppTest.java @@ -0,0 +1,4 @@ +package baseball; + +public class AppTest { +} diff --git a/src/test/java/baseball/checker/BallCheckerTest.java b/src/test/java/baseball/checker/BallCheckerTest.java new file mode 100644 index 0000000..11ac304 --- /dev/null +++ b/src/test/java/baseball/checker/BallCheckerTest.java @@ -0,0 +1,56 @@ +package baseball.checker; + +import baseball.config.Constants; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BallCheckerTest { + + private BallChecker ballChecker; + private List answer; + + @BeforeEach + @DisplayName("BallChecker랑 정답 리스트 초기화함") + public void setUp() { + ballChecker = new BallChecker(); + answer = Arrays.asList(1,2,3); + } + + @Test + @DisplayName("볼 없음: 예상한 숫자가 정답에 없을 때") + public void testNoBalls() { + List guess = Arrays.asList(4, 5, 6); + int balls = ballChecker.countBalls(guess, answer); + assertEquals(Constants.ZERO, balls, "볼 없어야 됨."); + } + + @Test + @DisplayName("1개의 볼 있음: 1이 정답에 있지만 위치가 다를 때") + public void testOneBall() { + List guess = Arrays.asList(4, 1, 6); + int balls = ballChecker.countBalls(guess, answer); + assertEquals(1, balls, "1개의 볼이어야 됨."); + } + + @Test + @DisplayName("2개의 볼 있음: 1이랑 3이 정답에 있지만 위치가 다를 때") + public void testTwoBalls() { + List guess = Arrays.asList(3, 2, 1); + int balls = ballChecker.countBalls(guess, answer); + assertEquals(2, balls, "2개의 볼이어야 됨."); + } + + @Test + @DisplayName("3개의 볼 있음: 숫자 다 맞지만 위치 다를 때") + public void testAllBalls() { + List guess = Arrays.asList(3, 1, 2); + int balls = ballChecker.countBalls(guess, answer); + assertEquals(3, balls, "3개의 볼이어야 됨."); + } +} diff --git a/src/test/java/baseball/checker/StrikeCheckerTest.java b/src/test/java/baseball/checker/StrikeCheckerTest.java new file mode 100644 index 0000000..17e0c98 --- /dev/null +++ b/src/test/java/baseball/checker/StrikeCheckerTest.java @@ -0,0 +1,56 @@ +package baseball.checker; + +import baseball.config.Constants; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class StrikeCheckerTest { + + private StrikeChecker strikeChecker; + private List answer; + + @BeforeEach + @DisplayName("StrikeChecker랑 정답 리스트 초기화함") + public void setUp() { + strikeChecker = new StrikeChecker(); + answer = Arrays.asList(1, 2, 3); + } + + @Test + @DisplayName("스트라이크 없음: 예상한 숫자가 정답이랑 안 맞을 때") + public void testNoStrikes() { + List guess = Arrays.asList(4, 5, 6); + int strikes = strikeChecker.countStrikes(guess, answer); + assertEquals(Constants.ZERO, strikes, "스트라이크 없음."); + } + + @Test + @DisplayName("1개 스트라이크: 하나 맞고 위치도 맞을 때") + public void testOneStrike() { + List guess = Arrays.asList(1, 5, 6); + int strikes = strikeChecker.countStrikes(guess, answer); + assertEquals(1, strikes, "1개의 스트라이크임."); + } + + @Test + @DisplayName("2개 스트라이크: 두 개 맞고 위치도 맞을 때") + public void testTwoStrikes() { + List guess = Arrays.asList(1, 2, 6); + int strikes = strikeChecker.countStrikes(guess, answer); + assertEquals(2, strikes, "2개의 스트라이크임."); + } + + @Test + @DisplayName("3개 스트라이크: 전부 다 맞을 때") + public void testThreeStrikes() { + List guess = Arrays.asList(1, 2, 3); + int strikes = strikeChecker.countStrikes(guess, answer); + assertEquals(3, strikes, "3개의 스트라이크임."); + } +} diff --git a/src/test/java/baseball/game/GameTest.java b/src/test/java/baseball/game/GameTest.java new file mode 100644 index 0000000..70143de --- /dev/null +++ b/src/test/java/baseball/game/GameTest.java @@ -0,0 +1,36 @@ +package baseball.game; + +import baseball.model.Result; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.DisplayName; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +public class GameTest { + + @Test + @DisplayName("랜덤 숫자 잘 생성됐는지 확인해보자") + public void testGenerateRandomNumbers() { + Game game = new Game(); + List numbers = game.getAnswer(); + + assertEquals(3, numbers.size(), "숫자 딱 3개 나와야 함."); + assertTrue(numbers.stream().allMatch(n -> n >= 1 && n <= 9), + "1에서 9 사이 숫자만 있어야 함."); + assertEquals(3, numbers.stream().distinct().count(), + "중복된 숫자 있으면 안 됨."); + } + + @Test + @DisplayName("정답 맞췄을 때 3 스트라이크인지 체크하자") + public void testCheckGuessCorrect() { + Game game = new Game(List.of(4, 2, 5)); + Result result = game.checkGuess(List.of(4, 2, 5)); + + assertEquals(3, result.getStrike(), "3 스트라이크 나왔음."); + assertEquals(0, result.getBall(), "볼 하나도 없음."); + assertTrue(result.isCorrect(), "정답 맞췄으니까 게임 끝났음."); + } +} diff --git a/src/test/java/baseball/game/GuessCheckerTest.java b/src/test/java/baseball/game/GuessCheckerTest.java new file mode 100644 index 0000000..bc78072 --- /dev/null +++ b/src/test/java/baseball/game/GuessCheckerTest.java @@ -0,0 +1,50 @@ +package baseball.game; + +import baseball.model.Result; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class GuessCheckerTest { + + private GuessChecker guessChecker; + private List answer; + + @BeforeEach + public void setUp() { + answer = Arrays.asList(1, 2, 3); + guessChecker = new GuessChecker(answer); + } + + @Test + @DisplayName("0 스트라이크, 0 볼 나오는지 확인해보셈") + public void testNoStrikeNoBall() { + List guess = Arrays.asList(4, 5, 6); + Result result = guessChecker.check(guess); + assertEquals(0, result.getStrike(), "스트라이크는 0이어야 함"); + assertEquals(0, result.getBall(), "볼은 0이어야 함"); + } + + @Test + @DisplayName("1 스트라이크, 1 볼 나오는지 확인해보셈") + public void testOneStrikeOneBall() { + List guess = Arrays.asList(1, 3, 4); + Result result = guessChecker.check(guess); + assertEquals(1, result.getStrike(), "스트라이크는 1이어야 함"); + assertEquals(1, result.getBall(), "볼은 1이어야 함"); + } + + @Test + @DisplayName("3 스트라이크 나오는지 확인해보셈") + public void testThreeStrikes() { + List guess = Arrays.asList(1, 2, 3); + Result result = guessChecker.check(guess); + assertEquals(3, result.getStrike(), "스트라이크는 3이어야 함"); + assertEquals(0, result.getBall(), "볼은 0이어야 함"); + } +} diff --git a/src/test/java/baseball/game/RandomNumberGeneratorTest.java b/src/test/java/baseball/game/RandomNumberGeneratorTest.java new file mode 100644 index 0000000..2fe0972 --- /dev/null +++ b/src/test/java/baseball/game/RandomNumberGeneratorTest.java @@ -0,0 +1,47 @@ +package baseball.game; + +import baseball.config.Constants; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; + +public class RandomNumberGeneratorTest { + + private RandomNumberGenerator randomNumberGenerator; + + @BeforeEach + public void setUp() { + randomNumberGenerator = new RandomNumberGenerator(); + } + + @Test + @DisplayName("생성된 숫자 개수 맞는지 확인해보셈") + public void testGenerateNumberCount() { + List numbers = randomNumberGenerator.generate(); + assertEquals(Constants.NUMBER_COUNT, numbers.size(), "생성된 숫자의 개수가 올바르지 않음"); + } + + @Test + @DisplayName("숫자 중복 안되는지 확인해보셈") + public void testNoDuplicateNumbers() { + List numbers = randomNumberGenerator.generate(); + Set numberSet = new HashSet<>(numbers); + assertEquals(numbers.size(), numberSet.size(), "중복된 숫자가 있음"); + } + + @Test + @DisplayName("숫자 범위 맞는지 확인해보셈") + public void testNumberRange() { + List numbers = randomNumberGenerator.generate(); + for (int num : numbers) { + assertTrue(num >= Constants.MIN_NUMBER && num <= Constants.MAX_NUMBER, + "숫자가 범위를 벗어남: " + num); + } + } +} diff --git a/src/test/java/study/StringTest.java b/src/test/java/study/StringTest.java deleted file mode 100644 index 43e47d9..0000000 --- a/src/test/java/study/StringTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package study; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class StringTest { - @Test - void replace() { - String actual = "abc".replace("b", "d"); - assertThat(actual).isEqualTo("adc"); - } -}