From 53baf2eed4ed7f693dfdd77355c684eb650e07f4 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 17:32:28 +0900 Subject: [PATCH 01/71] =?UTF-8?q?refactor:=20=EC=82=AC=EB=8B=A4=EB=A6=AC?= =?UTF-8?q?=EB=86=92=EC=9D=B4=20=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EA=B0=80=20=EC=9E=90=EC=84=B8?= =?UTF-8?q?=ED=95=9C=20=EB=82=B4=EC=9A=A9=EC=9D=84=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/view/InputView.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladder/view/InputView.java b/src/main/java/ladder/view/InputView.java index c783f1c756..76f2f2c718 100644 --- a/src/main/java/ladder/view/InputView.java +++ b/src/main/java/ladder/view/InputView.java @@ -10,9 +10,11 @@ public class InputView { private static final String DELIMITER = ","; private static final int SPLIT_LIMIT = -1; private static final String READ_LADDER_HEIGHT_MESSAGE = "최대 사다리 높이는 몇 개인가요?"; - private static final String INVALID_NUMBER_MESSAGE = "정수만 입력 가능합니다."; - private static final int HEIGHT_LOWER_BOUND = 1; - private static final String INVALID_HEIGHT_MESSAGE = "높이는 최소 " + HEIGHT_LOWER_BOUND + "이상이어야 합니다."; + private static final int LADDER_HEIGHT_LOWER_BOUND = 1; + private static final int LADDER_HEIGHT_UPPER_BOUND = 100; + private static final String INVALID_NUMBER_MESSAGE = LADDER_HEIGHT_UPPER_BOUND + " 이하의 정수만 입력 가능합니다."; + private static final String INVALID_HEIGHT_MESSAGE = + "높이는 최소 " + LADDER_HEIGHT_LOWER_BOUND + "이상, " + LADDER_HEIGHT_UPPER_BOUND + "이하여야 합니다."; private final Scanner scanner; @@ -48,8 +50,12 @@ private int parseInt(final String input) { } private void validateHeight(final int height) { - if (height < HEIGHT_LOWER_BOUND) { + if (isInvalidHeight(height)) { throw new IllegalArgumentException(INVALID_HEIGHT_MESSAGE); } } + + private boolean isInvalidHeight(final int height) { + return height < LADDER_HEIGHT_LOWER_BOUND || LADDER_HEIGHT_UPPER_BOUND < height; + } } From 63388cd78adca1572fa39f94480dc5623eaf5612 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 17:37:42 +0900 Subject: [PATCH 02/71] =?UTF-8?q?refactor:=20=EB=B0=98=ED=99=98=ED=95=A0?= =?UTF-8?q?=20=EB=95=8C=EB=A7=8C=20=EB=B6=88=EB=B3=80=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A1=9C=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Ladder.java | 4 ++-- src/main/java/ladder/domain/Players.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index 8c58d4c12f..de890b6666 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -1,6 +1,6 @@ package ladder.domain; -import static java.util.stream.Collectors.toUnmodifiableList; +import static java.util.stream.Collectors.toList; import java.util.Collections; import java.util.List; @@ -17,7 +17,7 @@ public Ladder(final BooleanGenerator booleanGenerator, final int height, final i private List generateLines(final BooleanGenerator booleanGenerator, final int height, final int width) { return Stream.generate(() -> new Line(booleanGenerator, width)) .limit(height) - .collect(toUnmodifiableList()); + .collect(toList()); } public List getLines() { diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index 729f557590..1f28c674d7 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -1,9 +1,11 @@ package ladder.domain; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toUnmodifiableList; + import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; @@ -38,13 +40,13 @@ private void validateDuplicateNames(final List names) { private List generatePlayers(final List names) { return names.stream() .map(Player::new) - .collect(Collectors.toUnmodifiableList()); + .collect(toList()); } public List getNames() { return players.stream() .map(Player::getName) - .collect(Collectors.toUnmodifiableList()); + .collect(toUnmodifiableList()); } public int count() { From 6f718813e0bd84055843f1dc9ed1a0e0ab8bd8cc Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 20:30:40 +0900 Subject: [PATCH 03/71] =?UTF-8?q?feat:=20=EA=B0=80=EB=A1=9C=20=EB=9D=BC?= =?UTF-8?q?=EC=9D=B8(Line)=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94?= =?UTF-8?q?=20=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=84=B0=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Line.java | 20 ++++++++++++++------ src/test/java/ladder/domain/LineTest.java | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index b69e5edabf..588c3c87d5 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -14,23 +14,31 @@ public Line(final BooleanGenerator booleanGenerator, final int width) { this.statuses = generateLine(booleanGenerator, width); } - private List generateLine(final BooleanGenerator booleanGenerator, final int width) { + private Line(final List statuses) { + this.statuses = statuses; + } + + public static Line generate(final BooleanGenerator generator, final int width) { + return new Line(generateLine(generator, width)); + } + + private static List generateLine(final BooleanGenerator generator, final int width) { final Deque statuses = new ArrayDeque<>(); - for (int i = 0; i < width; i++) { - statuses.add(generateLineStatus(booleanGenerator, statuses)); + while (statuses.size() < width) { + statuses.add(generateLineStatus(generator, statuses)); } return new ArrayList<>(statuses); } - private LineStatus generateLineStatus(final BooleanGenerator booleanGenerator, final Deque statuses) { - final boolean status = booleanGenerator.generate(); + private static LineStatus generateLineStatus(final BooleanGenerator generator, final Deque statuses) { + final boolean status = generator.generate(); if (isConnectable(statuses)) { return LineStatus.from(status); } return LineStatus.DISCONNECTED; } - private boolean isConnectable(final Deque statuses) { + private static boolean isConnectable(final Deque statuses) { return statuses.isEmpty() || statuses.getLast().isDisconnected(); } diff --git a/src/test/java/ladder/domain/LineTest.java b/src/test/java/ladder/domain/LineTest.java index e375d85d4f..e7587ad2d8 100644 --- a/src/test/java/ladder/domain/LineTest.java +++ b/src/test/java/ladder/domain/LineTest.java @@ -22,6 +22,14 @@ public class LineTest { assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, DISCONNECTED); } + @Test + void 라인은_너비를_받아_너비_만큼의_연결_상태값을_생성한다() { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, false, true, false, false)); + final Line line = Line.generate(booleanGenerator, 5); + + assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, DISCONNECTED); + } + @Test void 가로_라인의_상태가_연속으로_연결됨_상태일_수_없다() { final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true, true, true, true)); @@ -29,4 +37,12 @@ public class LineTest { assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, CONNECTED); } + + @Test + void 가로_라인의_연결_상태값이_연속으로_연결됨일_수_없다() { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true, true, true, true)); + final Line line = Line.generate(booleanGenerator, 5); + + assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, CONNECTED); + } } From e4d47ad3b0dfd7ca827884c3a8b0fd76b25b777c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 20:39:45 +0900 Subject: [PATCH 04/71] =?UTF-8?q?refactor:=20=EA=B0=80=EB=A1=9C=20?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8(Line)=20=EC=A0=95=EC=A0=81=20=ED=8C=A9?= =?UTF-8?q?=ED=84=B0=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Ladder.java | 2 +- src/main/java/ladder/domain/Line.java | 4 ---- src/test/java/ladder/domain/LineTest.java | 18 +----------------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index de890b6666..12d483c058 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -15,7 +15,7 @@ public Ladder(final BooleanGenerator booleanGenerator, final int height, final i } private List generateLines(final BooleanGenerator booleanGenerator, final int height, final int width) { - return Stream.generate(() -> new Line(booleanGenerator, width)) + return Stream.generate(() -> Line.generate(booleanGenerator, width)) .limit(height) .collect(toList()); } diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index 588c3c87d5..45f2dc506e 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -10,10 +10,6 @@ public class Line { private final List statuses; - public Line(final BooleanGenerator booleanGenerator, final int width) { - this.statuses = generateLine(booleanGenerator, width); - } - private Line(final List statuses) { this.statuses = statuses; } diff --git a/src/test/java/ladder/domain/LineTest.java b/src/test/java/ladder/domain/LineTest.java index e7587ad2d8..1272dac138 100644 --- a/src/test/java/ladder/domain/LineTest.java +++ b/src/test/java/ladder/domain/LineTest.java @@ -14,14 +14,6 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class LineTest { - @Test - void 라인은_너비를_받아_라인상태값을_생성한다() { - final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, false, true, false, false)); - final Line line = new Line(booleanGenerator, 5); - - assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, DISCONNECTED); - } - @Test void 라인은_너비를_받아_너비_만큼의_연결_상태값을_생성한다() { final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, false, true, false, false)); @@ -29,15 +21,7 @@ public class LineTest { assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, DISCONNECTED); } - - @Test - void 가로_라인의_상태가_연속으로_연결됨_상태일_수_없다() { - final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true, true, true, true)); - final Line line = new Line(booleanGenerator, 5); - - assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, CONNECTED); - } - + @Test void 가로_라인의_연결_상태값이_연속으로_연결됨일_수_없다() { final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true, true, true, true)); From 8dd1b1fb46c07963ebb1d6f0c45157809ac01c84 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 20:49:50 +0900 Subject: [PATCH 05/71] =?UTF-8?q?feat:=20=EC=82=AC=EB=8B=A4=EB=A6=AC(Ladde?= =?UTF-8?q?r)=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=ED=8C=A9=ED=84=B0=EB=A6=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Ladder.java | 12 ++++++++++-- src/test/java/ladder/domain/LadderTest.java | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index 12d483c058..071f4c81a7 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -14,8 +14,16 @@ public Ladder(final BooleanGenerator booleanGenerator, final int height, final i this.lines = generateLines(booleanGenerator, height, width); } - private List generateLines(final BooleanGenerator booleanGenerator, final int height, final int width) { - return Stream.generate(() -> Line.generate(booleanGenerator, width)) + private Ladder(final List lines) { + this.lines = lines; + } + + public static Ladder generate(final BooleanGenerator booleanGenerator, final int height, final int width) { + return new Ladder(generateLines(booleanGenerator, height, width)); + } + + private static List generateLines(final BooleanGenerator generator, final int height, final int width) { + return Stream.generate(() -> Line.generate(generator, width)) .limit(height) .collect(toList()); } diff --git a/src/test/java/ladder/domain/LadderTest.java b/src/test/java/ladder/domain/LadderTest.java index 3d632a579d..0270dc338f 100644 --- a/src/test/java/ladder/domain/LadderTest.java +++ b/src/test/java/ladder/domain/LadderTest.java @@ -26,4 +26,17 @@ public class LadderTest { List.of(CONNECTED, DISCONNECTED) ); } + + @Test + void 높이와_너비를_받아_사다리를_생성한다() { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(false, false, true, false)); + final Ladder ladder = Ladder.generate(booleanGenerator, 2, 2); + + assertThat(ladder.getLines()) + .extracting(Line::getLine) + .containsExactly( + List.of(DISCONNECTED, DISCONNECTED), + List.of(CONNECTED, DISCONNECTED) + ); + } } From 84d108cdea0d59b4a2201f321cea795dbd44d615 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 21:05:32 +0900 Subject: [PATCH 06/71] =?UTF-8?q?feat:=20=EC=82=AC=EB=8B=A4=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=ED=8C=A9=ED=84=B0=EB=A6=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Ladder.java | 8 ++------ src/main/java/ladder/domain/LadderGame.java | 4 ++-- src/test/java/ladder/domain/LadderTest.java | 13 ------------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index 071f4c81a7..2a1a29a61f 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -6,14 +6,10 @@ import java.util.List; import java.util.stream.Stream; -class Ladder { +public class Ladder { private final List lines; - - public Ladder(final BooleanGenerator booleanGenerator, final int height, final int width) { - this.lines = generateLines(booleanGenerator, height, width); - } - + private Ladder(final List lines) { this.lines = lines; } diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index 84f376b088..9d8a392fe9 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -9,9 +9,9 @@ public class LadderGame { private final Players players; private final Ladder ladder; - public LadderGame(final BooleanGenerator booleanGenerator, final Players players, final int height) { + public LadderGame(final BooleanGenerator generator, final Players players, final int height) { this.players = players; - this.ladder = new Ladder(booleanGenerator, height, players.count() - SUBTRACT_VALUE_OF_LADDER_WIDTH); + this.ladder = Ladder.generate(generator, height, players.count() - SUBTRACT_VALUE_OF_LADDER_WIDTH); } public List getPlayers() { diff --git a/src/test/java/ladder/domain/LadderTest.java b/src/test/java/ladder/domain/LadderTest.java index 0270dc338f..ad97bae0a5 100644 --- a/src/test/java/ladder/domain/LadderTest.java +++ b/src/test/java/ladder/domain/LadderTest.java @@ -14,19 +14,6 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class LadderTest { - @Test - void 사다리는_라인을_가진다() { - final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(false, false, true, false)); - final Ladder ladder = new Ladder(booleanGenerator, 2, 2); - - assertThat(ladder.getLines()) - .extracting(Line::getLine) - .containsExactly( - List.of(DISCONNECTED, DISCONNECTED), - List.of(CONNECTED, DISCONNECTED) - ); - } - @Test void 높이와_너비를_받아_사다리를_생성한다() { final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(false, false, true, false)); From 190e6933247824c7846283aee03962abe6ed8394 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 21:54:45 +0900 Subject: [PATCH 07/71] =?UTF-8?q?refactor:=20Players=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=84=B0?= =?UTF-8?q?=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ladder/controller/LadderGameController.java | 5 ++--- src/main/java/ladder/domain/Players.java | 16 ++++++++++------ src/test/java/ladder/domain/LadderGameTest.java | 2 +- src/test/java/ladder/domain/PlayersTest.java | 10 +++++----- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 6d9b415d60..eb36bd27f0 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -35,14 +35,13 @@ public void run() { private LadderGame initialize() { final Players players = readPlayers(); final int height = readHeight(); - + return new LadderGame(booleanGenerator, players, height); } private Players readPlayers() { try { - final List names = inputView.readPlayerNames(); - return new Players(names); + return Players.from(inputView.readPlayerNames()); } catch (IllegalArgumentException e) { outputView.printError(e.getMessage()); return readPlayers(); diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index 1f28c674d7..4fed0f4272 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -14,30 +14,34 @@ public class Players { private final List players; - public Players(final List names) { + private Players(final List players) { + this.players = players; + } + + public static Players from(final List names) { validate(names); - this.players = generatePlayers(names); + return new Players(toPlayers(names)); } - private void validate(final List names) { + private static void validate(final List names) { validatePlayersSize(names); validateDuplicateNames(names); } - private void validatePlayersSize(final List names) { + private static void validatePlayersSize(final List names) { if (names.size() < PLAYERS_SIZE_LOWER_BOUND) { throw new IllegalArgumentException(INVALID_PLAYERS_SIZE_MESSAGE); } } - private void validateDuplicateNames(final List names) { + private static void validateDuplicateNames(final List names) { final Set nonDuplicateNames = new HashSet<>(names); if (nonDuplicateNames.size() != names.size()) { throw new IllegalArgumentException(DUPLICATE_NAMES_MESSAGE); } } - private List generatePlayers(final List names) { + private static List toPlayers(final List names) { return names.stream() .map(Player::new) .collect(toList()); diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index 4df2f80459..151f8380a4 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -18,7 +18,7 @@ public class LadderGameTest { @BeforeEach void init() { final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true)); - final Players players = new Players(List.of("name1", "name2")); + final Players players = Players.from(List.of("name1", "name2")); final int height = 2; ladderGame = new LadderGame(booleanGenerator, players, height); } diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index 3e3ae43f32..237020b952 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -15,33 +15,33 @@ public class PlayersTest { @Test void 참가자가_한_명_이하인_경우_예외를_던진다() { - assertThatThrownBy(() -> new Players(List.of("name"))) + assertThatThrownBy(() -> Players.from(List.of("name"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("참가자는 최소 2명이어야 합니다."); } @Test void 참가자가_두_명_이상인_경우_예외를_던지지_않는다() { - assertThatNoException().isThrownBy(() -> new Players(List.of("name1", "name2"))); + assertThatNoException().isThrownBy(() -> Players.from(List.of("name1", "name2"))); } @Test void 참가자의_이름은_중복되는_경우_예외를_던진다() { - assertThatThrownBy(() -> new Players(List.of("name", "name"))) + assertThatThrownBy(() -> Players.from(List.of("name", "name"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("참가자의 이름은 중복되지 않아야 합니다."); } @Test void 모든_참가자의_이름을_반환한다() { - final Players players = new Players(List.of("name1", "name2")); + final Players players = Players.from(List.of("name1", "name2")); assertThat(players.getNames()).containsExactly("name1", "name2"); } @Test void 참가_인원을_반환한다() { - final Players players = new Players(List.of("name1", "name2")); + final Players players = Players.from(List.of("name1", "name2")); assertThat(players.count()).isEqualTo(2); } From 16c94d5482bc56d9d4c2207ed2e6d39b6d9d51c8 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 18 Feb 2023 22:14:23 +0900 Subject: [PATCH 08/71] =?UTF-8?q?style:=20booleanGenerator=20=EB=A7=A4?= =?UTF-8?q?=EA=B0=9C=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Ladder.java | 10 +++++++--- src/main/java/ladder/domain/LadderGame.java | 4 ++-- src/main/java/ladder/domain/Line.java | 15 +++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index 2a1a29a61f..b0ccd4b3fb 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -9,7 +9,7 @@ public class Ladder { private final List lines; - + private Ladder(final List lines) { this.lines = lines; } @@ -18,8 +18,12 @@ public static Ladder generate(final BooleanGenerator booleanGenerator, final int return new Ladder(generateLines(booleanGenerator, height, width)); } - private static List generateLines(final BooleanGenerator generator, final int height, final int width) { - return Stream.generate(() -> Line.generate(generator, width)) + private static List generateLines( + final BooleanGenerator booleanGenerator, + final int height, + final int width + ) { + return Stream.generate(() -> Line.generate(booleanGenerator, width)) .limit(height) .collect(toList()); } diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index 9d8a392fe9..7f447e31cd 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -9,9 +9,9 @@ public class LadderGame { private final Players players; private final Ladder ladder; - public LadderGame(final BooleanGenerator generator, final Players players, final int height) { + public LadderGame(final BooleanGenerator booleanGenerator, final Players players, final int height) { this.players = players; - this.ladder = Ladder.generate(generator, height, players.count() - SUBTRACT_VALUE_OF_LADDER_WIDTH); + this.ladder = Ladder.generate(booleanGenerator, height, players.count() - SUBTRACT_VALUE_OF_LADDER_WIDTH); } public List getPlayers() { diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index 45f2dc506e..6b18170c66 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -14,20 +14,23 @@ private Line(final List statuses) { this.statuses = statuses; } - public static Line generate(final BooleanGenerator generator, final int width) { - return new Line(generateLine(generator, width)); + public static Line generate(final BooleanGenerator booleanGenerator, final int width) { + return new Line(generateLine(booleanGenerator, width)); } - private static List generateLine(final BooleanGenerator generator, final int width) { + private static List generateLine(final BooleanGenerator booleanGenerator, final int width) { final Deque statuses = new ArrayDeque<>(); while (statuses.size() < width) { - statuses.add(generateLineStatus(generator, statuses)); + statuses.add(generateLineStatus(booleanGenerator, statuses)); } return new ArrayList<>(statuses); } - private static LineStatus generateLineStatus(final BooleanGenerator generator, final Deque statuses) { - final boolean status = generator.generate(); + private static LineStatus generateLineStatus( + final BooleanGenerator booleanGenerator, + final Deque statuses + ) { + final boolean status = booleanGenerator.generate(); if (isConnectable(statuses)) { return LineStatus.from(status); } From c137477d8611408e562e2493f7bee7d163dd4d70 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 19 Feb 2023 17:19:27 +0900 Subject: [PATCH 09/71] =?UTF-8?q?refactor:=20OutputView=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/view/OutputView.java | 40 ++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/main/java/ladder/view/OutputView.java b/src/main/java/ladder/view/OutputView.java index 2186ce257f..abe291cf89 100644 --- a/src/main/java/ladder/view/OutputView.java +++ b/src/main/java/ladder/view/OutputView.java @@ -10,47 +10,49 @@ public class OutputView { private static final int INITIAL_PLAYER_INDEX = 0; private static final int EMPTY_NAME_LENGTH = 0; private static final long SKIP_INITIAL_PLAYER = 1L; - private static final String GAME_RESULT_MESSAGE = "\n실행결과"; + private static final String NEXT_LINE = System.lineSeparator(); + private static final String GAME_RESULT_MESSAGE = NEXT_LINE + "실행결과" + NEXT_LINE; private static final String CONNECTED_SYMBOL = "-"; + private static final String DISCONNECTED_SYMBOL = " "; private static final String EMPTY_SYMBOL = " "; - private static final String NAME_MESSAGE_FORMAT = " %"; - private static final String STRING_FORMAT = "s"; + private static final String INITIAL_NAME_MESSAGE_FORMAT = "%s "; + private static final String NAME_MESSAGE_FORMAT = " %%%ds"; private static final String LINE_STATUS_MESSAGE_FORMAT = "%s|"; - private static final String NEXT_LINE = "\n"; private static final String ERROR_MESSAGE = "[ERROR] "; - public void printResult(final List players, final List ladder) { + public void printResult(final List playerNames, final List ladder) { System.out.println(GAME_RESULT_MESSAGE); - final int maxNameLength = calculateMaxNameLength(players); - System.out.println(generateNameMessages(players, maxNameLength)); + final int maxNameLength = calculateMaxNameLength(playerNames); + System.out.println(generateNameMessages(playerNames, maxNameLength)); - final String initialPlayerName = findInitialPlayerName(players); + final String initialPlayerName = getInitialPlayerName(playerNames); System.out.println(generateLadderMessage(initialPlayerName.length(), maxNameLength, ladder)); } - private int calculateMaxNameLength(final List players) { - return players.stream() + private int calculateMaxNameLength(final List playerNames) { + return playerNames.stream() .map(String::length) .max(Integer::compareTo) .orElse(EMPTY_NAME_LENGTH); } - private String generateNameMessages(final List players, final int maxNameLength) { - final String initialPlayerName = findInitialPlayerName(players) + EMPTY_SYMBOL; - final String nameMessage = players.stream() + private String generateNameMessages(final List playerNames, final int maxNameLength) { + final String initialNameMessage = String.format(INITIAL_NAME_MESSAGE_FORMAT, getInitialPlayerName(playerNames)); + final String playerNameMessages = playerNames.stream() .skip(SKIP_INITIAL_PLAYER) .map(name -> generateNameMessage(name, maxNameLength)) .collect(joining()); - return NEXT_LINE + initialPlayerName + nameMessage; + return initialNameMessage + playerNameMessages; } - private String generateNameMessage(final String name, int maxNameLength) { - return String.format(NAME_MESSAGE_FORMAT + maxNameLength + STRING_FORMAT, name); + private String getInitialPlayerName(final List playerNames) { + return playerNames.get(INITIAL_PLAYER_INDEX); } - private String findInitialPlayerName(final List players) { - return players.get(INITIAL_PLAYER_INDEX); + private String generateNameMessage(final String name, int maxNameLength) { + final String nameSizeFormat = String.format(NAME_MESSAGE_FORMAT, maxNameLength); + return String.format(nameSizeFormat, name); } private String generateLadderMessage(final int initialNameLength, final int maxNameLength, final List lines) { @@ -75,7 +77,7 @@ private String generateLineStatusMessage(final int maxNameLength, final LineStat if (lineStatus.isConnected()) { return generateRepeatedLineStatusMessage(CONNECTED_SYMBOL, maxNameLength); } - return generateRepeatedLineStatusMessage(EMPTY_SYMBOL, maxNameLength); + return generateRepeatedLineStatusMessage(DISCONNECTED_SYMBOL, maxNameLength); } public void printError(final String message) { From 0e9f3590479aba25f4dd3215b2eb154e47b6f1fa Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 20 Feb 2023 09:09:21 +0900 Subject: [PATCH 10/71] =?UTF-8?q?refactor:=20LadderGame=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=ED=8C=A9=ED=84=B0=EB=A6=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ladder/controller/LadderGameController.java | 2 +- src/main/java/ladder/domain/LadderGame.java | 15 ++++++++++++--- src/test/java/ladder/domain/LadderGameTest.java | 16 ++++++++-------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index eb36bd27f0..804071c9ea 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -36,7 +36,7 @@ private LadderGame initialize() { final Players players = readPlayers(); final int height = readHeight(); - return new LadderGame(booleanGenerator, players, height); + return LadderGame.initialize(players, booleanGenerator, height); } private Players readPlayers() { diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index 7f447e31cd..cf9b2106f7 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -4,14 +4,23 @@ public class LadderGame { - private static final int SUBTRACT_VALUE_OF_LADDER_WIDTH = 1; + private static final int SUBTRACT_LADDER_WIDTH_VALUE = 1; private final Players players; private final Ladder ladder; - public LadderGame(final BooleanGenerator booleanGenerator, final Players players, final int height) { + private LadderGame(final Players players, final Ladder ladder) { this.players = players; - this.ladder = Ladder.generate(booleanGenerator, height, players.count() - SUBTRACT_VALUE_OF_LADDER_WIDTH); + this.ladder = ladder; + } + + public static LadderGame initialize( + final Players players, + final BooleanGenerator booleanGenerator, + final int height + ) { + final Ladder ladder = Ladder.generate(booleanGenerator, height, players.count() - SUBTRACT_LADDER_WIDTH_VALUE); + return new LadderGame(players, ladder); } public List getPlayers() { diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index 151f8380a4..d4aba53284 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -4,7 +4,6 @@ import java.util.List; import ladder.util.TestBooleanGenerator; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -13,23 +12,24 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class LadderGameTest { - private LadderGame ladderGame; + private LadderGame initializeLadderGame(final List names, final List ladder, final int height) { + final Players players = Players.from(names); + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(ladder); - @BeforeEach - void init() { - final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true)); - final Players players = Players.from(List.of("name1", "name2")); - final int height = 2; - ladderGame = new LadderGame(booleanGenerator, players, height); + return LadderGame.initialize(players, booleanGenerator, height); } @Test void 참가자들의_이름을_반환한다() { + final LadderGame ladderGame = initializeLadderGame(List.of("name1", "name2"), List.of(true, true), 2); + assertThat(ladderGame.getPlayers()).containsExactly("name1", "name2"); } @Test void 생성된_사다리를_반환한다() { + final LadderGame ladderGame = initializeLadderGame(List.of("name1", "name2"), List.of(true, true), 2); + assertThat(ladderGame.getLadder()) .extracting(Line::getLine) .containsExactly( From cdd3c8f13d47f35c1bafd41c4865c16da1f975aa Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 20 Feb 2023 09:10:15 +0900 Subject: [PATCH 11/71] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/Application.java | 18 +++--------------- src/main/java/ladder/domain/Ladder.java | 11 ++--------- src/main/java/ladder/domain/Line.java | 6 +----- src/main/java/ladder/domain/Players.java | 11 ++++------- 4 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/main/java/ladder/Application.java b/src/main/java/ladder/Application.java index 78d0380cca..0aaabd0954 100644 --- a/src/main/java/ladder/Application.java +++ b/src/main/java/ladder/Application.java @@ -11,23 +11,11 @@ public class Application { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { final LadderGameController ladderGameController = new LadderGameController( - booleanGenerator(), - inputView(scanner), - outputView() + new RandomBooleanGenerator(), + new InputView(scanner), + new OutputView() ); ladderGameController.run(); } } - - private static RandomBooleanGenerator booleanGenerator() { - return new RandomBooleanGenerator(); - } - - private static OutputView outputView() { - return new OutputView(); - } - - private static InputView inputView(final Scanner scanner) { - return new InputView(scanner); - } } diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index b0ccd4b3fb..f6dad229bc 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -1,5 +1,6 @@ package ladder.domain; +import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; import java.util.Collections; @@ -15,17 +16,9 @@ private Ladder(final List lines) { } public static Ladder generate(final BooleanGenerator booleanGenerator, final int height, final int width) { - return new Ladder(generateLines(booleanGenerator, height, width)); - } - - private static List generateLines( - final BooleanGenerator booleanGenerator, - final int height, - final int width - ) { return Stream.generate(() -> Line.generate(booleanGenerator, width)) .limit(height) - .collect(toList()); + .collect(collectingAndThen(toList(), Ladder::new)); } public List getLines() { diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index 6b18170c66..6db10ed773 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -15,15 +15,11 @@ private Line(final List statuses) { } public static Line generate(final BooleanGenerator booleanGenerator, final int width) { - return new Line(generateLine(booleanGenerator, width)); - } - - private static List generateLine(final BooleanGenerator booleanGenerator, final int width) { final Deque statuses = new ArrayDeque<>(); while (statuses.size() < width) { statuses.add(generateLineStatus(booleanGenerator, statuses)); } - return new ArrayList<>(statuses); + return new Line(new ArrayList<>(statuses)); } private static LineStatus generateLineStatus( diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index 4fed0f4272..bc336e8fb9 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -1,5 +1,6 @@ package ladder.domain; +import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toUnmodifiableList; @@ -20,7 +21,9 @@ private Players(final List players) { public static Players from(final List names) { validate(names); - return new Players(toPlayers(names)); + return names.stream() + .map(Player::new) + .collect(collectingAndThen(toList(), Players::new)); } private static void validate(final List names) { @@ -41,12 +44,6 @@ private static void validateDuplicateNames(final List names) { } } - private static List toPlayers(final List names) { - return names.stream() - .map(Player::new) - .collect(toList()); - } - public List getNames() { return players.stream() .map(Player::getName) From f90c14c709375a9beffa4b5584c855c9b1f61edd Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 20 Feb 2023 14:37:20 +0900 Subject: [PATCH 12/71] =?UTF-8?q?docs:=202=EB=8B=A8=EA=B3=84=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b93573b55e..04fcdbf86d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,11 @@ graph TD LadderGameController --> LadderGame LadderGame --> Ladder LadderGame --> Players + LadderGame --> Items + LadderGame --> LadderGameResult + + Items --> Item Players --> Player LadderGameController --> InputView @@ -34,23 +38,36 @@ graph TD - [x] 참가자들의 이름은 중복될 수 없다. - [x] 중복된 이름이 존재하는 경우 예외를 던진다. -### 사다리 +### 실행 결과 + +- [ ] 실행 결과는 결과명을 가진다. + - [ ] 결과명은 1자 이상, 5자 이하의 길이를 가진다. + - [ ] 결과명이 없거나, 5자를 초과하는 경우 예외를 던진다. +- [ ] 참가인원과 동일한 결과 개수가 있어야 한다. + +### 사다리 게임 - [x] 사다리는 높이를 가진다. -- [x] 사다리 가로 라인을 가진다. - - [x] 사다리 가로 라인의 상태가 연속으로 `연결됨` 상태일 수 없다. -- [x] 각각의 가로 라인은 상태를 가진다. - - [x] 연결됨, 연결되지 않음으로 구분된다. + - [x] 높이는 1이상, 100이하의 값이어야 한다. +- [x] 사다리의 높이만큼 가로 라인을 가진다. + - [x] 각각의 가로 라인은 `사다리 게임 참가자 - 1` 너비만큼의 연결 상태를 가진다. + - [x] 연결 상태는 연결됨, 연결되지 않음으로 구분된다. + - [x] 가로 라인의 연결 상태가 연속으로 `연결됨` 일 수 없다. +- [ ] 사다리 게임 진행 후, 모든 참가자에 대한 결과를 반환한다. ### 입력 -- [x] 사람 이름은 쉼표(,)를 기준으로 구분하여 입력받는다. -- [x] 이름의 앞뒤 공백을 제거한다. +- [x] 참가자 이름은 쉼표(,)를 기준으로 구분하여 입력받는다. + - [x] 이름의 앞뒤 공백을 제거한다. +- [ ] 결과명은 쉼표(,)를 기준으로 구분하여 입력받는다. + - [ ] 결과명의 앞뒤 공백을 제거한다. - [x] 최대 사다리 높이를 입력받는다. - - [x] 1보다 작은 값을 입력하는 경우 예외를 던진다. + - [x] 1보다 작은 값을 입력 받거나, 100보다 큰 값을 입력받는 경우 예외를 던진다. +- [ ] 실행결과를 보고 싶은 참가자명을 입력받는다. ### 출력 -- [x] 최대 사람이름을 기준으로 사다리 폭이 넓어진다. +- [x] 가장 긴 사람 이름을 기준으로 사다리 폭이 넓어진다. 예) 가장 긴 사람이름 5, 사다리 폭 5 +- [ ] 실행 결과를 이용하여 해당 참가자에 대한 결과를 출력한다. From 5127aea96fd7238802643e781f934afe267d904f Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 20 Feb 2023 14:45:26 +0900 Subject: [PATCH 13/71] =?UTF-8?q?refactor:=20=EC=B0=B8=EA=B0=80=EC=9E=90?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=A6=84=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 4 ++-- src/test/java/ladder/domain/PlayerTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 6305e969a5..4d9d450c0e 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -2,8 +2,8 @@ public class Player { private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = "이름은 1자 이상, " + - NAME_LENGTH_UPPER_BOUND + "자 이하여야 한다."; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "참가자의 이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; private final String name; diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index f403de613c..70c05cfb49 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -14,7 +14,7 @@ public class PlayerTest { @Test - void 참여자는_이름을_가진다() { + void 참가자는_이름을_가진다() { final Player player = new Player("name"); assertThat(player.getName()).isEqualTo("name"); @@ -25,6 +25,6 @@ public class PlayerTest { void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { assertThatThrownBy(() -> new Player(name)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("이름은 1자 이상, 5자 이하여야 한다."); + .hasMessage("참가자의 이름은 1자 이상, 5자 이하여야 합니다."); } } From 3ef389d3c22bb8e86a391db3108215c82230a8e3 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Tue, 21 Feb 2023 08:32:06 +0900 Subject: [PATCH 14/71] =?UTF-8?q?feat:=20=EC=8B=A4=ED=96=89=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC(Item)=EB=A5=BC=20=ED=91=9C=ED=98=84=ED=95=98=EB=8A=94?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++---- src/main/java/ladder/domain/Item.java | 28 +++++++++++++++++++ src/test/java/ladder/domain/ItemTest.java | 33 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ladder/domain/Item.java create mode 100644 src/test/java/ladder/domain/ItemTest.java diff --git a/README.md b/README.md index 04fcdbf86d..5fa58bc4fa 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ graph TD ### 실행 결과 -- [ ] 실행 결과는 결과명을 가진다. - - [ ] 결과명은 1자 이상, 5자 이하의 길이를 가진다. - - [ ] 결과명이 없거나, 5자를 초과하는 경우 예외를 던진다. -- [ ] 참가인원과 동일한 결과 개수가 있어야 한다. +- [x] 실행 결과는 이름을 가진다. + - [x] 결과명은 1자 이상, 5자 이하의 길이를 가진다. + - [x] 결과명이 없거나, 5자를 초과하는 경우 예외를 던진다. +- [x] 참가인원과 동일한 개수가 있어야 한다. ### 사다리 게임 @@ -53,7 +53,7 @@ graph TD - [x] 각각의 가로 라인은 `사다리 게임 참가자 - 1` 너비만큼의 연결 상태를 가진다. - [x] 연결 상태는 연결됨, 연결되지 않음으로 구분된다. - [x] 가로 라인의 연결 상태가 연속으로 `연결됨` 일 수 없다. -- [ ] 사다리 게임 진행 후, 모든 참가자에 대한 결과를 반환한다. +- [ ] 사다리 게임 진행 후, 모든 참가자에 대한 결과(Item)를 반환한다. ### 입력 diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java new file mode 100644 index 0000000000..c4bbaac74a --- /dev/null +++ b/src/main/java/ladder/domain/Item.java @@ -0,0 +1,28 @@ +package ladder.domain; + +class Item { + private static final int NAME_LENGTH_UPPER_BOUND = 5; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + + private final String name; + + public Item(final String name) { + validate(name); + this.name = name; + } + + private void validate(final String name) { + if (isInvalidNameLength(name)) { + throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); + } + } + + private boolean isInvalidNameLength(final String name) { + return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + } + + public String getName() { + return name; + } +} diff --git a/src/test/java/ladder/domain/ItemTest.java b/src/test/java/ladder/domain/ItemTest.java new file mode 100644 index 0000000000..1399dbb461 --- /dev/null +++ b/src/test/java/ladder/domain/ItemTest.java @@ -0,0 +1,33 @@ +package ladder.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class ItemTest { + + @Test + void 실행결과는_이름을_가진다() { + final Item item = new Item("name"); + + assertThat(item.getName()).isEqualTo("name"); + } + + @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = {"우아한상품들"}) + void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + assertThatThrownBy(() -> new Item(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); + } + +} From 6d0605eb09303baa9919429e742cee137bb5434a Mon Sep 17 00:00:00 2001 From: greeng00se Date: Tue, 21 Feb 2023 08:33:38 +0900 Subject: [PATCH 15/71] =?UTF-8?q?feat:=20Player=EC=9D=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EA=B2=80=EC=A6=9D=EC=8B=9C=20null=20check=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 2 +- src/test/java/ladder/domain/PlayerTest.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 4d9d450c0e..927bc5bab6 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -19,7 +19,7 @@ private void validate(final String name) { } private boolean isInvalidNameLength(final String name) { - return name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); } public String getName() { diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 70c05cfb49..0e03ee4fcc 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @@ -21,7 +22,8 @@ public class PlayerTest { } @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") - @ValueSource(strings = {"", "우아한형제들"}) + @NullAndEmptySource + @ValueSource(strings = {"우아한형제들"}) void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { assertThatThrownBy(() -> new Player(name)) .isInstanceOf(IllegalArgumentException.class) From cf9d52bc7c4b8c87daa488f246a4c9815c280a1d Mon Sep 17 00:00:00 2001 From: greeng00se Date: Tue, 21 Feb 2023 13:33:26 +0900 Subject: [PATCH 16/71] =?UTF-8?q?feat:=20Item=EC=9D=98=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=89=20=EC=BB=AC=EB=A0=89=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Items.java | 29 ++++++++++++++++++++++ src/test/java/ladder/domain/ItemsTest.java | 21 ++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/ladder/domain/Items.java create mode 100644 src/test/java/ladder/domain/ItemsTest.java diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java new file mode 100644 index 0000000000..f13d32f6ea --- /dev/null +++ b/src/main/java/ladder/domain/Items.java @@ -0,0 +1,29 @@ +package ladder.domain; + +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; + +import java.util.List; + +class Items { + private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; + + private final List items; + + private Items(final List items) { + this.items = items; + } + + public static Items from(List items, int playerCount) { + validateItemCount(items, playerCount); + return items.stream() + .map(Item::new) + .collect(collectingAndThen(toList(), Items::new)); + } + + private static void validateItemCount(final List items, final int playerCount) { + if (items.size() != playerCount) { + throw new IllegalArgumentException(INVALID_ITEM_COUNT_MESSAGE); + } + } +} diff --git a/src/test/java/ladder/domain/ItemsTest.java b/src/test/java/ladder/domain/ItemsTest.java new file mode 100644 index 0000000000..08c5b00782 --- /dev/null +++ b/src/test/java/ladder/domain/ItemsTest.java @@ -0,0 +1,21 @@ +package ladder.domain; + +import static java.util.List.of; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class ItemsTest { + + @Test + void 실행결과는_참가인원과_동일한_개수가_아니라면_예외를_던진다() { + assertThatThrownBy(() -> Items.from(of("item1", "item2"), 3)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("참가인원과 동일한 개수의 실행결과를 입력해야 합니다."); + } + +} From 21fde321798b0d44b097dfe31a544841a2d37c51 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Tue, 21 Feb 2023 14:05:49 +0900 Subject: [PATCH 17/71] =?UTF-8?q?feat:=20=EC=8B=A4=ED=96=89=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ladder/controller/LadderGameController.java | 11 +++++++++++ src/main/java/ladder/domain/Item.java | 2 +- src/main/java/ladder/domain/Items.java | 2 +- src/main/java/ladder/view/InputView.java | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 804071c9ea..92b05f76d6 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -2,6 +2,7 @@ import java.util.List; import ladder.domain.BooleanGenerator; +import ladder.domain.Items; import ladder.domain.LadderGame; import ladder.domain.Line; import ladder.domain.Players; @@ -35,6 +36,7 @@ public void run() { private LadderGame initialize() { final Players players = readPlayers(); final int height = readHeight(); + final Items items = readItems(players.count()); return LadderGame.initialize(players, booleanGenerator, height); } @@ -56,4 +58,13 @@ private int readHeight() { return readHeight(); } } + + private Items readItems(int playerCount) { + try { + return Items.from(inputView.readItemNames(), playerCount); + } catch (IllegalArgumentException e) { + outputView.printError(e.getMessage()); + return readItems(playerCount); + } + } } diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java index c4bbaac74a..23f9d9b3d5 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -1,6 +1,6 @@ package ladder.domain; -class Item { +public class Item { private static final int NAME_LENGTH_UPPER_BOUND = 5; private static final String INVALID_NAME_LENGTH_MESSAGE = "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index f13d32f6ea..e0a9d0c7b6 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -5,7 +5,7 @@ import java.util.List; -class Items { +public class Items { private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; private final List items; diff --git a/src/main/java/ladder/view/InputView.java b/src/main/java/ladder/view/InputView.java index 76f2f2c718..dc9c52fb65 100644 --- a/src/main/java/ladder/view/InputView.java +++ b/src/main/java/ladder/view/InputView.java @@ -9,6 +9,7 @@ public class InputView { private static final String READ_PLAYER_NAMES_MESSAGE = "참여할 사람 이름을 입력하세요. (이름은 쉼표(,)로 구분하세요)"; private static final String DELIMITER = ","; private static final int SPLIT_LIMIT = -1; + private static final String READ_ITEM_NAMES_MESSAGE = "실행 결과를 입력하세요. (결과는 쉼표(,)로 구분하세요)"; private static final String READ_LADDER_HEIGHT_MESSAGE = "최대 사다리 높이는 몇 개인가요?"; private static final int LADDER_HEIGHT_LOWER_BOUND = 1; private static final int LADDER_HEIGHT_UPPER_BOUND = 100; @@ -26,11 +27,22 @@ public List readPlayerNames() { System.out.println(READ_PLAYER_NAMES_MESSAGE); final String input = scanner.nextLine(); + return splitCsvInput(input); + } + + public List splitCsvInput(String input) { return Arrays.stream(input.split(DELIMITER, SPLIT_LIMIT)) .map(String::trim) .collect(Collectors.toList()); } + public List readItemNames() { + System.out.println(READ_ITEM_NAMES_MESSAGE); + final String input = scanner.nextLine(); + + return splitCsvInput(input); + } + public int readLadderHeight() { System.out.println(READ_LADDER_HEIGHT_MESSAGE); final String input = scanner.nextLine(); From 48977baf15cb89deb353e0f9fbc4a7c2b59f01f9 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Tue, 21 Feb 2023 14:15:14 +0900 Subject: [PATCH 18/71] =?UTF-8?q?refactor:=20final=20=EB=B9=A0=EC=A7=84=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/controller/LadderGameController.java | 2 +- src/main/java/ladder/domain/Items.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 92b05f76d6..eeb730cbe8 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -59,7 +59,7 @@ private int readHeight() { } } - private Items readItems(int playerCount) { + private Items readItems(final int playerCount) { try { return Items.from(inputView.readItemNames(), playerCount); } catch (IllegalArgumentException e) { diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index e0a9d0c7b6..4753b56f43 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -14,7 +14,7 @@ private Items(final List items) { this.items = items; } - public static Items from(List items, int playerCount) { + public static Items from(final List items, int playerCount) { validateItemCount(items, playerCount); return items.stream() .map(Item::new) From 4ab0b42d9bf87cd3d18594310c179a013c0cc017 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Tue, 21 Feb 2023 14:45:12 +0900 Subject: [PATCH 19/71] =?UTF-8?q?feat:=20LadderGame=20Items=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LadderGameController.java | 2 +- src/main/java/ladder/domain/LadderGame.java | 10 ++++--- .../java/ladder/domain/LadderGameTest.java | 26 +++++++++++++++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index eeb730cbe8..1f9421b888 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -38,7 +38,7 @@ private LadderGame initialize() { final int height = readHeight(); final Items items = readItems(players.count()); - return LadderGame.initialize(players, booleanGenerator, height); + return LadderGame.initialize(players, booleanGenerator, height, items); } private Players readPlayers() { diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index cf9b2106f7..2aec201715 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -3,24 +3,26 @@ import java.util.List; public class LadderGame { - private static final int SUBTRACT_LADDER_WIDTH_VALUE = 1; private final Players players; private final Ladder ladder; + private final Items items; - private LadderGame(final Players players, final Ladder ladder) { + private LadderGame(final Players players, final Ladder ladder, final Items items) { this.players = players; this.ladder = ladder; + this.items = items; } public static LadderGame initialize( final Players players, final BooleanGenerator booleanGenerator, - final int height + final int height, + final Items items ) { final Ladder ladder = Ladder.generate(booleanGenerator, height, players.count() - SUBTRACT_LADDER_WIDTH_VALUE); - return new LadderGame(players, ladder); + return new LadderGame(players, ladder, items); } public List getPlayers() { diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index d4aba53284..a65c746397 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -12,23 +12,39 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class LadderGameTest { - private LadderGame initializeLadderGame(final List names, final List ladder, final int height) { - final Players players = Players.from(names); + private LadderGame initializeLadderGame( + final List playerNames, + final List ladder, + final int height, + final List itemNames + ) { + final Players players = Players.from(playerNames); final BooleanGenerator booleanGenerator = new TestBooleanGenerator(ladder); + final Items items = Items.from(itemNames, players.count()); - return LadderGame.initialize(players, booleanGenerator, height); + return LadderGame.initialize(players, booleanGenerator, height, items); } @Test void 참가자들의_이름을_반환한다() { - final LadderGame ladderGame = initializeLadderGame(List.of("name1", "name2"), List.of(true, true), 2); + final LadderGame ladderGame = initializeLadderGame( + List.of("name1", "name2"), + List.of(true, true), + 2, + List.of("item1", "item2") + ); assertThat(ladderGame.getPlayers()).containsExactly("name1", "name2"); } @Test void 생성된_사다리를_반환한다() { - final LadderGame ladderGame = initializeLadderGame(List.of("name1", "name2"), List.of(true, true), 2); + final LadderGame ladderGame = initializeLadderGame( + List.of("name1", "name2"), + List.of(true, true), + 2, + List.of("item1", "item2") + ); assertThat(ladderGame.getLadder()) .extracting(Line::getLine) From a3c61823290574b95056cc6bbc64847afcab1c69 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 08:21:30 +0900 Subject: [PATCH 20/71] =?UTF-8?q?feat:=20=EC=9C=84=EC=B9=98=EB=A5=BC=20?= =?UTF-8?q?=ED=91=9C=ED=98=84=ED=95=98=EB=8A=94=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 ++++++----- src/main/java/ladder/domain/Position.java | 44 +++++++++++++++++++ src/test/java/ladder/domain/PositionTest.java | 30 +++++++++++++ 3 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 src/main/java/ladder/domain/Position.java create mode 100644 src/test/java/ladder/domain/PositionTest.java diff --git a/README.md b/README.md index 5fa58bc4fa..70cc5b0e3c 100644 --- a/README.md +++ b/README.md @@ -32,18 +32,20 @@ graph TD - [x] 참가자는 이름을 가진다. - [x] 이름은 1자 이상, 5자 이하의 길이를 가진다. - - [x] 이름이 없거나, 5자를 초과하는 경우 예외를 던진다. + - [x] 이름이 없거나, 5자를 초과하는 경우 예외를 던진다. + - [x] 참가자들의 이름은 중복될 수 없다. + - [x] 중복된 이름이 존재하는 경우 예외를 던진다. - [x] 참가자는 최소 2명 이어야 한다. - [x] 참가자가 1명 이하인 경우 예외를 던진다. -- [x] 참가자들의 이름은 중복될 수 없다. - - [x] 중복된 이름이 존재하는 경우 예외를 던진다. +- [ ] 참가자는 최대 20명 이어야 한다. + - [ ] 참가자가 20명을 초과하는 경우 예외를 던진다. -### 실행 결과 +### 아이템(실행결과) -- [x] 실행 결과는 이름을 가진다. - - [x] 결과명은 1자 이상, 5자 이하의 길이를 가진다. - - [x] 결과명이 없거나, 5자를 초과하는 경우 예외를 던진다. -- [x] 참가인원과 동일한 개수가 있어야 한다. +- [x] 아이템은 이름을 가진다. + - [x] 이름은 1자 이상, 5자 이하의 길이를 가진다. + - [x] 이름이 없거나, 5자를 초과하는 경우 예외를 던진다. +- [x] 아이템은 참가인원과 동일한 개수가 있어야 한다. ### 사다리 게임 @@ -53,14 +55,15 @@ graph TD - [x] 각각의 가로 라인은 `사다리 게임 참가자 - 1` 너비만큼의 연결 상태를 가진다. - [x] 연결 상태는 연결됨, 연결되지 않음으로 구분된다. - [x] 가로 라인의 연결 상태가 연속으로 `연결됨` 일 수 없다. -- [ ] 사다리 게임 진행 후, 모든 참가자에 대한 결과(Item)를 반환한다. +- [ ] 사다리 게임을 진행한다. +- [ ] 모든 참가자에 대한 결과를 반환한다. ### 입력 - [x] 참가자 이름은 쉼표(,)를 기준으로 구분하여 입력받는다. - [x] 이름의 앞뒤 공백을 제거한다. -- [ ] 결과명은 쉼표(,)를 기준으로 구분하여 입력받는다. - - [ ] 결과명의 앞뒤 공백을 제거한다. +- [x] 결과명은 쉼표(,)를 기준으로 구분하여 입력받는다. + - [x] 결과명의 앞뒤 공백을 제거한다. - [x] 최대 사다리 높이를 입력받는다. - [x] 1보다 작은 값을 입력 받거나, 100보다 큰 값을 입력받는 경우 예외를 던진다. - [ ] 실행결과를 보고 싶은 참가자명을 입력받는다. diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java new file mode 100644 index 0000000000..8663a2e360 --- /dev/null +++ b/src/main/java/ladder/domain/Position.java @@ -0,0 +1,44 @@ +package ladder.domain; + +import java.util.HashMap; +import java.util.Map; + +public class Position { + + private static final int POSITION_VALUE_LOWER_BOUND = 1; + private static final int POSITION_VALUE_UPPER_BOUND = 20; + private static final String INVALID_VALUE_MESSAGE = + "위치값은 " + POSITION_VALUE_LOWER_BOUND + "이상, " + POSITION_VALUE_UPPER_BOUND + "이하여야 합니다."; + private static final Map CACHE = new HashMap<>(); + + static { + for (int i = POSITION_VALUE_LOWER_BOUND; i <= POSITION_VALUE_UPPER_BOUND; i++) { + CACHE.put(i, new Position(i)); + } + } + + private final int value; + + private Position(final int value) { + this.value = value; + } + + public static Position valueOf(final int value) { + validate(value); + return CACHE.get(value); + } + + private static void validate(final int value) { + if (isInvalidPosition(value)) { + throw new IllegalArgumentException(INVALID_VALUE_MESSAGE); + } + } + + private static boolean isInvalidPosition(final int value) { + return value < POSITION_VALUE_LOWER_BOUND || POSITION_VALUE_UPPER_BOUND < value; + } + + public int getValue() { + return value; + } +} diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java new file mode 100644 index 0000000000..3819b961b9 --- /dev/null +++ b/src/test/java/ladder/domain/PositionTest.java @@ -0,0 +1,30 @@ +package ladder.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class PositionTest { + + @ParameterizedTest(name = "위치값이 0보다 작거나 20보다 큰 경우 예외를 던진다 입력값: {0}") + @ValueSource(ints = {-1, 0, 21}) + void 위치값이_1보다_작거나_20보다_큰_경우_예외를_던진다(final int value) { + assertThatThrownBy(() -> Position.valueOf(value)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("위치값은 1이상, 20이하여야 합니다."); + } + + @ParameterizedTest(name = "올바른 위치값을 받으면 정상적으로 생성된다. 입력값: {0}") + @ValueSource(ints = {1, 20}) + void 올바른_위치값을_받으면_정상적으로_생성된다(final int value) { + final Position position = Position.valueOf(value); + + assertThat(position.getValue()).isEqualTo(value); + } +} From e293af6cadd1a8982739f3d699279581adbae5a9 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 08:53:41 +0900 Subject: [PATCH 21/71] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A6=84=EC=9D=84=20?= =?UTF-8?q?=ED=91=9C=ED=98=84=ED=95=98=EB=8A=94=20Name=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- src/main/java/ladder/domain/Item.java | 22 +++----------- src/main/java/ladder/domain/Name.java | 29 ++++++++++++++++++ src/main/java/ladder/domain/Player.java | 20 ++----------- src/test/java/ladder/domain/ItemTest.java | 14 --------- src/test/java/ladder/domain/NameTest.java | 33 +++++++++++++++++++++ src/test/java/ladder/domain/PlayerTest.java | 13 -------- 7 files changed, 70 insertions(+), 64 deletions(-) create mode 100644 src/main/java/ladder/domain/Name.java create mode 100644 src/test/java/ladder/domain/NameTest.java diff --git a/README.md b/README.md index 70cc5b0e3c..01eb559723 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,7 @@ graph TD ### 아이템(실행결과) - [x] 아이템은 이름을 가진다. - - [x] 이름은 1자 이상, 5자 이하의 길이를 가진다. - - [x] 이름이 없거나, 5자를 초과하는 경우 예외를 던진다. + - [ ] 이름 길이는 참가자의 이름과 동일하게 1자 이상, 5자 이하의 길이를 가진다. - [x] 아이템은 참가인원과 동일한 개수가 있어야 한다. ### 사다리 게임 diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java index 23f9d9b3d5..392251f6aa 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -1,28 +1,14 @@ package ladder.domain; public class Item { - private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = - "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - - private final String name; + + private final Name name; public Item(final String name) { - validate(name); - this.name = name; - } - - private void validate(final String name) { - if (isInvalidNameLength(name)) { - throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); - } - } - - private boolean isInvalidNameLength(final String name) { - return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + this.name = new Name(name); } public String getName() { - return name; + return name.getValue(); } } diff --git a/src/main/java/ladder/domain/Name.java b/src/main/java/ladder/domain/Name.java new file mode 100644 index 0000000000..73f3de88c2 --- /dev/null +++ b/src/main/java/ladder/domain/Name.java @@ -0,0 +1,29 @@ +package ladder.domain; + +class Name { + + private static final int NAME_LENGTH_UPPER_BOUND = 5; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + + private final String value; + + public Name(final String value) { + validate(value); + this.value = value; + } + + private void validate(final String value) { + if (isInvalidNameLength(value)) { + throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); + } + } + + private boolean isInvalidNameLength(final String value) { + return value == null || value.isBlank() || NAME_LENGTH_UPPER_BOUND < value.length(); + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 927bc5bab6..042e7d3b13 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -1,28 +1,14 @@ package ladder.domain; public class Player { - private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = - "참가자의 이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - private final String name; + private final Name name; public Player(final String name) { - validate(name); - this.name = name; - } - - private void validate(final String name) { - if (isInvalidNameLength(name)) { - throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); - } - } - - private boolean isInvalidNameLength(final String name) { - return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + this.name = new Name(name); } public String getName() { - return name; + return name.getValue(); } } diff --git a/src/test/java/ladder/domain/ItemTest.java b/src/test/java/ladder/domain/ItemTest.java index 1399dbb461..5190da567c 100644 --- a/src/test/java/ladder/domain/ItemTest.java +++ b/src/test/java/ladder/domain/ItemTest.java @@ -1,14 +1,10 @@ package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.NullAndEmptySource; -import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -20,14 +16,4 @@ public class ItemTest { assertThat(item.getName()).isEqualTo("name"); } - - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") - @NullAndEmptySource - @ValueSource(strings = {"우아한상품들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { - assertThatThrownBy(() -> new Item(name)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); - } - } diff --git a/src/test/java/ladder/domain/NameTest.java b/src/test/java/ladder/domain/NameTest.java new file mode 100644 index 0000000000..a2aa1554d2 --- /dev/null +++ b/src/test/java/ladder/domain/NameTest.java @@ -0,0 +1,33 @@ +package ladder.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class NameTest { + + @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = {"우아한형제들"}) + void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + assertThatThrownBy(() -> new Name(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("이름은 1자 이상, 5자 이하여야 합니다."); + } + + @Test + void 이름이_정상적으로_생성된다() { + final Name name = new Name("name"); + + assertThat(name.getValue()).isEqualTo("name"); + } + +} diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 0e03ee4fcc..3b99286446 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -1,14 +1,10 @@ package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.NullAndEmptySource; -import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -20,13 +16,4 @@ public class PlayerTest { assertThat(player.getName()).isEqualTo("name"); } - - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") - @NullAndEmptySource - @ValueSource(strings = {"우아한형제들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { - assertThatThrownBy(() -> new Player(name)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("참가자의 이름은 1자 이상, 5자 이하여야 합니다."); - } } From 112f329d3a03cf4dac7a34d376c71c06b6ccdc11 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 09:10:54 +0900 Subject: [PATCH 22/71] =?UTF-8?q?feat:=20=EC=B0=B8=EA=B0=80=EC=9E=90?= =?UTF-8?q?=EC=99=80=20=EC=8B=A4=ED=96=89=EA=B2=B0=EA=B3=BC=EC=97=90=20Pos?= =?UTF-8?q?ition=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- src/main/java/ladder/domain/Item.java | 10 ++++++++-- src/main/java/ladder/domain/Items.java | 6 ++++-- src/main/java/ladder/domain/Player.java | 8 +++++++- src/main/java/ladder/domain/Players.java | 6 ++++-- src/main/java/ladder/domain/Position.java | 8 ++++---- src/test/java/ladder/domain/ItemTest.java | 9 ++++++++- src/test/java/ladder/domain/PlayerTest.java | 9 ++++++++- src/test/java/ladder/domain/PositionTest.java | 10 +++++----- 9 files changed, 51 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 01eb559723..25c288e445 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,14 @@ graph TD - [x] 참가자가 1명 이하인 경우 예외를 던진다. - [ ] 참가자는 최대 20명 이어야 한다. - [ ] 참가자가 20명을 초과하는 경우 예외를 던진다. +- [x] 참가자는 위치를 가진다. ### 아이템(실행결과) - [x] 아이템은 이름을 가진다. - - [ ] 이름 길이는 참가자의 이름과 동일하게 1자 이상, 5자 이하의 길이를 가진다. + - [x] 이름 길이는 참가자의 이름과 동일하게 1자 이상, 5자 이하의 길이를 가진다. - [x] 아이템은 참가인원과 동일한 개수가 있어야 한다. +- [x] 아이템은 위치를 가진다. ### 사다리 게임 diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java index 392251f6aa..34385f8571 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -1,14 +1,20 @@ package ladder.domain; public class Item { - + private final Name name; + private Position position; - public Item(final String name) { + public Item(final String name, final Position position) { this.name = new Name(name); + this.position = position; } public String getName() { return name.getValue(); } + + public Position getPosition() { + return position; + } } diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index 4753b56f43..fedf0c65df 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -4,6 +4,7 @@ import static java.util.stream.Collectors.toList; import java.util.List; +import java.util.stream.IntStream; public class Items { private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; @@ -16,8 +17,9 @@ private Items(final List items) { public static Items from(final List items, int playerCount) { validateItemCount(items, playerCount); - return items.stream() - .map(Item::new) + return IntStream.range(0, items.size()) + .boxed() + .map(index -> new Item(items.get(index), Position.valueOf(index))) .collect(collectingAndThen(toList(), Items::new)); } diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 042e7d3b13..098b56d356 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -3,12 +3,18 @@ public class Player { private final Name name; + private Position position; - public Player(final String name) { + public Player(final String name, final Position position) { this.name = new Name(name); + this.position = position; } public String getName() { return name.getValue(); } + + public Position getPosition() { + return position; + } } diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index bc336e8fb9..fdcc27dc94 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.IntStream; public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; @@ -21,8 +22,9 @@ private Players(final List players) { public static Players from(final List names) { validate(names); - return names.stream() - .map(Player::new) + return IntStream.range(0, names.size()) + .boxed() + .map(index -> new Player(names.get(index), Position.valueOf(index))) .collect(collectingAndThen(toList(), Players::new)); } diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index 8663a2e360..3be8bfeea6 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -5,14 +5,14 @@ public class Position { - private static final int POSITION_VALUE_LOWER_BOUND = 1; + private static final int POSITION_VALUE_LOWER_BOUND = 0; private static final int POSITION_VALUE_UPPER_BOUND = 20; private static final String INVALID_VALUE_MESSAGE = - "위치값은 " + POSITION_VALUE_LOWER_BOUND + "이상, " + POSITION_VALUE_UPPER_BOUND + "이하여야 합니다."; + "위치값은 " + POSITION_VALUE_LOWER_BOUND + "이상, " + POSITION_VALUE_UPPER_BOUND + "미만이어야 합니다."; private static final Map CACHE = new HashMap<>(); static { - for (int i = POSITION_VALUE_LOWER_BOUND; i <= POSITION_VALUE_UPPER_BOUND; i++) { + for (int i = POSITION_VALUE_LOWER_BOUND; i < POSITION_VALUE_UPPER_BOUND; i++) { CACHE.put(i, new Position(i)); } } @@ -35,7 +35,7 @@ private static void validate(final int value) { } private static boolean isInvalidPosition(final int value) { - return value < POSITION_VALUE_LOWER_BOUND || POSITION_VALUE_UPPER_BOUND < value; + return value < POSITION_VALUE_LOWER_BOUND || POSITION_VALUE_UPPER_BOUND <= value; } public int getValue() { diff --git a/src/test/java/ladder/domain/ItemTest.java b/src/test/java/ladder/domain/ItemTest.java index 5190da567c..01c960c7a5 100644 --- a/src/test/java/ladder/domain/ItemTest.java +++ b/src/test/java/ladder/domain/ItemTest.java @@ -12,8 +12,15 @@ public class ItemTest { @Test void 실행결과는_이름을_가진다() { - final Item item = new Item("name"); + final Item item = new Item("name", Position.valueOf(1)); assertThat(item.getName()).isEqualTo("name"); } + + @Test + void 실행결과는_위치를_가진다() { + final Item item = new Item("name", Position.valueOf(1)); + + assertThat(item.getPosition()).isEqualTo(Position.valueOf(1)); + } } diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 3b99286446..581a6d7b9c 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -12,8 +12,15 @@ public class PlayerTest { @Test void 참가자는_이름을_가진다() { - final Player player = new Player("name"); + final Player player = new Player("name", Position.valueOf(1)); assertThat(player.getName()).isEqualTo("name"); } + + @Test + void 참가자는_위치를_가진다() { + final Player player = new Player("name", Position.valueOf(1)); + + assertThat(player.getPosition()).isEqualTo(Position.valueOf(1)); + } } diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java index 3819b961b9..96a21a7db7 100644 --- a/src/test/java/ladder/domain/PositionTest.java +++ b/src/test/java/ladder/domain/PositionTest.java @@ -12,16 +12,16 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class PositionTest { - @ParameterizedTest(name = "위치값이 0보다 작거나 20보다 큰 경우 예외를 던진다 입력값: {0}") - @ValueSource(ints = {-1, 0, 21}) - void 위치값이_1보다_작거나_20보다_큰_경우_예외를_던진다(final int value) { + @ParameterizedTest(name = "위치값이 0보다 작거나 20이상인 경우 예외를 던진다 입력값: {0}") + @ValueSource(ints = {-1, 20}) + void 위치값이_0보다_작거나_20이상인_경우_예외를_던진다(final int value) { assertThatThrownBy(() -> Position.valueOf(value)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("위치값은 1이상, 20이하여야 합니다."); + .hasMessage("위치값은 0이상, 20미만이어야 합니다."); } @ParameterizedTest(name = "올바른 위치값을 받으면 정상적으로 생성된다. 입력값: {0}") - @ValueSource(ints = {1, 20}) + @ValueSource(ints = {0, 19}) void 올바른_위치값을_받으면_정상적으로_생성된다(final int value) { final Position position = Position.valueOf(value); From 3527a007384ddea6ee002964de1ad0f0a01bbd0f Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 09:22:27 +0900 Subject: [PATCH 23/71] =?UTF-8?q?feat:=20=EC=B0=B8=EA=B0=80=EC=9E=90?= =?UTF-8?q?=EC=88=98=20=EC=83=81=ED=95=9C=EC=84=A0=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/java/ladder/domain/Players.java | 6 ++++-- src/test/java/ladder/domain/PlayersTest.java | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 25c288e445..7e566d11c9 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ graph TD - [x] 중복된 이름이 존재하는 경우 예외를 던진다. - [x] 참가자는 최소 2명 이어야 한다. - [x] 참가자가 1명 이하인 경우 예외를 던진다. -- [ ] 참가자는 최대 20명 이어야 한다. - - [ ] 참가자가 20명을 초과하는 경우 예외를 던진다. +- [x] 참가자는 최대 20명 이어야 한다. + - [x] 참가자가 20명을 초과하는 경우 예외를 던진다. - [x] 참가자는 위치를 가진다. ### 아이템(실행결과) diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index fdcc27dc94..555b54eaac 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -11,7 +11,9 @@ public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; - private static final String INVALID_PLAYERS_SIZE_MESSAGE = "참가자는 최소 " + PLAYERS_SIZE_LOWER_BOUND + "명이어야 합니다."; + private static final int PLAYERS_SIZE_UPPER_BOUND = 20; + private static final String INVALID_PLAYERS_SIZE_MESSAGE = + "참가자는 최소 " + PLAYERS_SIZE_LOWER_BOUND + "명, 최대 " + PLAYERS_SIZE_UPPER_BOUND + "명이어야 합니다."; private static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; private final List players; @@ -34,7 +36,7 @@ private static void validate(final List names) { } private static void validatePlayersSize(final List names) { - if (names.size() < PLAYERS_SIZE_LOWER_BOUND) { + if (names.size() < PLAYERS_SIZE_LOWER_BOUND || PLAYERS_SIZE_UPPER_BOUND < names.size()) { throw new IllegalArgumentException(INVALID_PLAYERS_SIZE_MESSAGE); } } diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index 237020b952..e71073d4d2 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -5,19 +5,29 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class PlayersTest { - @Test - void 참가자가_한_명_이하인_경우_예외를_던진다() { - assertThatThrownBy(() -> Players.from(List.of("name"))) + @ParameterizedTest(name = "올바른 참가자 수가 아닌 경우 예외를 던진다. 참가자 수 : {0}") + @ValueSource(ints = {1, 21}) + void 올바른_참가자_수가_아닌_경우_예외를_던진다(final int playerCount) { + final List names = IntStream.range(0, playerCount) + .boxed() + .map(String::valueOf) + .collect(Collectors.toList()); + + assertThatThrownBy(() -> Players.from(names)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("참가자는 최소 2명이어야 합니다."); + .hasMessage("참가자는 최소 2명, 최대 20명이어야 합니다."); } @Test From 7660742d9fc42f6f741d97df22425adb2d0676eb Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 11:20:00 +0900 Subject: [PATCH 24/71] =?UTF-8?q?feat:=20=EC=9D=B4=EC=A0=84=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98,=20=EB=8B=A4=EC=9D=8C=20=EC=9C=84=EC=B9=98=EB=A5=BC?= =?UTF-8?q?=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++++ src/main/java/ladder/domain/Position.java | 10 ++++++ src/test/java/ladder/domain/PositionTest.java | 33 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/README.md b/README.md index 7e566d11c9..8acac2cae3 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,19 @@ graph TD LadderGame --> Players LadderGame --> Items + Player --> Name + Player --> Position + Item --> Position + Item --> Name + + Line --> Position + LadderGame --> LadderGameResult Items --> Item Players --> Player + LadderGameController --> InputView LadderGameController --> OutputView @@ -40,6 +48,7 @@ graph TD - [x] 참가자는 최대 20명 이어야 한다. - [x] 참가자가 20명을 초과하는 경우 예외를 던진다. - [x] 참가자는 위치를 가진다. + - [x] 위치 값은 0부터 시작한다. ### 아이템(실행결과) @@ -47,6 +56,7 @@ graph TD - [x] 이름 길이는 참가자의 이름과 동일하게 1자 이상, 5자 이하의 길이를 가진다. - [x] 아이템은 참가인원과 동일한 개수가 있어야 한다. - [x] 아이템은 위치를 가진다. + - [x] 위치 값은 0부터 시작한다. ### 사다리 게임 @@ -54,6 +64,7 @@ graph TD - [x] 높이는 1이상, 100이하의 값이어야 한다. - [x] 사다리의 높이만큼 가로 라인을 가진다. - [x] 각각의 가로 라인은 `사다리 게임 참가자 - 1` 너비만큼의 연결 상태를 가진다. + - [ ] `사다리 게임 참가자 - 1` 만큼의 위치값을 가지고 각 위치에 연결상태가 존재한다. - [x] 연결 상태는 연결됨, 연결되지 않음으로 구분된다. - [x] 가로 라인의 연결 상태가 연속으로 `연결됨` 일 수 없다. - [ ] 사다리 게임을 진행한다. diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index 3be8bfeea6..415a37bc3d 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -7,8 +7,10 @@ public class Position { private static final int POSITION_VALUE_LOWER_BOUND = 0; private static final int POSITION_VALUE_UPPER_BOUND = 20; + private static final int MOVE_COUNT = 1; private static final String INVALID_VALUE_MESSAGE = "위치값은 " + POSITION_VALUE_LOWER_BOUND + "이상, " + POSITION_VALUE_UPPER_BOUND + "미만이어야 합니다."; + private static final Position EMPTY = new Position(Integer.MIN_VALUE); private static final Map CACHE = new HashMap<>(); static { @@ -38,6 +40,14 @@ private static boolean isInvalidPosition(final int value) { return value < POSITION_VALUE_LOWER_BOUND || POSITION_VALUE_UPPER_BOUND <= value; } + public Position getPrevious() { + return CACHE.getOrDefault(this.value - MOVE_COUNT, EMPTY); + } + + public Position getNext() { + return CACHE.getOrDefault(this.value + MOVE_COUNT, EMPTY); + } + public int getValue() { return value; } diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java index 96a21a7db7..c90999d51d 100644 --- a/src/test/java/ladder/domain/PositionTest.java +++ b/src/test/java/ladder/domain/PositionTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -27,4 +28,36 @@ public class PositionTest { assertThat(position.getValue()).isEqualTo(value); } + + @Test + void 이전_값이_존재하지_않는_경우_사용할_수_없는_위치값을_반환한다() { + final Position position = Position.valueOf(0); + + final Position previousPosition = position.getPrevious(); + + assertThat(previousPosition.getValue()).isEqualTo(Integer.MIN_VALUE); + } + + @Test + void 이전_값을_반환한다() { + final Position position = Position.valueOf(1); + + assertThat(position.getPrevious()).isEqualTo(Position.valueOf(0)); + } + + @Test + void 다음_값이_존재하지_않는_경우_사용할_수_없는_위치값을_반환한다() { + final Position position = Position.valueOf(19); + + final Position nextPosition = position.getNext(); + + assertThat(nextPosition.getValue()).isEqualTo(Integer.MIN_VALUE); + } + + @Test + void 다음_값을_반환한다() { + final Position position = Position.valueOf(18); + + assertThat(position.getNext()).isEqualTo(Position.valueOf(19)); + } } From afb96fdbbce29f21eef377202971c6acfe28023c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 17:06:04 +0900 Subject: [PATCH 25/71] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=ED=95=9C=20?= =?UTF-8?q?=EA=B0=92=EA=B9=8C=EC=A7=80=EC=9D=98=20Position=EC=9D=84=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Position.java | 9 +++++++++ src/test/java/ladder/domain/PositionTest.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index 415a37bc3d..f9d653f361 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -1,7 +1,10 @@ package ladder.domain; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class Position { @@ -40,6 +43,12 @@ private static boolean isInvalidPosition(final int value) { return value < POSITION_VALUE_LOWER_BOUND || POSITION_VALUE_UPPER_BOUND <= value; } + public static List range(final int endExclusive) { + return IntStream.range(POSITION_VALUE_LOWER_BOUND, endExclusive) + .mapToObj(Position::valueOf) + .collect(Collectors.toList()); + } + public Position getPrevious() { return CACHE.getOrDefault(this.value - MOVE_COUNT, EMPTY); } diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java index c90999d51d..432b45cbcc 100644 --- a/src/test/java/ladder/domain/PositionTest.java +++ b/src/test/java/ladder/domain/PositionTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -29,6 +30,20 @@ public class PositionTest { assertThat(position.getValue()).isEqualTo(value); } + @Test + void 입력한_값까지의_Position을_반환한다() { + final List positions = Position.range(3); + + assertThat(positions).containsExactly(Position.valueOf(0), Position.valueOf(1), Position.valueOf(2)); + } + + @Test + void 허용범위_밖_위치값을_입력하는_경우_예외를_던진다() { + assertThatThrownBy(() -> Position.range(21)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("위치값은 0이상, 20미만이어야 합니다."); + } + @Test void 이전_값이_존재하지_않는_경우_사용할_수_없는_위치값을_반환한다() { final Position position = Position.valueOf(0); From 8c7c9979610a449eaeefa1b96161c1509a009c86 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Wed, 22 Feb 2023 23:17:06 +0900 Subject: [PATCH 26/71] =?UTF-8?q?feat:=20=EA=B0=80=EB=A1=9C=EB=9D=BC?= =?UTF-8?q?=EC=9D=B8=20=ED=95=9C=20=EC=A4=84=EC=97=90=20=EB=8C=80=ED=95=9C?= =?UTF-8?q?=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20=EA=B2=8C=EC=9E=84=EC=9D=84=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - src/main/java/ladder/domain/Line.java | 44 +++++++++++++++-------- src/test/java/ladder/domain/LineTest.java | 16 ++++++++- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8acac2cae3..9ed99f0ed7 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,6 @@ graph TD Items --> Item Players --> Player - LadderGameController --> InputView LadderGameController --> OutputView diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index 6db10ed773..b628254b3b 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -1,43 +1,59 @@ package ladder.domain; -import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Collections; -import java.util.Deque; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class Line { - private final List statuses; + private final Map statuses; - private Line(final List statuses) { + private Line(final Map statuses) { this.statuses = statuses; } public static Line generate(final BooleanGenerator booleanGenerator, final int width) { - final Deque statuses = new ArrayDeque<>(); - while (statuses.size() < width) { - statuses.add(generateLineStatus(booleanGenerator, statuses)); + final Map statuses = new LinkedHashMap<>(); + for (Position position : Position.range(width)) { + final LineStatus previousStatus = getPreviousLineStatus(statuses, position); + statuses.put(position, generateLineStatus(booleanGenerator, previousStatus)); } - return new Line(new ArrayList<>(statuses)); + return new Line(statuses); + } + + private static LineStatus getPreviousLineStatus(final Map statuses, final Position position) { + return statuses.getOrDefault(position.getPrevious(), LineStatus.DISCONNECTED); } private static LineStatus generateLineStatus( final BooleanGenerator booleanGenerator, - final Deque statuses + final LineStatus previousLineStatus ) { final boolean status = booleanGenerator.generate(); - if (isConnectable(statuses)) { + if (previousLineStatus.isDisconnected()) { return LineStatus.from(status); } return LineStatus.DISCONNECTED; } - private static boolean isConnectable(final Deque statuses) { - return statuses.isEmpty() || statuses.getLast().isDisconnected(); + public Position play(final Position position) { + if (isConnected(position.getPrevious())) { + return position.getPrevious(); + } + + if (isConnected(position)) { + return position.getNext(); + } + + return position; + } + + private boolean isConnected(final Position position) { + return statuses.getOrDefault(position, LineStatus.DISCONNECTED).isConnected(); } public List getLine() { - return Collections.unmodifiableList(statuses); + return new ArrayList<>(statuses.values()); } } diff --git a/src/test/java/ladder/domain/LineTest.java b/src/test/java/ladder/domain/LineTest.java index 1272dac138..79b7334cfa 100644 --- a/src/test/java/ladder/domain/LineTest.java +++ b/src/test/java/ladder/domain/LineTest.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -21,7 +23,7 @@ public class LineTest { assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, DISCONNECTED); } - + @Test void 가로_라인의_연결_상태값이_연속으로_연결됨일_수_없다() { final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, true, true, true, true)); @@ -29,4 +31,16 @@ public class LineTest { assertThat(line.getLine()).containsExactly(CONNECTED, DISCONNECTED, CONNECTED, DISCONNECTED, CONNECTED); } + + @ParameterizedTest(name = "가로라인 한 줄에 대한 사다리 게임을 진행한다. start: {0} end: {1}") + @CsvSource({"0,1", "1,0", "2,3", "3,2", "4,4", "5,5"}) + void 가로라인_한_줄에_대한_사다리게임을_진행한다(final int startPosition, final int endPosition) { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of(true, false, true, false, false)); + final Line line = Line.generate(booleanGenerator, 5); + final Position position = Position.valueOf(startPosition); + + Position result = line.play(position); + + assertThat(result).isEqualTo(Position.valueOf(endPosition)); + } } From 86748d9777adac1176ce255018f6f80771a20117 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 09:01:48 +0900 Subject: [PATCH 27/71] =?UTF-8?q?feat:=20=ED=95=9C=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EC=A7=84=ED=96=89=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/java/ladder/domain/Ladder.java | 8 ++++++++ src/test/java/ladder/domain/LadderTest.java | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ed99f0ed7..f5a3a55017 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,10 @@ graph TD - [x] 높이는 1이상, 100이하의 값이어야 한다. - [x] 사다리의 높이만큼 가로 라인을 가진다. - [x] 각각의 가로 라인은 `사다리 게임 참가자 - 1` 너비만큼의 연결 상태를 가진다. - - [ ] `사다리 게임 참가자 - 1` 만큼의 위치값을 가지고 각 위치에 연결상태가 존재한다. + - [x] `사다리 게임 참가자 - 1` 만큼의 위치값을 가지고 각 위치에 연결상태가 존재한다. - [x] 연결 상태는 연결됨, 연결되지 않음으로 구분된다. - [x] 가로 라인의 연결 상태가 연속으로 `연결됨` 일 수 없다. -- [ ] 사다리 게임을 진행한다. +- [x] 사다리 게임을 진행한다. - [ ] 모든 참가자에 대한 결과를 반환한다. ### 입력 diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index f6dad229bc..1a44531e20 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -24,4 +24,12 @@ public static Ladder generate(final BooleanGenerator booleanGenerator, final int public List getLines() { return Collections.unmodifiableList(lines); } + + public Position play(final Position position) { + Position currentPosition = position; + for (Line line : lines) { + currentPosition = line.play(currentPosition); + } + return currentPosition; + } } diff --git a/src/test/java/ladder/domain/LadderTest.java b/src/test/java/ladder/domain/LadderTest.java index ad97bae0a5..6d07cc9b8e 100644 --- a/src/test/java/ladder/domain/LadderTest.java +++ b/src/test/java/ladder/domain/LadderTest.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -26,4 +28,20 @@ public class LadderTest { List.of(CONNECTED, DISCONNECTED) ); } + + @ParameterizedTest(name = "한 위치에 대한 사다리 게임을 진행한다. start: {0} end: {1}") + @CsvSource({"0,1", "1,3", "2,2", "3,0"}) + void 한_위치에_대한_사다리게임을_진행한다(final int startPosition, final int endPosition) { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( + false, false, true, + false, true, false, + true, false, true + )); + final Ladder ladder = Ladder.generate(booleanGenerator, 3, 3); + final Position position = Position.valueOf(startPosition); + + Position result = ladder.play(position); + + assertThat(result).isEqualTo(Position.valueOf(endPosition)); + } } From fd278f653688d0b2e91740cf146d80004619a278 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 09:38:46 +0900 Subject: [PATCH 28/71] =?UTF-8?q?style:=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Ladder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index 1a44531e20..5b1a188cf7 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -21,10 +21,6 @@ public static Ladder generate(final BooleanGenerator booleanGenerator, final int .collect(collectingAndThen(toList(), Ladder::new)); } - public List getLines() { - return Collections.unmodifiableList(lines); - } - public Position play(final Position position) { Position currentPosition = position; for (Line line : lines) { @@ -32,4 +28,8 @@ public Position play(final Position position) { } return currentPosition; } + + public List getLines() { + return Collections.unmodifiableList(lines); + } } From 7de3d9937071d713791b43a1938e6d5f98def68d Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 11:19:03 +0900 Subject: [PATCH 29/71] =?UTF-8?q?feat:=20=EA=B2=8C=EC=9E=84=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ladder/domain/LadderGameResult.java | 34 ++++++++++++++ .../ladder/domain/LadderGameResultTest.java | 46 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/main/java/ladder/domain/LadderGameResult.java create mode 100644 src/test/java/ladder/domain/LadderGameResultTest.java diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java new file mode 100644 index 0000000000..3d1322ea1e --- /dev/null +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -0,0 +1,34 @@ +package ladder.domain; + +import java.util.LinkedHashMap; +import java.util.Map; + +class LadderGameResult { + + private static final String PRINT_ALL = "all"; + private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; + + private final Map result; + + public LadderGameResult(final Map result) { + this.result = result; + } + + public Map get(final String name) { + if (name.equals(PRINT_ALL)) { + return getAll(); + } + return getSingle(name); + } + + private Map getAll() { + return new LinkedHashMap<>(result); + } + + private Map getSingle(final String name) { + if (!result.containsKey(name)) { + throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); + } + return Map.of(name, result.get(name)); + } +} diff --git a/src/test/java/ladder/domain/LadderGameResultTest.java b/src/test/java/ladder/domain/LadderGameResultTest.java new file mode 100644 index 0000000000..d72e5398a3 --- /dev/null +++ b/src/test/java/ladder/domain/LadderGameResultTest.java @@ -0,0 +1,46 @@ +package ladder.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.entry; + +import java.util.Map; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class LadderGameResultTest { + + @Test + void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of("name", "1000")); + + assertThatThrownBy(() -> ladderGameResult.get("NONAME")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("사다리 게임에 참가한 사람의 이름을 입력해야합니다."); + } + + @Test + void 한_사람에_대한_게임_결과를_반환한다() { + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of("name", "1000")); + + final Map result = ladderGameResult.get("name"); + + assertThat(result).containsExactly(entry("name", "1000")); + } + + @Test + void 모든_사람에_대한_게임_결과를_반환한다() { + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( + "name", "0", + "name2", "1000" + )); + + final Map result = ladderGameResult.get("all"); + + assertThat(result).contains(entry("name", "0"), entry("name2", "1000")); + } + +} From 4cfd6eebba2aa189906fb37dca5de1cbbff3a2ab Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 12:58:28 +0900 Subject: [PATCH 30/71] =?UTF-8?q?refactor:=20Items,=20Players=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=8B=9C=20Map=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Item.java | 28 ++++++++++------- src/main/java/ladder/domain/Items.java | 29 +++++++++++------- src/main/java/ladder/domain/Name.java | 29 ------------------ src/main/java/ladder/domain/Player.java | 26 ++++++++++------ src/main/java/ladder/domain/Players.java | 28 ++++++++--------- src/test/java/ladder/domain/ItemTest.java | 18 +++++++---- src/test/java/ladder/domain/ItemsTest.java | 11 +++++-- src/test/java/ladder/domain/NameTest.java | 33 --------------------- src/test/java/ladder/domain/PlayerTest.java | 18 +++++++---- 9 files changed, 100 insertions(+), 120 deletions(-) delete mode 100644 src/main/java/ladder/domain/Name.java delete mode 100644 src/test/java/ladder/domain/NameTest.java diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java index 34385f8571..c4bbaac74a 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -1,20 +1,28 @@ package ladder.domain; -public class Item { +class Item { + private static final int NAME_LENGTH_UPPER_BOUND = 5; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - private final Name name; - private Position position; + private final String name; - public Item(final String name, final Position position) { - this.name = new Name(name); - this.position = position; + public Item(final String name) { + validate(name); + this.name = name; } - public String getName() { - return name.getValue(); + private void validate(final String name) { + if (isInvalidNameLength(name)) { + throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); + } + } + + private boolean isInvalidNameLength(final String name) { + return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); } - public Position getPosition() { - return position; + public String getName() { + return name; } } diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index fedf0c65df..40028f8de8 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -1,26 +1,27 @@ package ladder.domain; -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toUnmodifiableList; +import java.util.LinkedHashMap; import java.util.List; -import java.util.stream.IntStream; +import java.util.Map; public class Items { private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; - private final List items; + private final Map items; - private Items(final List items) { + private Items(final Map items) { this.items = items; } - public static Items from(final List items, int playerCount) { - validateItemCount(items, playerCount); - return IntStream.range(0, items.size()) - .boxed() - .map(index -> new Item(items.get(index), Position.valueOf(index))) - .collect(collectingAndThen(toList(), Items::new)); + public static Items from(final List names, int playerCount) { + validateItemCount(names, playerCount); + final Map items = new LinkedHashMap<>(); + for (int index = 0; index < names.size(); index++) { + items.put(Position.valueOf(index), new Item(names.get(index))); + } + return new Items(items); } private static void validateItemCount(final List items, final int playerCount) { @@ -28,4 +29,10 @@ private static void validateItemCount(final List items, final int player throw new IllegalArgumentException(INVALID_ITEM_COUNT_MESSAGE); } } + + public List getNames() { + return items.values().stream() + .map(Item::getName) + .collect(toUnmodifiableList()); + } } diff --git a/src/main/java/ladder/domain/Name.java b/src/main/java/ladder/domain/Name.java deleted file mode 100644 index 73f3de88c2..0000000000 --- a/src/main/java/ladder/domain/Name.java +++ /dev/null @@ -1,29 +0,0 @@ -package ladder.domain; - -class Name { - - private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = - "이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - - private final String value; - - public Name(final String value) { - validate(value); - this.value = value; - } - - private void validate(final String value) { - if (isInvalidNameLength(value)) { - throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); - } - } - - private boolean isInvalidNameLength(final String value) { - return value == null || value.isBlank() || NAME_LENGTH_UPPER_BOUND < value.length(); - } - - public String getValue() { - return value; - } -} diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 098b56d356..927bc5bab6 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -1,20 +1,28 @@ package ladder.domain; public class Player { + private static final int NAME_LENGTH_UPPER_BOUND = 5; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "참가자의 이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - private final Name name; - private Position position; + private final String name; - public Player(final String name, final Position position) { - this.name = new Name(name); - this.position = position; + public Player(final String name) { + validate(name); + this.name = name; } - public String getName() { - return name.getValue(); + private void validate(final String name) { + if (isInvalidNameLength(name)) { + throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); + } + } + + private boolean isInvalidNameLength(final String name) { + return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); } - public Position getPosition() { - return position; + public String getName() { + return name; } } diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index 555b54eaac..209e4d609d 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -1,13 +1,12 @@ package ladder.domain; -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toUnmodifiableList; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; -import java.util.stream.IntStream; public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; @@ -16,18 +15,19 @@ public class Players { "참가자는 최소 " + PLAYERS_SIZE_LOWER_BOUND + "명, 최대 " + PLAYERS_SIZE_UPPER_BOUND + "명이어야 합니다."; private static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; - private final List players; + private final Map players; - private Players(final List players) { + private Players(final Map players) { this.players = players; } public static Players from(final List names) { validate(names); - return IntStream.range(0, names.size()) - .boxed() - .map(index -> new Player(names.get(index), Position.valueOf(index))) - .collect(collectingAndThen(toList(), Players::new)); + final Map players = new LinkedHashMap<>(); + for (int index = 0; index < names.size(); index++) { + players.put(Position.valueOf(index), new Player(names.get(index))); + } + return new Players(players); } private static void validate(final List names) { @@ -48,13 +48,13 @@ private static void validateDuplicateNames(final List names) { } } + public int count() { + return players.size(); + } + public List getNames() { - return players.stream() + return players.values().stream() .map(Player::getName) .collect(toUnmodifiableList()); } - - public int count() { - return players.size(); - } } diff --git a/src/test/java/ladder/domain/ItemTest.java b/src/test/java/ladder/domain/ItemTest.java index 01c960c7a5..9502422c80 100644 --- a/src/test/java/ladder/domain/ItemTest.java +++ b/src/test/java/ladder/domain/ItemTest.java @@ -1,10 +1,14 @@ package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -12,15 +16,17 @@ public class ItemTest { @Test void 실행결과는_이름을_가진다() { - final Item item = new Item("name", Position.valueOf(1)); + final Item item = new Item("name"); assertThat(item.getName()).isEqualTo("name"); } - @Test - void 실행결과는_위치를_가진다() { - final Item item = new Item("name", Position.valueOf(1)); - - assertThat(item.getPosition()).isEqualTo(Position.valueOf(1)); + @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = {"우아한상품들"}) + void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + assertThatThrownBy(() -> new Item(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); } } diff --git a/src/test/java/ladder/domain/ItemsTest.java b/src/test/java/ladder/domain/ItemsTest.java index 08c5b00782..8ff8d9b616 100644 --- a/src/test/java/ladder/domain/ItemsTest.java +++ b/src/test/java/ladder/domain/ItemsTest.java @@ -1,8 +1,9 @@ package ladder.domain; -import static java.util.List.of; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -13,9 +14,15 @@ public class ItemsTest { @Test void 실행결과는_참가인원과_동일한_개수가_아니라면_예외를_던진다() { - assertThatThrownBy(() -> Items.from(of("item1", "item2"), 3)) + assertThatThrownBy(() -> Items.from(List.of("item1", "item2"), 3)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("참가인원과 동일한 개수의 실행결과를 입력해야 합니다."); } + @Test + void 모든_실행결과의_이름을_반환한다() { + final Items items = Items.from(List.of("item1", "item2", "item3"), 3); + + assertThat(items.getNames()).containsExactly("item1", "item2", "item3"); + } } diff --git a/src/test/java/ladder/domain/NameTest.java b/src/test/java/ladder/domain/NameTest.java deleted file mode 100644 index a2aa1554d2..0000000000 --- a/src/test/java/ladder/domain/NameTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package ladder.domain; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.NullAndEmptySource; -import org.junit.jupiter.params.provider.ValueSource; - -@SuppressWarnings("NonAsciiCharacters") -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -public class NameTest { - - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") - @NullAndEmptySource - @ValueSource(strings = {"우아한형제들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { - assertThatThrownBy(() -> new Name(name)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("이름은 1자 이상, 5자 이하여야 합니다."); - } - - @Test - void 이름이_정상적으로_생성된다() { - final Name name = new Name("name"); - - assertThat(name.getValue()).isEqualTo("name"); - } - -} diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 581a6d7b9c..0e03ee4fcc 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -1,10 +1,14 @@ package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -12,15 +16,17 @@ public class PlayerTest { @Test void 참가자는_이름을_가진다() { - final Player player = new Player("name", Position.valueOf(1)); + final Player player = new Player("name"); assertThat(player.getName()).isEqualTo("name"); } - @Test - void 참가자는_위치를_가진다() { - final Player player = new Player("name", Position.valueOf(1)); - - assertThat(player.getPosition()).isEqualTo(Position.valueOf(1)); + @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = {"우아한형제들"}) + void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + assertThatThrownBy(() -> new Player(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("참가자의 이름은 1자 이상, 5자 이하여야 합니다."); } } From d5a20247295cba9de6ca99f03a98fa5a96a9790b Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 13:51:19 +0900 Subject: [PATCH 31/71] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=EC=9D=98=20=ED=83=80=EC=9E=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ladder/domain/LadderGameResult.java | 20 +++++++++++++------ src/main/java/ladder/domain/Player.java | 19 ++++++++++++++++++ .../ladder/domain/LadderGameResultTest.java | 14 ++++++++----- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 3d1322ea1e..69658a010a 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -1,6 +1,7 @@ package ladder.domain; -import java.util.LinkedHashMap; +import static java.util.stream.Collectors.toMap; + import java.util.Map; class LadderGameResult { @@ -8,9 +9,9 @@ class LadderGameResult { private static final String PRINT_ALL = "all"; private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; - private final Map result; + private final Map result; - public LadderGameResult(final Map result) { + public LadderGameResult(final Map result) { this.result = result; } @@ -22,13 +23,20 @@ public Map get(final String name) { } private Map getAll() { - return new LinkedHashMap<>(result); + return result.keySet().stream() + .collect(toMap(Player::getName, this::getItemName)); + } + + private String getItemName(final Player player) { + return result.get(player).getName(); } private Map getSingle(final String name) { - if (!result.containsKey(name)) { + final Player player = new Player(name); + if (!result.containsKey(player)) { throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); } - return Map.of(name, result.get(name)); + final Item item = result.get(player); + return Map.of(player.getName(), item.getName()); } } diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 927bc5bab6..f8228fe399 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -1,5 +1,7 @@ package ladder.domain; +import java.util.Objects; + public class Player { private static final int NAME_LENGTH_UPPER_BOUND = 5; private static final String INVALID_NAME_LENGTH_MESSAGE = @@ -25,4 +27,21 @@ private boolean isInvalidNameLength(final String name) { public String getName() { return name; } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Player player = (Player) o; + return Objects.equals(name, player.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } } diff --git a/src/test/java/ladder/domain/LadderGameResultTest.java b/src/test/java/ladder/domain/LadderGameResultTest.java index d72e5398a3..d834b6a5cf 100644 --- a/src/test/java/ladder/domain/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/LadderGameResultTest.java @@ -15,16 +15,20 @@ public class LadderGameResultTest { @Test void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { - final LadderGameResult ladderGameResult = new LadderGameResult(Map.of("name", "1000")); + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( + new Player("name"), new Item("1000") + )); - assertThatThrownBy(() -> ladderGameResult.get("NONAME")) + assertThatThrownBy(() -> ladderGameResult.get("whois")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("사다리 게임에 참가한 사람의 이름을 입력해야합니다."); } @Test void 한_사람에_대한_게임_결과를_반환한다() { - final LadderGameResult ladderGameResult = new LadderGameResult(Map.of("name", "1000")); + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( + new Player("name"), new Item("1000") + )); final Map result = ladderGameResult.get("name"); @@ -34,8 +38,8 @@ public class LadderGameResultTest { @Test void 모든_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - "name", "0", - "name2", "1000" + new Player("name"), new Item("0"), + new Player("name2"), new Item("1000") )); final Map result = ladderGameResult.get("all"); From c50ec09e707a51ce909f133343f3637823e3d3aa Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 13:54:07 +0900 Subject: [PATCH 32/71] =?UTF-8?q?feat:=20=EC=98=88=EC=95=BD=EC=96=B4?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EB=A6=84=EC=9C=BC=EB=A1=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EB=AA=BB=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 17 +++++++++++++++++ src/test/java/ladder/domain/PlayerTest.java | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index f8228fe399..42d8d699d0 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -6,6 +6,8 @@ public class Player { private static final int NAME_LENGTH_UPPER_BOUND = 5; private static final String INVALID_NAME_LENGTH_MESSAGE = "참가자의 이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + private static final String RESERVED_NAME = "all"; + private static final String RESERVED_NAME_MESSAGE = "all은 사용할 수 없는 이름입니다."; private final String name; @@ -15,6 +17,11 @@ public Player(final String name) { } private void validate(final String name) { + validateInvalidNameLength(name); + validateReservedName(name); + } + + private void validateInvalidNameLength(final String name) { if (isInvalidNameLength(name)) { throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); } @@ -24,6 +31,16 @@ private boolean isInvalidNameLength(final String name) { return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); } + private void validateReservedName(final String name) { + if (isReservedName(name)) { + throw new IllegalArgumentException(RESERVED_NAME_MESSAGE); + } + } + + private boolean isReservedName(final String name) { + return name.equals(RESERVED_NAME); + } + public String getName() { return name; } diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 0e03ee4fcc..73278e2ae5 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -29,4 +29,11 @@ public class PlayerTest { .isInstanceOf(IllegalArgumentException.class) .hasMessage("참가자의 이름은 1자 이상, 5자 이하여야 합니다."); } + + @Test + void all을_이름으로_사용할_수_없다() { + assertThatThrownBy(() -> new Player("all")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("all은 사용할 수 없는 이름입니다."); + } } From 933e2be051f6b671c117988a442c7382623002ee Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 15:27:07 +0900 Subject: [PATCH 33/71] =?UTF-8?q?feat:=20=EB=AA=A8=EB=93=A0=20=EC=B0=B8?= =?UTF-8?q?=EA=B0=80=EC=9E=90=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=82=AC?= =?UTF-8?q?=EB=8B=A4=EB=A6=AC=20=EA=B2=8C=EC=9E=84=EC=9D=84=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/ladder/domain/Items.java | 4 ++++ src/main/java/ladder/domain/LadderGame.java | 11 ++++++++++ .../java/ladder/domain/LadderGameResult.java | 10 +++++---- src/main/java/ladder/domain/Players.java | 4 ++++ src/test/java/ladder/domain/ItemsTest.java | 9 ++++++++ .../java/ladder/domain/LadderGameTest.java | 22 +++++++++++++++++++ src/test/java/ladder/domain/PlayersTest.java | 17 ++++++++++---- 8 files changed, 70 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f5a3a55017..47e3937902 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ graph TD - [x] 연결 상태는 연결됨, 연결되지 않음으로 구분된다. - [x] 가로 라인의 연결 상태가 연속으로 `연결됨` 일 수 없다. - [x] 사다리 게임을 진행한다. -- [ ] 모든 참가자에 대한 결과를 반환한다. +- [x] 모든 참가자에 대한 결과를 반환한다. ### 입력 diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index 40028f8de8..b9f6bf2af6 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -30,6 +30,10 @@ private static void validateItemCount(final List items, final int player } } + public Item get(final Position position) { + return items.get(position); + } + public List getNames() { return items.values().stream() .map(Item::getName) diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index 2aec201715..2bc73b6c0f 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -1,6 +1,8 @@ package ladder.domain; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class LadderGame { private static final int SUBTRACT_LADDER_WIDTH_VALUE = 1; @@ -25,6 +27,15 @@ public static LadderGame initialize( return new LadderGame(players, ladder, items); } + public LadderGameResult play() { + final Map result = new LinkedHashMap<>(); + for (Position position : Position.range(players.count())) { + final Position resultPosition = ladder.play(position); + result.put(players.get(position), items.get(resultPosition)); + } + return new LadderGameResult(result); + } + public List getPlayers() { return players.getNames(); } diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 69658a010a..3fab6923ba 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -1,7 +1,6 @@ package ladder.domain; -import static java.util.stream.Collectors.toMap; - +import java.util.LinkedHashMap; import java.util.Map; class LadderGameResult { @@ -23,8 +22,11 @@ public Map get(final String name) { } private Map getAll() { - return result.keySet().stream() - .collect(toMap(Player::getName, this::getItemName)); + final Map playerToItem = new LinkedHashMap<>(); + for (Player player : result.keySet()) { + playerToItem.put(player.getName(), getItemName(player)); + } + return playerToItem; } private String getItemName(final Player player) { diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index 209e4d609d..a108b9eafa 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -52,6 +52,10 @@ public int count() { return players.size(); } + public Player get(final Position position) { + return players.get(position); + } + public List getNames() { return players.values().stream() .map(Player::getName) diff --git a/src/test/java/ladder/domain/ItemsTest.java b/src/test/java/ladder/domain/ItemsTest.java index 8ff8d9b616..c2a61cd33d 100644 --- a/src/test/java/ladder/domain/ItemsTest.java +++ b/src/test/java/ladder/domain/ItemsTest.java @@ -19,6 +19,15 @@ public class ItemsTest { .hasMessage("참가인원과 동일한 개수의 실행결과를 입력해야 합니다."); } + @Test + void 입력받은_위치에_해당하는_실행결과를_반환한다() { + final Items items = Items.from(List.of("item1", "item2", "item3"), 3); + + final Item item = items.get(Position.valueOf(1)); + + assertThat(item.getName()).isEqualTo("item2"); + } + @Test void 모든_실행결과의_이름을_반환한다() { final Items items = Items.from(List.of("item1", "item2", "item3"), 3); diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index a65c746397..40bb441c44 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -1,6 +1,7 @@ package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; import java.util.List; import ladder.util.TestBooleanGenerator; @@ -53,4 +54,25 @@ private LadderGame initializeLadderGame( List.of(LineStatus.CONNECTED) ); } + + @Test + void 모든_참가자에_대한_사다리게임을_진행한다() { + final LadderGame ladderGame = initializeLadderGame( + List.of("name1", "name2", "name3"), + List.of( + true, false, + false, true + ), + 2, + List.of("item1", "item2", "item3") + ); + + LadderGameResult ladderGameResult = ladderGame.play(); + + assertThat(ladderGameResult.get("all")).containsExactly( + entry("name1", "item3"), + entry("name2", "item1"), + entry("name3", "item2") + ); + } } diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index e71073d4d2..fd273e4f14 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -43,16 +43,25 @@ public class PlayersTest { } @Test - void 모든_참가자의_이름을_반환한다() { + void 참가_인원을_반환한다() { final Players players = Players.from(List.of("name1", "name2")); - assertThat(players.getNames()).containsExactly("name1", "name2"); + assertThat(players.count()).isEqualTo(2); } @Test - void 참가_인원을_반환한다() { + void 입력받은_위치에_해당하는_참가자를_반환한다() { final Players players = Players.from(List.of("name1", "name2")); - assertThat(players.count()).isEqualTo(2); + final Player result = players.get(Position.valueOf(0)); + + assertThat(result).isEqualTo(new Player("name1")); + } + + @Test + void 모든_참가자의_이름을_반환한다() { + final Players players = Players.from(List.of("name1", "name2")); + + assertThat(players.getNames()).containsExactly("name1", "name2"); } } From 03e46fa1734325b1636b4c897d37673ff80f699b Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 16:20:21 +0900 Subject: [PATCH 34/71] =?UTF-8?q?feat:=20=EC=82=AC=EB=8B=A4=EB=A6=AC?= =?UTF-8?q?=EC=9D=98=20=EC=B6=9C=EB=A0=A5=20=EB=AC=B8=EC=9E=90=EC=97=B4?= =?UTF-8?q?=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ladder/view/LadderMessageGenerator.java | 41 ++++++++++++++ .../view/LadderMessageGeneratorTest.java | 55 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/main/java/ladder/view/LadderMessageGenerator.java create mode 100644 src/test/java/ladder/view/LadderMessageGeneratorTest.java diff --git a/src/main/java/ladder/view/LadderMessageGenerator.java b/src/main/java/ladder/view/LadderMessageGenerator.java new file mode 100644 index 0000000000..dcc428bfbf --- /dev/null +++ b/src/main/java/ladder/view/LadderMessageGenerator.java @@ -0,0 +1,41 @@ +package ladder.view; + +import static java.util.stream.Collectors.joining; + +import java.util.List; +import ladder.domain.Line; +import ladder.domain.LineStatus; + +class LadderMessageGenerator { + + private static final String NEXT_LINE = System.lineSeparator(); + private static final String CONNECTED_SYMBOL = "-"; + private static final String DISCONNECTED_SYMBOL = " "; + private static final String EMPTY_SYMBOL = " "; + private static final String LINE_STATUS_MESSAGE_FORMAT = "%s|"; + + public static String generate(final int maxNameLength, final List lines) { + return lines.stream() + .map(line -> generateLineMessage(maxNameLength, line)) + .collect(joining(NEXT_LINE)); + } + + private static String generateLineMessage(final int maxNameLength, final Line line) { + final String initialMessage = generateRepeatedLineStatusMessage(EMPTY_SYMBOL, maxNameLength); + final String ladderMessage = line.getLine().stream() + .map(lineStatus -> generateLineStatusMessage(maxNameLength, lineStatus)) + .collect(joining()); + return initialMessage + ladderMessage; + } + + private static String generateRepeatedLineStatusMessage(final String symbol, final int count) { + return String.format(LINE_STATUS_MESSAGE_FORMAT, symbol.repeat(count)); + } + + private static String generateLineStatusMessage(final int maxNameLength, final LineStatus lineStatus) { + if (lineStatus.isConnected()) { + return generateRepeatedLineStatusMessage(CONNECTED_SYMBOL, maxNameLength); + } + return generateRepeatedLineStatusMessage(DISCONNECTED_SYMBOL, maxNameLength); + } +} diff --git a/src/test/java/ladder/view/LadderMessageGeneratorTest.java b/src/test/java/ladder/view/LadderMessageGeneratorTest.java new file mode 100644 index 0000000000..0b248ac13a --- /dev/null +++ b/src/test/java/ladder/view/LadderMessageGeneratorTest.java @@ -0,0 +1,55 @@ +package ladder.view; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import ladder.domain.BooleanGenerator; +import ladder.domain.Ladder; +import ladder.util.TestBooleanGenerator; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class LadderMessageGeneratorTest { + + private static final String NEXT_LINE = System.lineSeparator(); + + @Test + void 사다리_출력_문자열을_생성한다() { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( + false, false, true, + false, true, false, + true, false, true + )); + final Ladder ladder = Ladder.generate(booleanGenerator, 3, 3); + + final String result = LadderMessageGenerator.generate(3, ladder.getLines()); + + assertThat(result).isEqualTo( + " | | |---|" + NEXT_LINE + + " | |---| |" + NEXT_LINE + + " |---| |---|" + ); + } + + @Test + void 사다리_가로라인의_출력_문자열은_참가자이름과_결과의이름에_따라_변경된다() { + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( + false, false, true, + false, true, false, + true, false, true + )); + final Ladder ladder = Ladder.generate(booleanGenerator, 3, 3); + + final String result = LadderMessageGenerator.generate(1, ladder.getLines()); + + assertThat(result).isEqualTo( + " | | |-|" + NEXT_LINE + + " | |-| |" + NEXT_LINE + + " |-| |-|" + ); + } + +} From 758df5abeb6f7c5475ee02ff9d83e7c4b9e7487b Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 16:39:23 +0900 Subject: [PATCH 35/71] =?UTF-8?q?feat:=20=EC=8B=A4=ED=96=89=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++-- .../controller/LadderGameController.java | 3 +- src/main/java/ladder/domain/LadderGame.java | 4 ++ src/main/java/ladder/view/OutputView.java | 64 ++++--------------- .../java/ladder/domain/LadderGameTest.java | 12 ++++ 5 files changed, 36 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 47e3937902..470acc816a 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,14 @@ graph TD LadderGame --> Players LadderGame --> Items - Player --> Name - Player --> Position - Item --> Position - Item --> Name + Ladder --> Line + Line --> LineStatus + LadderGame --> Position + Ladder --> Position + Items --> Position Line --> Position + Players --> Position LadderGame --> LadderGameResult @@ -31,8 +33,6 @@ graph TD LadderGameController --> InputView LadderGameController --> OutputView - Ladder --> Line - Line --> LineStatus ``` ### 참가자 diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 1f9421b888..3dd8a6d9f2 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -29,8 +29,9 @@ public void run() { final LadderGame ladderGame = initialize(); final List players = ladderGame.getPlayers(); final List ladder = ladderGame.getLadder(); + final List items = ladderGame.getItems(); - outputView.printResult(players, ladder); + outputView.printLadderResult(players, ladder, items); } private LadderGame initialize() { diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index 2bc73b6c0f..a8ef756a68 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -43,4 +43,8 @@ public List getPlayers() { public List getLadder() { return ladder.getLines(); } + + public List getItems() { + return items.getNames(); + } } diff --git a/src/main/java/ladder/view/OutputView.java b/src/main/java/ladder/view/OutputView.java index abe291cf89..bf03308f4f 100644 --- a/src/main/java/ladder/view/OutputView.java +++ b/src/main/java/ladder/view/OutputView.java @@ -2,52 +2,37 @@ import static java.util.stream.Collectors.joining; +import java.util.Collection; import java.util.List; import ladder.domain.Line; -import ladder.domain.LineStatus; public class OutputView { - private static final int INITIAL_PLAYER_INDEX = 0; private static final int EMPTY_NAME_LENGTH = 0; - private static final long SKIP_INITIAL_PLAYER = 1L; private static final String NEXT_LINE = System.lineSeparator(); - private static final String GAME_RESULT_MESSAGE = NEXT_LINE + "실행결과" + NEXT_LINE; - private static final String CONNECTED_SYMBOL = "-"; - private static final String DISCONNECTED_SYMBOL = " "; - private static final String EMPTY_SYMBOL = " "; - private static final String INITIAL_NAME_MESSAGE_FORMAT = "%s "; + private static final String GAME_RESULT_MESSAGE = NEXT_LINE + "사다리결과" + NEXT_LINE; private static final String NAME_MESSAGE_FORMAT = " %%%ds"; - private static final String LINE_STATUS_MESSAGE_FORMAT = "%s|"; private static final String ERROR_MESSAGE = "[ERROR] "; - public void printResult(final List playerNames, final List ladder) { + public void printLadderResult(final List players, final List ladder, final List items) { System.out.println(GAME_RESULT_MESSAGE); - - final int maxNameLength = calculateMaxNameLength(playerNames); - System.out.println(generateNameMessages(playerNames, maxNameLength)); - - final String initialPlayerName = getInitialPlayerName(playerNames); - System.out.println(generateLadderMessage(initialPlayerName.length(), maxNameLength, ladder)); + final int maxNameLength = calculateMaxNameLength(List.of(players, items)); + System.out.println(generateNameMessages(players, maxNameLength)); + System.out.println(LadderMessageGenerator.generate(maxNameLength, ladder)); + System.out.println(generateNameMessages(items, maxNameLength)); } - private int calculateMaxNameLength(final List playerNames) { - return playerNames.stream() + private int calculateMaxNameLength(final List> names) { + return names.stream() + .flatMap(Collection::stream) .map(String::length) .max(Integer::compareTo) .orElse(EMPTY_NAME_LENGTH); } - private String generateNameMessages(final List playerNames, final int maxNameLength) { - final String initialNameMessage = String.format(INITIAL_NAME_MESSAGE_FORMAT, getInitialPlayerName(playerNames)); - final String playerNameMessages = playerNames.stream() - .skip(SKIP_INITIAL_PLAYER) + private String generateNameMessages(final List names, final int maxNameLength) { + return names.stream() .map(name -> generateNameMessage(name, maxNameLength)) .collect(joining()); - return initialNameMessage + playerNameMessages; - } - - private String getInitialPlayerName(final List playerNames) { - return playerNames.get(INITIAL_PLAYER_INDEX); } private String generateNameMessage(final String name, int maxNameLength) { @@ -55,31 +40,6 @@ private String generateNameMessage(final String name, int maxNameLength) { return String.format(nameSizeFormat, name); } - private String generateLadderMessage(final int initialNameLength, final int maxNameLength, final List lines) { - return lines.stream() - .map(line -> generateLineMessage(initialNameLength, maxNameLength, line)) - .collect(joining(NEXT_LINE)); - } - - private String generateLineMessage(final int initialNameLength, final int maxNameLength, final Line line) { - final String initialMessage = generateRepeatedLineStatusMessage(EMPTY_SYMBOL, initialNameLength); - final String ladderMessage = line.getLine().stream() - .map(lineStatus -> generateLineStatusMessage(maxNameLength, lineStatus)) - .collect(joining()); - return initialMessage + ladderMessage; - } - - private String generateRepeatedLineStatusMessage(final String symbol, final int count) { - return String.format(LINE_STATUS_MESSAGE_FORMAT, symbol.repeat(count)); - } - - private String generateLineStatusMessage(final int maxNameLength, final LineStatus lineStatus) { - if (lineStatus.isConnected()) { - return generateRepeatedLineStatusMessage(CONNECTED_SYMBOL, maxNameLength); - } - return generateRepeatedLineStatusMessage(DISCONNECTED_SYMBOL, maxNameLength); - } - public void printError(final String message) { System.out.println(ERROR_MESSAGE + message); } diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index 40bb441c44..ac9a98f9a0 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -55,6 +55,18 @@ private LadderGame initializeLadderGame( ); } + @Test + void 모든_실행결과를_반환한다() { + final LadderGame ladderGame = initializeLadderGame( + List.of("name1", "name2"), + List.of(true, true), + 2, + List.of("item1", "item2") + ); + + assertThat(ladderGame.getItems()).containsExactly("item1", "item2"); + } + @Test void 모든_참가자에_대한_사다리게임을_진행한다() { final LadderGame ladderGame = initializeLadderGame( From e86667828b02b9fc987633ec5a8fcb9d3e550d0c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Thu, 23 Feb 2023 23:47:10 +0900 Subject: [PATCH 36/71] =?UTF-8?q?feat:=20=EC=82=AC=EB=8B=A4=EB=A6=AC?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../controller/LadderGameController.java | 69 ++++++++++++------- .../java/ladder/domain/LadderGameResult.java | 10 +-- src/main/java/ladder/view/InputView.java | 9 ++- src/main/java/ladder/view/OutputView.java | 38 +++++++++- 5 files changed, 97 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 470acc816a..e5d168b86e 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,11 @@ graph TD - [x] 결과명의 앞뒤 공백을 제거한다. - [x] 최대 사다리 높이를 입력받는다. - [x] 1보다 작은 값을 입력 받거나, 100보다 큰 값을 입력받는 경우 예외를 던진다. -- [ ] 실행결과를 보고 싶은 참가자명을 입력받는다. +- [x] 실행결과를 보고 싶은 참가자명을 입력받는다. ### 출력 - [x] 가장 긴 사람 이름을 기준으로 사다리 폭이 넓어진다. 예) 가장 긴 사람이름 5, 사다리 폭 5 -- [ ] 실행 결과를 이용하여 해당 참가자에 대한 결과를 출력한다. +- [x] 실행 결과를 이용하여 해당 참가자에 대한 결과를 출력한다. diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 3dd8a6d9f2..d1234e7535 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -1,9 +1,12 @@ package ladder.controller; import java.util.List; +import java.util.Map; +import java.util.function.Supplier; import ladder.domain.BooleanGenerator; import ladder.domain.Items; import ladder.domain.LadderGame; +import ladder.domain.LadderGameResult; import ladder.domain.Line; import ladder.domain.Players; import ladder.view.InputView; @@ -27,45 +30,65 @@ public LadderGameController( public void run() { final LadderGame ladderGame = initialize(); - final List players = ladderGame.getPlayers(); - final List ladder = ladderGame.getLadder(); - final List items = ladderGame.getItems(); - - outputView.printLadderResult(players, ladder, items); + printLadderResult(ladderGame); + final LadderGameResult ladderGameResult = ladderGame.play(); + printLadderGameResult(ladderGameResult); } private LadderGame initialize() { - final Players players = readPlayers(); - final int height = readHeight(); - final Items items = readItems(players.count()); + final Players players = repeatUntilGetValidInput(() -> Players.from(inputView.readPlayerNames())); + final Items items = repeatUntilGetValidInput(() -> Items.from(inputView.readItemNames(), players.count())); + final int height = repeatUntilGetValidInput(inputView::readLadderHeight); return LadderGame.initialize(players, booleanGenerator, height, items); } - private Players readPlayers() { + private T repeatUntilGetValidInput(Supplier inputReader) { try { - return Players.from(inputView.readPlayerNames()); + return inputReader.get(); } catch (IllegalArgumentException e) { outputView.printError(e.getMessage()); - return readPlayers(); + return repeatUntilGetValidInput(inputReader); } } - private int readHeight() { - try { - return inputView.readLadderHeight(); - } catch (IllegalArgumentException e) { - outputView.printError(e.getMessage()); - return readHeight(); + private void printLadderResult(final LadderGame ladderGame) { + final List players = ladderGame.getPlayers(); + final List ladder = ladderGame.getLadder(); + final List items = ladderGame.getItems(); + + outputView.printLadderResult(players, ladder, items); + } + + private void printLadderGameResult(final LadderGameResult ladderGameResult) { + LadderGameCommand command = LadderGameCommand.SINGLE; + while (command.isContinued()) { + final Map result = repeatUntilGetValidInput(() -> getLadderGameResult(ladderGameResult)); + command = LadderGameCommand.from(result.size()); + outputView.printLadderGameResult(result); } } - private Items readItems(final int playerCount) { - try { - return Items.from(inputView.readItemNames(), playerCount); - } catch (IllegalArgumentException e) { - outputView.printError(e.getMessage()); - return readItems(playerCount); + private Map getLadderGameResult(final LadderGameResult ladderGameResult) { + final String name = inputView.readPlayerName(); + return ladderGameResult.get(name); + } + + enum LadderGameCommand { + ALL, + SINGLE; + + private static final int SINGLE_RESULT_SIZE = 1; + + public static LadderGameCommand from(final int size) { + if (size == SINGLE_RESULT_SIZE) { + return SINGLE; + } + return ALL; + } + + public boolean isContinued() { + return this == SINGLE; } } } diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 3fab6923ba..ba99f5e8a7 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -3,7 +3,7 @@ import java.util.LinkedHashMap; import java.util.Map; -class LadderGameResult { +public class LadderGameResult { private static final String PRINT_ALL = "all"; private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; @@ -16,12 +16,12 @@ public LadderGameResult(final Map result) { public Map get(final String name) { if (name.equals(PRINT_ALL)) { - return getAll(); + return getMultipleResult(); } - return getSingle(name); + return getSingleResult(name); } - private Map getAll() { + private Map getMultipleResult() { final Map playerToItem = new LinkedHashMap<>(); for (Player player : result.keySet()) { playerToItem.put(player.getName(), getItemName(player)); @@ -33,7 +33,7 @@ private String getItemName(final Player player) { return result.get(player).getName(); } - private Map getSingle(final String name) { + private Map getSingleResult(final String name) { final Player player = new Player(name); if (!result.containsKey(player)) { throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); diff --git a/src/main/java/ladder/view/InputView.java b/src/main/java/ladder/view/InputView.java index dc9c52fb65..79464555fd 100644 --- a/src/main/java/ladder/view/InputView.java +++ b/src/main/java/ladder/view/InputView.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; public class InputView { + private static final String NEXT_LINE = System.lineSeparator(); private static final String READ_PLAYER_NAMES_MESSAGE = "참여할 사람 이름을 입력하세요. (이름은 쉼표(,)로 구분하세요)"; private static final String DELIMITER = ","; private static final int SPLIT_LIMIT = -1; @@ -16,6 +17,7 @@ public class InputView { private static final String INVALID_NUMBER_MESSAGE = LADDER_HEIGHT_UPPER_BOUND + " 이하의 정수만 입력 가능합니다."; private static final String INVALID_HEIGHT_MESSAGE = "높이는 최소 " + LADDER_HEIGHT_LOWER_BOUND + "이상, " + LADDER_HEIGHT_UPPER_BOUND + "이하여야 합니다."; + private static final String READ_PLAYER_NAME_MESSAGE = NEXT_LINE + "결과를 보고 싶은 사람은? [all 입력시 전체 결과 출력 후 종료]"; private final Scanner scanner; @@ -30,7 +32,7 @@ public List readPlayerNames() { return splitCsvInput(input); } - public List splitCsvInput(String input) { + private List splitCsvInput(String input) { return Arrays.stream(input.split(DELIMITER, SPLIT_LIMIT)) .map(String::trim) .collect(Collectors.toList()); @@ -70,4 +72,9 @@ private void validateHeight(final int height) { private boolean isInvalidHeight(final int height) { return height < LADDER_HEIGHT_LOWER_BOUND || LADDER_HEIGHT_UPPER_BOUND < height; } + + public String readPlayerName() { + System.out.println(READ_PLAYER_NAME_MESSAGE); + return scanner.nextLine(); + } } diff --git a/src/main/java/ladder/view/OutputView.java b/src/main/java/ladder/view/OutputView.java index bf03308f4f..2ee071fce4 100644 --- a/src/main/java/ladder/view/OutputView.java +++ b/src/main/java/ladder/view/OutputView.java @@ -4,17 +4,22 @@ import java.util.Collection; import java.util.List; +import java.util.Map; import ladder.domain.Line; public class OutputView { private static final int EMPTY_NAME_LENGTH = 0; private static final String NEXT_LINE = System.lineSeparator(); - private static final String GAME_RESULT_MESSAGE = NEXT_LINE + "사다리결과" + NEXT_LINE; + private static final String LADDER_RESULT_MESSAGE = NEXT_LINE + "사다리결과" + NEXT_LINE; private static final String NAME_MESSAGE_FORMAT = " %%%ds"; private static final String ERROR_MESSAGE = "[ERROR] "; + private static final int SINGLE_GAME_RESULT_SIZE = 1; + private static final String SINGLE_RESULT_MESSAGE_FORMAT = "%s"; + private static final String LADDER_GAME_RESULT_MESSAGE = NEXT_LINE + "실행 결과"; + private static final String LADDER_GAME_RESULT_MESSAGE_FORMAT = "%s : %s"; public void printLadderResult(final List players, final List ladder, final List items) { - System.out.println(GAME_RESULT_MESSAGE); + System.out.println(LADDER_RESULT_MESSAGE); final int maxNameLength = calculateMaxNameLength(List.of(players, items)); System.out.println(generateNameMessages(players, maxNameLength)); System.out.println(LadderMessageGenerator.generate(maxNameLength, ladder)); @@ -40,6 +45,35 @@ private String generateNameMessage(final String name, int maxNameLength) { return String.format(nameSizeFormat, name); } + public void printLadderGameResult(final Map result) { + System.out.println(LADDER_GAME_RESULT_MESSAGE); + System.out.println(generateLadderGameResultMessage(result)); + } + + private String generateLadderGameResultMessage(final Map result) { + if (isSingleLadderGameResult(result)) { + return generateSingleLadderGameResultMessage(result); + } + return generateMultipleLadderGameResultMessage(result); + } + + private boolean isSingleLadderGameResult(final Map result) { + return result.size() == SINGLE_GAME_RESULT_SIZE; + } + + private String generateSingleLadderGameResultMessage(final Map result) { + final String itemName = result.values().stream() + .findAny() + .orElse(NEXT_LINE); + return String.format(SINGLE_RESULT_MESSAGE_FORMAT, itemName); + } + + private String generateMultipleLadderGameResultMessage(final Map result) { + return result.keySet().stream() + .map(player -> String.format(LADDER_GAME_RESULT_MESSAGE_FORMAT, player, result.get(player))) + .collect(joining(NEXT_LINE)); + } + public void printError(final String message) { System.out.println(ERROR_MESSAGE + message); } From 39e192c20b6bcf5bb878d6ae87a73f0be3800896 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 08:16:51 +0900 Subject: [PATCH 37/71] =?UTF-8?q?refactor:=20=EB=AC=B8=EC=9E=90=EC=97=B4?= =?UTF-8?q?=20=EB=B9=84=EA=B5=90=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/LadderGameResult.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index ba99f5e8a7..2e0cdf39a9 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -5,7 +5,7 @@ public class LadderGameResult { - private static final String PRINT_ALL = "all"; + private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; private final Map result; @@ -15,7 +15,7 @@ public LadderGameResult(final Map result) { } public Map get(final String name) { - if (name.equals(PRINT_ALL)) { + if (MULTIPLE_RESULT_RESERVED_NAME.equals(name)) { return getMultipleResult(); } return getSingleResult(name); From 20d6371244351d791d3b5b6b028a1decdda75628 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 09:02:27 +0900 Subject: [PATCH 38/71] =?UTF-8?q?style:=20equals=EB=9E=91=20getter=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 42d8d699d0..fb3b90f3b9 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -41,10 +41,6 @@ private boolean isReservedName(final String name) { return name.equals(RESERVED_NAME); } - public String getName() { - return name; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -61,4 +57,8 @@ public boolean equals(final Object o) { public int hashCode() { return Objects.hash(name); } + + public String getName() { + return name; + } } From bcc9c073f93e9780b32b7250c0e9796881db54d4 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 09:03:10 +0900 Subject: [PATCH 39/71] =?UTF-8?q?feat:=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20?= =?UTF-8?q?=EB=86=92=EC=9D=B4=20=EC=9B=90=EC=8B=9C=EA=B0=92=20=ED=8F=AC?= =?UTF-8?q?=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LadderGameController.java | 3 +- src/main/java/ladder/domain/Height.java | 42 +++++++++++++++++++ src/main/java/ladder/domain/LadderGame.java | 5 ++- src/main/java/ladder/view/InputView.java | 32 +------------- src/test/java/ladder/domain/HeightTest.java | 26 ++++++++++++ .../java/ladder/domain/LadderGameTest.java | 3 +- 6 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 src/main/java/ladder/domain/Height.java create mode 100644 src/test/java/ladder/domain/HeightTest.java diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index d1234e7535..8e0169a4bd 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.function.Supplier; import ladder.domain.BooleanGenerator; +import ladder.domain.Height; import ladder.domain.Items; import ladder.domain.LadderGame; import ladder.domain.LadderGameResult; @@ -38,7 +39,7 @@ public void run() { private LadderGame initialize() { final Players players = repeatUntilGetValidInput(() -> Players.from(inputView.readPlayerNames())); final Items items = repeatUntilGetValidInput(() -> Items.from(inputView.readItemNames(), players.count())); - final int height = repeatUntilGetValidInput(inputView::readLadderHeight); + final Height height = repeatUntilGetValidInput(() -> new Height(inputView.readLadderHeight())); return LadderGame.initialize(players, booleanGenerator, height, items); } diff --git a/src/main/java/ladder/domain/Height.java b/src/main/java/ladder/domain/Height.java new file mode 100644 index 0000000000..fca243afa8 --- /dev/null +++ b/src/main/java/ladder/domain/Height.java @@ -0,0 +1,42 @@ +package ladder.domain; + +public class Height { + + private static final int HEIGHT_LOWER_BOUND = 1; + private static final int HEIGHT_UPPER_BOUND = 100; + private static final String INVALID_HEIGHT_MESSAGE = + "높이는 " + HEIGHT_LOWER_BOUND + "이상, " + HEIGHT_UPPER_BOUND + "이하의 값이어야 합니다."; + + private final int value; + + public Height(final String value) { + this(parseInt(value)); + } + + private Height(final int value) { + validate(value); + this.value = value; + } + + private static int parseInt(final String value) { + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(INVALID_HEIGHT_MESSAGE); + } + } + + private static void validate(final int value) { + if (isInvalidHeight(value)) { + throw new IllegalArgumentException(INVALID_HEIGHT_MESSAGE); + } + } + + private static boolean isInvalidHeight(final int value) { + return value < HEIGHT_LOWER_BOUND || HEIGHT_UPPER_BOUND < value; + } + + public int getValue() { + return value; + } +} diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index a8ef756a68..f63b919cf3 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -20,10 +20,11 @@ private LadderGame(final Players players, final Ladder ladder, final Items items public static LadderGame initialize( final Players players, final BooleanGenerator booleanGenerator, - final int height, + final Height height, final Items items ) { - final Ladder ladder = Ladder.generate(booleanGenerator, height, players.count() - SUBTRACT_LADDER_WIDTH_VALUE); + final int ladderWidth = players.count() - SUBTRACT_LADDER_WIDTH_VALUE; + final Ladder ladder = Ladder.generate(booleanGenerator, height.getValue(), ladderWidth); return new LadderGame(players, ladder, items); } diff --git a/src/main/java/ladder/view/InputView.java b/src/main/java/ladder/view/InputView.java index 79464555fd..f57cfd9986 100644 --- a/src/main/java/ladder/view/InputView.java +++ b/src/main/java/ladder/view/InputView.java @@ -12,11 +12,6 @@ public class InputView { private static final int SPLIT_LIMIT = -1; private static final String READ_ITEM_NAMES_MESSAGE = "실행 결과를 입력하세요. (결과는 쉼표(,)로 구분하세요)"; private static final String READ_LADDER_HEIGHT_MESSAGE = "최대 사다리 높이는 몇 개인가요?"; - private static final int LADDER_HEIGHT_LOWER_BOUND = 1; - private static final int LADDER_HEIGHT_UPPER_BOUND = 100; - private static final String INVALID_NUMBER_MESSAGE = LADDER_HEIGHT_UPPER_BOUND + " 이하의 정수만 입력 가능합니다."; - private static final String INVALID_HEIGHT_MESSAGE = - "높이는 최소 " + LADDER_HEIGHT_LOWER_BOUND + "이상, " + LADDER_HEIGHT_UPPER_BOUND + "이하여야 합니다."; private static final String READ_PLAYER_NAME_MESSAGE = NEXT_LINE + "결과를 보고 싶은 사람은? [all 입력시 전체 결과 출력 후 종료]"; private final Scanner scanner; @@ -45,32 +40,9 @@ public List readItemNames() { return splitCsvInput(input); } - public int readLadderHeight() { + public String readLadderHeight() { System.out.println(READ_LADDER_HEIGHT_MESSAGE); - final String input = scanner.nextLine(); - - final int height = parseInt(input); - validateHeight(height); - - return height; - } - - private int parseInt(final String input) { - try { - return Integer.parseInt(input); - } catch (NumberFormatException e) { - throw new IllegalArgumentException(INVALID_NUMBER_MESSAGE); - } - } - - private void validateHeight(final int height) { - if (isInvalidHeight(height)) { - throw new IllegalArgumentException(INVALID_HEIGHT_MESSAGE); - } - } - - private boolean isInvalidHeight(final int height) { - return height < LADDER_HEIGHT_LOWER_BOUND || LADDER_HEIGHT_UPPER_BOUND < height; + return scanner.nextLine(); } public String readPlayerName() { diff --git a/src/test/java/ladder/domain/HeightTest.java b/src/test/java/ladder/domain/HeightTest.java new file mode 100644 index 0000000000..70c2942cd2 --- /dev/null +++ b/src/test/java/ladder/domain/HeightTest.java @@ -0,0 +1,26 @@ +package ladder.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class HeightTest { + + @ParameterizedTest(name = "높이는 1이상, 100이하의 값이 아닌 경우 예외를 던진다. 입력값: \"{0}\"") + @ValueSource(strings = {"0", "-1", "101", "!", "백"}) + void 높이는_올바른_입력값이_아니라면_예외를_던진다(final String value) { + assertThatThrownBy(() -> new Height(value)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("높이는 1이상, 100이하의 값이어야 합니다."); + } + + @ParameterizedTest(name = "높이가 정상적으로 생성된다. 입력값: {0}") + @ValueSource(strings = {"1", "100"}) + void 높이가_정상적으로_생성된다(final String value) { + final Height height = new Height(value); + + assertThat(height.getValue()).isEqualTo(Integer.parseInt(value)); + } +} diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index ac9a98f9a0..827210aabd 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -16,11 +16,12 @@ public class LadderGameTest { private LadderGame initializeLadderGame( final List playerNames, final List ladder, - final int height, + final int value, final List itemNames ) { final Players players = Players.from(playerNames); final BooleanGenerator booleanGenerator = new TestBooleanGenerator(ladder); + final Height height = new Height(String.valueOf(value)); final Items items = Items.from(itemNames, players.count()); return LadderGame.initialize(players, booleanGenerator, height, items); From 74e5f7195305ad94dbd11ab5772624423752aa12 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 10:49:31 +0900 Subject: [PATCH 40/71] =?UTF-8?q?style:=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Height.java | 1 - src/main/java/ladder/domain/LadderGameResult.java | 1 - src/main/java/ladder/domain/Position.java | 1 - 3 files changed, 3 deletions(-) diff --git a/src/main/java/ladder/domain/Height.java b/src/main/java/ladder/domain/Height.java index fca243afa8..7d0ecc5d0a 100644 --- a/src/main/java/ladder/domain/Height.java +++ b/src/main/java/ladder/domain/Height.java @@ -1,7 +1,6 @@ package ladder.domain; public class Height { - private static final int HEIGHT_LOWER_BOUND = 1; private static final int HEIGHT_UPPER_BOUND = 100; private static final String INVALID_HEIGHT_MESSAGE = diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 2e0cdf39a9..b518789484 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -4,7 +4,6 @@ import java.util.Map; public class LadderGameResult { - private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index f9d653f361..c61ddec1da 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -7,7 +7,6 @@ import java.util.stream.IntStream; public class Position { - private static final int POSITION_VALUE_LOWER_BOUND = 0; private static final int POSITION_VALUE_UPPER_BOUND = 20; private static final int MOVE_COUNT = 1; From 2dfe9908c50a09a00838832a7e29496cc840ce01 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 11:12:42 +0900 Subject: [PATCH 41/71] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EC=9B=90=EC=8B=9C?= =?UTF-8?q?=EA=B0=92=20=ED=8F=AC=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 38 +---------- src/main/java/ladder/domain/PlayerName.java | 64 +++++++++++++++++++ .../java/ladder/domain/PlayerNameTest.java | 40 ++++++++++++ src/test/java/ladder/domain/PlayerTest.java | 22 +------ 4 files changed, 108 insertions(+), 56 deletions(-) create mode 100644 src/main/java/ladder/domain/PlayerName.java create mode 100644 src/test/java/ladder/domain/PlayerNameTest.java diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index fb3b90f3b9..ebba7888d9 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -3,42 +3,10 @@ import java.util.Objects; public class Player { - private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = - "참가자의 이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - private static final String RESERVED_NAME = "all"; - private static final String RESERVED_NAME_MESSAGE = "all은 사용할 수 없는 이름입니다."; - - private final String name; + private final PlayerName name; public Player(final String name) { - validate(name); - this.name = name; - } - - private void validate(final String name) { - validateInvalidNameLength(name); - validateReservedName(name); - } - - private void validateInvalidNameLength(final String name) { - if (isInvalidNameLength(name)) { - throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); - } - } - - private boolean isInvalidNameLength(final String name) { - return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); - } - - private void validateReservedName(final String name) { - if (isReservedName(name)) { - throw new IllegalArgumentException(RESERVED_NAME_MESSAGE); - } - } - - private boolean isReservedName(final String name) { - return name.equals(RESERVED_NAME); + this.name = new PlayerName(name); } @Override @@ -59,6 +27,6 @@ public int hashCode() { } public String getName() { - return name; + return name.getValue(); } } diff --git a/src/main/java/ladder/domain/PlayerName.java b/src/main/java/ladder/domain/PlayerName.java new file mode 100644 index 0000000000..4b00aca18e --- /dev/null +++ b/src/main/java/ladder/domain/PlayerName.java @@ -0,0 +1,64 @@ +package ladder.domain; + +import java.util.Objects; + +class PlayerName { + private static final int NAME_LENGTH_UPPER_BOUND = 5; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + private static final String RESERVED_NAME = "all"; + private static final String RESERVED_NAME_MESSAGE = "all은 사용할 수 없는 이름입니다."; + + private final String value; + + public PlayerName(final String name) { + validate(name); + this.value = name; + } + + private void validate(final String name) { + validateInvalidNameLength(name); + validateReservedName(name); + } + + private void validateInvalidNameLength(final String name) { + if (isInvalidNameLength(name)) { + throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); + } + } + + private boolean isInvalidNameLength(final String name) { + return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + } + + private void validateReservedName(final String name) { + if (isReservedName(name)) { + throw new IllegalArgumentException(RESERVED_NAME_MESSAGE); + } + } + + private boolean isReservedName(final String name) { + return RESERVED_NAME.equals(name); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final PlayerName that = (PlayerName) o; + return Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(value); + } + + public String getValue() { + return value; + } +} diff --git a/src/test/java/ladder/domain/PlayerNameTest.java b/src/test/java/ladder/domain/PlayerNameTest.java new file mode 100644 index 0000000000..9d896dbda2 --- /dev/null +++ b/src/test/java/ladder/domain/PlayerNameTest.java @@ -0,0 +1,40 @@ +package ladder.domain; + + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +public class PlayerNameTest { + + @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = {"우아한형제들"}) + void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + assertThatThrownBy(() -> new PlayerName(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("이름은 1자 이상, 5자 이하여야 합니다."); + } + + @Test + void 이름이_정상적으로_생성한다() { + final PlayerName name = new PlayerName("name"); + + assertThat(name.getValue()).isEqualTo("name"); + } + + @Test + void all을_이름으로_사용할_수_없다() { + assertThatThrownBy(() -> new Player("all")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("all은 사용할 수 없는 이름입니다."); + } +} diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 73278e2ae5..9a64d31ae3 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -1,39 +1,19 @@ package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.NullAndEmptySource; -import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class PlayerTest { @Test - void 참가자는_이름을_가진다() { + void 참가자가_정상적으로_생성된다() { final Player player = new Player("name"); assertThat(player.getName()).isEqualTo("name"); } - - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") - @NullAndEmptySource - @ValueSource(strings = {"우아한형제들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { - assertThatThrownBy(() -> new Player(name)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("참가자의 이름은 1자 이상, 5자 이하여야 합니다."); - } - - @Test - void all을_이름으로_사용할_수_없다() { - assertThatThrownBy(() -> new Player("all")) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("all은 사용할 수 없는 이름입니다."); - } } From 7cf5ae9c4a2a51d34b62f9425bbfac4f7e2f58ae Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 11:23:45 +0900 Subject: [PATCH 42/71] =?UTF-8?q?refactor:=20players=EA=B0=80=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 11 +++++++++++ src/main/java/ladder/domain/Players.java | 20 +++++++++----------- src/test/java/ladder/domain/PlayerTest.java | 9 ++++++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index ebba7888d9..3b38da615b 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -4,9 +4,16 @@ public class Player { private final PlayerName name; + private final Position position; + + public Player(final String name, final Position position) { + this.name = new PlayerName(name); + this.position = position; + } public Player(final String name) { this.name = new PlayerName(name); + this.position = Position.valueOf(0); } @Override @@ -29,4 +36,8 @@ public int hashCode() { public String getName() { return name.getValue(); } + + public Position getPosition() { + return position; + } } diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index a108b9eafa..dd281d3af8 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -3,10 +3,10 @@ import static java.util.stream.Collectors.toUnmodifiableList; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; @@ -15,19 +15,17 @@ public class Players { "참가자는 최소 " + PLAYERS_SIZE_LOWER_BOUND + "명, 최대 " + PLAYERS_SIZE_UPPER_BOUND + "명이어야 합니다."; private static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; - private final Map players; + private final List players; - private Players(final Map players) { + private Players(final List players) { this.players = players; } public static Players from(final List names) { validate(names); - final Map players = new LinkedHashMap<>(); - for (int index = 0; index < names.size(); index++) { - players.put(Position.valueOf(index), new Player(names.get(index))); - } - return new Players(players); + return IntStream.range(0, names.size()) + .mapToObj(index -> new Player(names.get(index), Position.valueOf(index))) + .collect(Collectors.collectingAndThen(Collectors.toList(), Players::new)); } private static void validate(final List names) { @@ -53,11 +51,11 @@ public int count() { } public Player get(final Position position) { - return players.get(position); + return players.get(position.getValue()); } public List getNames() { - return players.values().stream() + return players.stream() .map(Player::getName) .collect(toUnmodifiableList()); } diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 9a64d31ae3..cdf5184b27 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -12,8 +12,15 @@ public class PlayerTest { @Test void 참가자가_정상적으로_생성된다() { - final Player player = new Player("name"); + final Player player = new Player("name", Position.valueOf(0)); assertThat(player.getName()).isEqualTo("name"); } + + @Test + void 참가자는_위치를_가진다() { + final Player player = new Player("name", Position.valueOf(0)); + + assertThat(player.getPosition()).isEqualTo(Position.valueOf(0)); + } } From 7f6615957827ec438a7e29b0c4c3c412737f140e Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 11:42:39 +0900 Subject: [PATCH 43/71] =?UTF-8?q?feat:=20Item=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=9B=90=EC=8B=9C=EA=B0=92=20?= =?UTF-8?q?=ED=8F=AC=EC=9E=A5=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/ItemName.java | 28 +++++++++++++++++++ src/test/java/ladder/domain/ItemNameTest.java | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/ladder/domain/ItemName.java create mode 100644 src/test/java/ladder/domain/ItemNameTest.java diff --git a/src/main/java/ladder/domain/ItemName.java b/src/main/java/ladder/domain/ItemName.java new file mode 100644 index 0000000000..cbcedfb293 --- /dev/null +++ b/src/main/java/ladder/domain/ItemName.java @@ -0,0 +1,28 @@ +package ladder.domain; + +class ItemName { + private static final int NAME_LENGTH_UPPER_BOUND = 5; + private static final String INVALID_NAME_LENGTH_MESSAGE = + "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + + private final String value; + + public ItemName(final String name) { + validate(name); + this.value = name; + } + + private void validate(final String name) { + if (isInvalidNameLength(name)) { + throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); + } + } + + private boolean isInvalidNameLength(final String name) { + return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + } + + public String getValue() { + return value; + } +} diff --git a/src/test/java/ladder/domain/ItemNameTest.java b/src/test/java/ladder/domain/ItemNameTest.java new file mode 100644 index 0000000000..f7f0b7bfdd --- /dev/null +++ b/src/test/java/ladder/domain/ItemNameTest.java @@ -0,0 +1,28 @@ +package ladder.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; + +public class ItemNameTest { + + @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = {"우아한상품들"}) + void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + assertThatThrownBy(() -> new ItemName(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); + } + + @Test + void 실행결과는_이름을_가진다() { + final ItemName name = new ItemName("name"); + + assertThat(name.getValue()).isEqualTo("name"); + } +} From 1682d00279dadcf3ca1439a43fb5b9b859708b10 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 11:53:32 +0900 Subject: [PATCH 44/71] =?UTF-8?q?refactor:=20Item=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=9B=90=EC=8B=9C=EA=B0=92=20?= =?UTF-8?q?=ED=8F=AC=EC=9E=A5=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Item.java | 28 +++++++++------------ src/main/java/ladder/domain/Items.java | 26 ++++++++++--------- src/main/java/ladder/domain/LadderGame.java | 2 +- src/test/java/ladder/domain/ItemTest.java | 22 ++++++++-------- src/test/java/ladder/domain/ItemsTest.java | 12 ++++++++- 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java index c4bbaac74a..473814aeb2 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -1,28 +1,24 @@ package ladder.domain; class Item { - private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = - "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + private final ItemName name; + private final Position position; - private final String name; - - public Item(final String name) { - validate(name); - this.name = name; + public Item(final String name, final Position position) { + this.name = new ItemName(name); + this.position = position; } - private void validate(final String name) { - if (isInvalidNameLength(name)) { - throw new IllegalArgumentException(INVALID_NAME_LENGTH_MESSAGE); - } + public Item(final String name) { + this.name = new ItemName(name); + this.position = Position.valueOf(0); } - - private boolean isInvalidNameLength(final String name) { - return name == null || name.isBlank() || NAME_LENGTH_UPPER_BOUND < name.length(); + + public boolean isSamePosition(final Position position) { + return this.position == position; } public String getName() { - return name; + return name.getValue(); } } diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index b9f6bf2af6..b91870373d 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -2,26 +2,25 @@ import static java.util.stream.Collectors.toUnmodifiableList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class Items { private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; + private static final String INVALID_ITEM_MESSAGE = "해당 위치에 있는 아이템이 존재하지 않습니다."; - private final Map items; + private final List items; - private Items(final Map items) { + private Items(final List items) { this.items = items; } public static Items from(final List names, int playerCount) { validateItemCount(names, playerCount); - final Map items = new LinkedHashMap<>(); - for (int index = 0; index < names.size(); index++) { - items.put(Position.valueOf(index), new Item(names.get(index))); - } - return new Items(items); + return IntStream.range(0, names.size()) + .mapToObj(index -> new Item(names.get(index), Position.valueOf(index))) + .collect(Collectors.collectingAndThen(Collectors.toList(), Items::new)); } private static void validateItemCount(final List items, final int playerCount) { @@ -30,12 +29,15 @@ private static void validateItemCount(final List items, final int player } } - public Item get(final Position position) { - return items.get(position); + public Item findByPosition(final Position position) { + return items.stream() + .filter(item -> item.isSamePosition(position)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(INVALID_ITEM_MESSAGE)); } public List getNames() { - return items.values().stream() + return items.stream() .map(Item::getName) .collect(toUnmodifiableList()); } diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index f63b919cf3..0c90133cc7 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -32,7 +32,7 @@ public LadderGameResult play() { final Map result = new LinkedHashMap<>(); for (Position position : Position.range(players.count())) { final Position resultPosition = ladder.play(position); - result.put(players.get(position), items.get(resultPosition)); + result.put(players.get(position), items.findByPosition(resultPosition)); } return new LadderGameResult(result); } diff --git a/src/test/java/ladder/domain/ItemTest.java b/src/test/java/ladder/domain/ItemTest.java index 9502422c80..56e19cb0ce 100644 --- a/src/test/java/ladder/domain/ItemTest.java +++ b/src/test/java/ladder/domain/ItemTest.java @@ -1,32 +1,30 @@ package ladder.domain; +import static ladder.domain.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.NullAndEmptySource; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.CsvSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class ItemTest { @Test - void 실행결과는_이름을_가진다() { - final Item item = new Item("name"); + void 실행결과가_정상적으로_생성된다() { + final Item item = new Item("name", valueOf(0)); assertThat(item.getName()).isEqualTo("name"); } - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") - @NullAndEmptySource - @ValueSource(strings = {"우아한상품들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { - assertThatThrownBy(() -> new Item(name)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); + @ParameterizedTest(name = "입력받은 위치와 같은 위치인지 확인한다. 위치: {0}, 결과 {1}") + @CsvSource({"0,true", "1,false"}) + void 입력받은_위치와_같은_위치인지_확인한다(final int position, final boolean result) { + final Item item = new Item("item", valueOf(0)); + + assertThat(item.isSamePosition(valueOf(position))).isEqualTo(result); } } diff --git a/src/test/java/ladder/domain/ItemsTest.java b/src/test/java/ladder/domain/ItemsTest.java index c2a61cd33d..1f1a67a64f 100644 --- a/src/test/java/ladder/domain/ItemsTest.java +++ b/src/test/java/ladder/domain/ItemsTest.java @@ -1,5 +1,6 @@ package ladder.domain; +import static ladder.domain.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -19,11 +20,20 @@ public class ItemsTest { .hasMessage("참가인원과 동일한 개수의 실행결과를 입력해야 합니다."); } + @Test + void 입력받은_위치에_해당하는_실행결과가_없다면_예외를_던진다() { + final Items items = Items.from(List.of("item1", "item2", "item3"), 3); + + assertThatThrownBy(() -> items.findByPosition(valueOf(10))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("해당 위치에 있는 아이템이 존재하지 않습니다."); + } + @Test void 입력받은_위치에_해당하는_실행결과를_반환한다() { final Items items = Items.from(List.of("item1", "item2", "item3"), 3); - final Item item = items.get(Position.valueOf(1)); + final Item item = items.findByPosition(valueOf(1)); assertThat(item.getName()).isEqualTo("item2"); } From 346bbb0a3fd4da9dd19664e8fa3746ad0f52e4f9 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:01:42 +0900 Subject: [PATCH 45/71] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=9C=84=EC=B9=98=EC=99=80=20=EA=B0=99=EC=9D=80=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/LadderGame.java | 2 +- src/main/java/ladder/domain/Player.java | 8 ++++---- src/main/java/ladder/domain/Players.java | 8 ++++++-- src/test/java/ladder/domain/PlayerTest.java | 11 +++++++---- src/test/java/ladder/domain/PlayersTest.java | 4 ++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index 0c90133cc7..b52bb613d1 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -32,7 +32,7 @@ public LadderGameResult play() { final Map result = new LinkedHashMap<>(); for (Position position : Position.range(players.count())) { final Position resultPosition = ladder.play(position); - result.put(players.get(position), items.findByPosition(resultPosition)); + result.put(players.findByPosition(position), items.findByPosition(resultPosition)); } return new LadderGameResult(result); } diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 3b38da615b..d9c2d993df 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -16,6 +16,10 @@ public Player(final String name) { this.position = Position.valueOf(0); } + public boolean isSamePosition(final Position position) { + return this.position == position; + } + @Override public boolean equals(final Object o) { if (this == o) { @@ -36,8 +40,4 @@ public int hashCode() { public String getName() { return name.getValue(); } - - public Position getPosition() { - return position; - } } diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index dd281d3af8..a1ff135437 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -14,6 +14,7 @@ public class Players { private static final String INVALID_PLAYERS_SIZE_MESSAGE = "참가자는 최소 " + PLAYERS_SIZE_LOWER_BOUND + "명, 최대 " + PLAYERS_SIZE_UPPER_BOUND + "명이어야 합니다."; private static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; + private static final String INVALID_PLAYER_MESSAGE = "해당 위치에 있는 참가자가 존재하지 않습니다."; private final List players; @@ -50,8 +51,11 @@ public int count() { return players.size(); } - public Player get(final Position position) { - return players.get(position.getValue()); + public Player findByPosition(final Position position) { + return players.stream() + .filter(player -> player.isSamePosition(position)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(INVALID_PLAYER_MESSAGE)); } public List getNames() { diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index cdf5184b27..3260174d92 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -17,10 +19,11 @@ public class PlayerTest { assertThat(player.getName()).isEqualTo("name"); } - @Test - void 참가자는_위치를_가진다() { - final Player player = new Player("name", Position.valueOf(0)); + @ParameterizedTest(name = "입력받은 위치와 같은 위치인지 확인한다. 위치: {0}, 결과 {1}") + @CsvSource({"0,true", "1,false"}) + void 입력받은_위치와_같은_위치인지_확인한다(final int position, final boolean result) { + final Player player = new Player("item", Position.valueOf(0)); - assertThat(player.getPosition()).isEqualTo(Position.valueOf(0)); + assertThat(player.isSamePosition(Position.valueOf(position))).isEqualTo(result); } } diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index fd273e4f14..ca4b0ea1d7 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -53,9 +53,9 @@ public class PlayersTest { void 입력받은_위치에_해당하는_참가자를_반환한다() { final Players players = Players.from(List.of("name1", "name2")); - final Player result = players.get(Position.valueOf(0)); + final Player result = players.findByPosition(Position.valueOf(0)); - assertThat(result).isEqualTo(new Player("name1")); + assertThat(result.getName()).isEqualTo("name1"); } @Test From 9fab87d9cd24f54fdedcbcc60d687c19f9bf1d9a Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:05:25 +0900 Subject: [PATCH 46/71] =?UTF-8?q?feat:=20=EC=B0=B8=EA=B0=80=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EC=82=AC=EB=8B=A4=EB=A6=AC=EB=A5=BC=20=EB=B0=9B?= =?UTF-8?q?=EC=95=84=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20=ED=83=80=EA=B8=B0?= =?UTF-8?q?=EB=A5=BC=20=EC=A7=84=ED=96=89=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Player.java | 4 ++++ src/test/java/ladder/domain/PlayerTest.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index d9c2d993df..8b0d851af6 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -16,6 +16,10 @@ public Player(final String name) { this.position = Position.valueOf(0); } + public Position play(final Ladder ladder) { + return ladder.play(position); + } + public boolean isSamePosition(final Position position) { return this.position == position; } diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index 3260174d92..b3229c7c21 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -2,6 +2,8 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.util.List; +import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -26,4 +28,19 @@ public class PlayerTest { assertThat(player.isSamePosition(Position.valueOf(position))).isEqualTo(result); } + + @Test + void 참가자는_사다리를_받아_사다리타기를_진행한다() { + final Player player = new Player("item", Position.valueOf(0)); + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( + false, false, true, + false, true, false, + true, false, true + )); + final Ladder ladder = Ladder.generate(booleanGenerator, 3, 3); + + final Position result = player.play(ladder); + + assertThat(result).isEqualTo(Position.valueOf(1)); + } } From c492ff5f63cc4bcd963bd4260f79cc08e07473ce Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:13:00 +0900 Subject: [PATCH 47/71] =?UTF-8?q?feat:=20=EB=AA=A8=EB=93=A0=20=EC=B0=B8?= =?UTF-8?q?=EA=B0=80=EC=9E=90=EA=B0=80=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20?= =?UTF-8?q?=ED=83=80=EA=B8=B0=EB=A5=BC=20=EC=A7=84=ED=96=89=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Players.java | 14 ++++++++++-- src/test/java/ladder/domain/PlayersTest.java | 23 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index a1ff135437..194e055fd2 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -3,7 +3,9 @@ import static java.util.stream.Collectors.toUnmodifiableList; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -47,8 +49,12 @@ private static void validateDuplicateNames(final List names) { } } - public int count() { - return players.size(); + public Map play(final Ladder ladder) { + final Map result = new LinkedHashMap<>(); + for (Player player : players) { + result.put(player, player.play(ladder)); + } + return result; } public Player findByPosition(final Position position) { @@ -58,6 +64,10 @@ public Player findByPosition(final Position position) { .orElseThrow(() -> new IllegalArgumentException(INVALID_PLAYER_MESSAGE)); } + public int count() { + return players.size(); + } + public List getNames() { return players.stream() .map(Player::getName) diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index ca4b0ea1d7..7a68c78860 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -3,10 +3,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.entry; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; +import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -64,4 +67,24 @@ public class PlayersTest { assertThat(players.getNames()).containsExactly("name1", "name2"); } + + @Test + void 모든_참가자들의_사다리_게임을_진행한다() { + final Players players = Players.from(List.of("name1", "name2", "name3", "name4")); + final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( + false, false, true, + false, true, false, + true, false, true + )); + final Ladder ladder = Ladder.generate(booleanGenerator, 3, 3); + + final Map result = players.play(ladder); + + assertThat(result).containsExactly( + entry(players.findByPosition(Position.valueOf(0)), Position.valueOf(1)), + entry(players.findByPosition(Position.valueOf(1)), Position.valueOf(3)), + entry(players.findByPosition(Position.valueOf(2)), Position.valueOf(2)), + entry(players.findByPosition(Position.valueOf(3)), Position.valueOf(0)) + ); + } } From aaa3b86e756f05e57d97552f8f9051f4068f70cc Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:22:08 +0900 Subject: [PATCH 48/71] =?UTF-8?q?refactor:=20LadderGameResult=EC=9D=98=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Player, Item -> String, String --- .../java/ladder/domain/LadderGameResult.java | 20 +++++-------------- .../ladder/domain/LadderGameResultTest.java | 9 ++++----- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index b518789484..9700fddcae 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -7,9 +7,9 @@ public class LadderGameResult { private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; - private final Map result; + private final Map result; - public LadderGameResult(final Map result) { + public LadderGameResult(final Map result) { this.result = result; } @@ -21,23 +21,13 @@ public Map get(final String name) { } private Map getMultipleResult() { - final Map playerToItem = new LinkedHashMap<>(); - for (Player player : result.keySet()) { - playerToItem.put(player.getName(), getItemName(player)); - } - return playerToItem; - } - - private String getItemName(final Player player) { - return result.get(player).getName(); + return new LinkedHashMap<>(result); } private Map getSingleResult(final String name) { - final Player player = new Player(name); - if (!result.containsKey(player)) { + if (!result.containsKey(name)) { throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); } - final Item item = result.get(player); - return Map.of(player.getName(), item.getName()); + return Map.of(name, result.get(name)); } } diff --git a/src/test/java/ladder/domain/LadderGameResultTest.java b/src/test/java/ladder/domain/LadderGameResultTest.java index d834b6a5cf..077be44de7 100644 --- a/src/test/java/ladder/domain/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/LadderGameResultTest.java @@ -16,7 +16,7 @@ public class LadderGameResultTest { @Test void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name"), new Item("1000") + "name", "1000" )); assertThatThrownBy(() -> ladderGameResult.get("whois")) @@ -27,7 +27,7 @@ public class LadderGameResultTest { @Test void 한_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name"), new Item("1000") + "name", "1000" )); final Map result = ladderGameResult.get("name"); @@ -38,13 +38,12 @@ public class LadderGameResultTest { @Test void 모든_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name"), new Item("0"), - new Player("name2"), new Item("1000") + "name", "0", + "name2", "1000" )); final Map result = ladderGameResult.get("all"); assertThat(result).contains(entry("name", "0"), entry("name2", "1000")); } - } From dd5b2a08eb2768df37dfe72dc44cf9e0bfc39046 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:22:36 +0900 Subject: [PATCH 49/71] =?UTF-8?q?refactor:=20players=EC=97=90=20ladder?= =?UTF-8?q?=EB=A5=BC=20=EB=84=98=EA=B2=A8=EC=A3=BC=EB=8A=94=20=EB=B0=A9?= =?UTF-8?q?=EB=B2=95=EC=9C=BC=EB=A1=9C=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EC=A7=84=ED=96=89=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/LadderGame.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index b52bb613d1..fcc0988b21 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -29,14 +29,19 @@ public static LadderGame initialize( } public LadderGameResult play() { - final Map result = new LinkedHashMap<>(); - for (Position position : Position.range(players.count())) { - final Position resultPosition = ladder.play(position); - result.put(players.findByPosition(position), items.findByPosition(resultPosition)); + final Map playResult = players.play(ladder); + + final Map result = new LinkedHashMap<>(); + for (Player player : playResult.keySet()) { + result.put(player.getName(), toItemName(playResult.get(player))); } return new LadderGameResult(result); } + private String toItemName(final Position position) { + return items.findByPosition(position).getName(); + } + public List getPlayers() { return players.getNames(); } From 932fcec3b0e966ec125ba010fce35c45662c7480 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:28:31 +0900 Subject: [PATCH 50/71] =?UTF-8?q?remove:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Item.java | 5 ---- src/main/java/ladder/domain/Player.java | 24 ------------------- .../java/ladder/domain/PlayerNameTest.java | 2 +- 3 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/Item.java index 473814aeb2..7fa6ba63f1 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -9,11 +9,6 @@ public Item(final String name, final Position position) { this.position = position; } - public Item(final String name) { - this.name = new ItemName(name); - this.position = Position.valueOf(0); - } - public boolean isSamePosition(final Position position) { return this.position == position; } diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/Player.java index 8b0d851af6..5186e3d447 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -1,7 +1,5 @@ package ladder.domain; -import java.util.Objects; - public class Player { private final PlayerName name; private final Position position; @@ -11,11 +9,6 @@ public Player(final String name, final Position position) { this.position = position; } - public Player(final String name) { - this.name = new PlayerName(name); - this.position = Position.valueOf(0); - } - public Position play(final Ladder ladder) { return ladder.play(position); } @@ -24,23 +17,6 @@ public boolean isSamePosition(final Position position) { return this.position == position; } - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final Player player = (Player) o; - return Objects.equals(name, player.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - public String getName() { return name.getValue(); } diff --git a/src/test/java/ladder/domain/PlayerNameTest.java b/src/test/java/ladder/domain/PlayerNameTest.java index 9d896dbda2..c1b7b786aa 100644 --- a/src/test/java/ladder/domain/PlayerNameTest.java +++ b/src/test/java/ladder/domain/PlayerNameTest.java @@ -33,7 +33,7 @@ public class PlayerNameTest { @Test void all을_이름으로_사용할_수_없다() { - assertThatThrownBy(() -> new Player("all")) + assertThatThrownBy(() -> new PlayerName("all")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("all은 사용할 수 없는 이름입니다."); } From 908ed1a624dfc2491bd9012a6b956757b93d7bb8 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 12:36:04 +0900 Subject: [PATCH 51/71] =?UTF-8?q?style:=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/Application.java | 2 +- .../ladder/controller/LadderGameController.java | 14 +++++++------- src/main/java/ladder/domain/{ => item}/Item.java | 6 ++++-- .../java/ladder/domain/{ => item}/ItemName.java | 4 ++-- src/main/java/ladder/domain/{ => item}/Items.java | 3 ++- .../domain/{ => ladder}/BooleanGenerator.java | 2 +- .../java/ladder/domain/{ => ladder}/Height.java | 2 +- .../java/ladder/domain/{ => ladder}/Ladder.java | 2 +- .../ladder/domain/{ => ladder}/LadderGame.java | 5 ++++- .../domain/{ => ladder}/LadderGameResult.java | 2 +- src/main/java/ladder/domain/{ => ladder}/Line.java | 2 +- .../ladder/domain/{ => ladder}/LineStatus.java | 2 +- .../java/ladder/domain/{ => ladder}/Position.java | 2 +- .../{ => ladder}/RandomBooleanGenerator.java | 2 +- .../java/ladder/domain/{ => player}/Player.java | 5 ++++- .../ladder/domain/{ => player}/PlayerName.java | 4 ++-- .../java/ladder/domain/{ => player}/Players.java | 4 +++- .../java/ladder/view/LadderMessageGenerator.java | 4 ++-- src/main/java/ladder/view/OutputView.java | 2 +- .../ladder/domain/{ => item}/ItemNameTest.java | 2 +- .../java/ladder/domain/{ => item}/ItemTest.java | 4 ++-- .../java/ladder/domain/{ => item}/ItemsTest.java | 4 ++-- .../ladder/domain/{ => ladder}/HeightTest.java | 2 +- .../domain/{ => ladder}/LadderGameResultTest.java | 2 +- .../ladder/domain/{ => ladder}/LadderGameTest.java | 4 +++- .../ladder/domain/{ => ladder}/LadderTest.java | 6 +++--- .../ladder/domain/{ => ladder}/LineStatusTest.java | 2 +- .../java/ladder/domain/{ => ladder}/LineTest.java | 6 +++--- .../ladder/domain/{ => ladder}/PositionTest.java | 2 +- .../ladder/domain/{ => player}/PlayerNameTest.java | 2 +- .../ladder/domain/{ => player}/PlayerTest.java | 5 ++++- .../ladder/domain/{ => player}/PlayersTest.java | 5 ++++- .../java/ladder/util/TestBooleanGenerator.java | 2 +- .../ladder/view/LadderMessageGeneratorTest.java | 4 ++-- 34 files changed, 70 insertions(+), 51 deletions(-) rename src/main/java/ladder/domain/{ => item}/Item.java (81%) rename src/main/java/ladder/domain/{ => item}/ItemName.java (93%) rename src/main/java/ladder/domain/{ => item}/Items.java (95%) rename src/main/java/ladder/domain/{ => ladder}/BooleanGenerator.java (67%) rename src/main/java/ladder/domain/{ => ladder}/Height.java (97%) rename src/main/java/ladder/domain/{ => ladder}/Ladder.java (96%) rename src/main/java/ladder/domain/{ => ladder}/LadderGame.java (92%) rename src/main/java/ladder/domain/{ => ladder}/LadderGameResult.java (97%) rename src/main/java/ladder/domain/{ => ladder}/Line.java (98%) rename src/main/java/ladder/domain/{ => ladder}/LineStatus.java (92%) rename src/main/java/ladder/domain/{ => ladder}/Position.java (98%) rename src/main/java/ladder/domain/{ => ladder}/RandomBooleanGenerator.java (88%) rename src/main/java/ladder/domain/{ => player}/Player.java (83%) rename src/main/java/ladder/domain/{ => player}/PlayerName.java (96%) rename src/main/java/ladder/domain/{ => player}/Players.java (96%) rename src/test/java/ladder/domain/{ => item}/ItemNameTest.java (97%) rename src/test/java/ladder/domain/{ => item}/ItemTest.java (92%) rename src/test/java/ladder/domain/{ => item}/ItemsTest.java (95%) rename src/test/java/ladder/domain/{ => ladder}/HeightTest.java (97%) rename src/test/java/ladder/domain/{ => ladder}/LadderGameResultTest.java (98%) rename src/test/java/ladder/domain/{ => ladder}/LadderGameTest.java (96%) rename src/test/java/ladder/domain/{ => ladder}/LadderTest.java (92%) rename src/test/java/ladder/domain/{ => ladder}/LineStatusTest.java (97%) rename src/test/java/ladder/domain/{ => ladder}/LineTest.java (93%) rename src/test/java/ladder/domain/{ => ladder}/PositionTest.java (98%) rename src/test/java/ladder/domain/{ => player}/PlayerNameTest.java (98%) rename src/test/java/ladder/domain/{ => player}/PlayerTest.java (91%) rename src/test/java/ladder/domain/{ => player}/PlayersTest.java (95%) diff --git a/src/main/java/ladder/Application.java b/src/main/java/ladder/Application.java index 0aaabd0954..8cdf172467 100644 --- a/src/main/java/ladder/Application.java +++ b/src/main/java/ladder/Application.java @@ -2,7 +2,7 @@ import java.util.Scanner; import ladder.controller.LadderGameController; -import ladder.domain.RandomBooleanGenerator; +import ladder.domain.ladder.RandomBooleanGenerator; import ladder.view.InputView; import ladder.view.OutputView; diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 8e0169a4bd..0c3b1be647 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -3,13 +3,13 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; -import ladder.domain.BooleanGenerator; -import ladder.domain.Height; -import ladder.domain.Items; -import ladder.domain.LadderGame; -import ladder.domain.LadderGameResult; -import ladder.domain.Line; -import ladder.domain.Players; +import ladder.domain.item.Items; +import ladder.domain.ladder.BooleanGenerator; +import ladder.domain.ladder.Height; +import ladder.domain.ladder.LadderGame; +import ladder.domain.ladder.LadderGameResult; +import ladder.domain.ladder.Line; +import ladder.domain.player.Players; import ladder.view.InputView; import ladder.view.OutputView; diff --git a/src/main/java/ladder/domain/Item.java b/src/main/java/ladder/domain/item/Item.java similarity index 81% rename from src/main/java/ladder/domain/Item.java rename to src/main/java/ladder/domain/item/Item.java index 7fa6ba63f1..4136e8868e 100644 --- a/src/main/java/ladder/domain/Item.java +++ b/src/main/java/ladder/domain/item/Item.java @@ -1,6 +1,8 @@ -package ladder.domain; +package ladder.domain.item; -class Item { +import ladder.domain.ladder.Position; + +public class Item { private final ItemName name; private final Position position; diff --git a/src/main/java/ladder/domain/ItemName.java b/src/main/java/ladder/domain/item/ItemName.java similarity index 93% rename from src/main/java/ladder/domain/ItemName.java rename to src/main/java/ladder/domain/item/ItemName.java index cbcedfb293..14c4a284d5 100644 --- a/src/main/java/ladder/domain/ItemName.java +++ b/src/main/java/ladder/domain/item/ItemName.java @@ -1,6 +1,6 @@ -package ladder.domain; +package ladder.domain.item; -class ItemName { +public class ItemName { private static final int NAME_LENGTH_UPPER_BOUND = 5; private static final String INVALID_NAME_LENGTH_MESSAGE = "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/item/Items.java similarity index 95% rename from src/main/java/ladder/domain/Items.java rename to src/main/java/ladder/domain/item/Items.java index b91870373d..8c3ac957e2 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/item/Items.java @@ -1,10 +1,11 @@ -package ladder.domain; +package ladder.domain.item; import static java.util.stream.Collectors.toUnmodifiableList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; +import ladder.domain.ladder.Position; public class Items { private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; diff --git a/src/main/java/ladder/domain/BooleanGenerator.java b/src/main/java/ladder/domain/ladder/BooleanGenerator.java similarity index 67% rename from src/main/java/ladder/domain/BooleanGenerator.java rename to src/main/java/ladder/domain/ladder/BooleanGenerator.java index 5178e70d40..7c04f2c280 100644 --- a/src/main/java/ladder/domain/BooleanGenerator.java +++ b/src/main/java/ladder/domain/ladder/BooleanGenerator.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; public interface BooleanGenerator { boolean generate(); diff --git a/src/main/java/ladder/domain/Height.java b/src/main/java/ladder/domain/ladder/Height.java similarity index 97% rename from src/main/java/ladder/domain/Height.java rename to src/main/java/ladder/domain/ladder/Height.java index 7d0ecc5d0a..5de4b2d744 100644 --- a/src/main/java/ladder/domain/Height.java +++ b/src/main/java/ladder/domain/ladder/Height.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; public class Height { private static final int HEIGHT_LOWER_BOUND = 1; diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/ladder/Ladder.java similarity index 96% rename from src/main/java/ladder/domain/Ladder.java rename to src/main/java/ladder/domain/ladder/Ladder.java index 5b1a188cf7..1b4ff97f98 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/ladder/Ladder.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/ladder/LadderGame.java similarity index 92% rename from src/main/java/ladder/domain/LadderGame.java rename to src/main/java/ladder/domain/ladder/LadderGame.java index fcc0988b21..243bb8b3e5 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/ladder/LadderGame.java @@ -1,8 +1,11 @@ -package ladder.domain; +package ladder.domain.ladder; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import ladder.domain.item.Items; +import ladder.domain.player.Player; +import ladder.domain.player.Players; public class LadderGame { private static final int SUBTRACT_LADDER_WIDTH_VALUE = 1; diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/ladder/LadderGameResult.java similarity index 97% rename from src/main/java/ladder/domain/LadderGameResult.java rename to src/main/java/ladder/domain/ladder/LadderGameResult.java index 9700fddcae..29af2d190c 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/ladder/LadderGameResult.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import java.util.LinkedHashMap; import java.util.Map; diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/ladder/Line.java similarity index 98% rename from src/main/java/ladder/domain/Line.java rename to src/main/java/ladder/domain/ladder/Line.java index b628254b3b..f3c18a8741 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/ladder/Line.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import java.util.ArrayList; import java.util.LinkedHashMap; diff --git a/src/main/java/ladder/domain/LineStatus.java b/src/main/java/ladder/domain/ladder/LineStatus.java similarity index 92% rename from src/main/java/ladder/domain/LineStatus.java rename to src/main/java/ladder/domain/ladder/LineStatus.java index 58309f666e..3d3cba5b5e 100644 --- a/src/main/java/ladder/domain/LineStatus.java +++ b/src/main/java/ladder/domain/ladder/LineStatus.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; public enum LineStatus { CONNECTED, diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/ladder/Position.java similarity index 98% rename from src/main/java/ladder/domain/Position.java rename to src/main/java/ladder/domain/ladder/Position.java index c61ddec1da..75aea93b71 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/ladder/Position.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ladder/domain/RandomBooleanGenerator.java b/src/main/java/ladder/domain/ladder/RandomBooleanGenerator.java similarity index 88% rename from src/main/java/ladder/domain/RandomBooleanGenerator.java rename to src/main/java/ladder/domain/ladder/RandomBooleanGenerator.java index 61d1244551..7c9c5b84c5 100644 --- a/src/main/java/ladder/domain/RandomBooleanGenerator.java +++ b/src/main/java/ladder/domain/ladder/RandomBooleanGenerator.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import java.util.Random; diff --git a/src/main/java/ladder/domain/Player.java b/src/main/java/ladder/domain/player/Player.java similarity index 83% rename from src/main/java/ladder/domain/Player.java rename to src/main/java/ladder/domain/player/Player.java index 5186e3d447..0a09b9a851 100644 --- a/src/main/java/ladder/domain/Player.java +++ b/src/main/java/ladder/domain/player/Player.java @@ -1,4 +1,7 @@ -package ladder.domain; +package ladder.domain.player; + +import ladder.domain.ladder.Ladder; +import ladder.domain.ladder.Position; public class Player { private final PlayerName name; diff --git a/src/main/java/ladder/domain/PlayerName.java b/src/main/java/ladder/domain/player/PlayerName.java similarity index 96% rename from src/main/java/ladder/domain/PlayerName.java rename to src/main/java/ladder/domain/player/PlayerName.java index 4b00aca18e..d9f5bff058 100644 --- a/src/main/java/ladder/domain/PlayerName.java +++ b/src/main/java/ladder/domain/player/PlayerName.java @@ -1,8 +1,8 @@ -package ladder.domain; +package ladder.domain.player; import java.util.Objects; -class PlayerName { +public class PlayerName { private static final int NAME_LENGTH_UPPER_BOUND = 5; private static final String INVALID_NAME_LENGTH_MESSAGE = "이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/player/Players.java similarity index 96% rename from src/main/java/ladder/domain/Players.java rename to src/main/java/ladder/domain/player/Players.java index 194e055fd2..d28c384c73 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/player/Players.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.player; import static java.util.stream.Collectors.toUnmodifiableList; @@ -9,6 +9,8 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; +import ladder.domain.ladder.Ladder; +import ladder.domain.ladder.Position; public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; diff --git a/src/main/java/ladder/view/LadderMessageGenerator.java b/src/main/java/ladder/view/LadderMessageGenerator.java index dcc428bfbf..4599565ed4 100644 --- a/src/main/java/ladder/view/LadderMessageGenerator.java +++ b/src/main/java/ladder/view/LadderMessageGenerator.java @@ -3,8 +3,8 @@ import static java.util.stream.Collectors.joining; import java.util.List; -import ladder.domain.Line; -import ladder.domain.LineStatus; +import ladder.domain.ladder.Line; +import ladder.domain.ladder.LineStatus; class LadderMessageGenerator { diff --git a/src/main/java/ladder/view/OutputView.java b/src/main/java/ladder/view/OutputView.java index 2ee071fce4..590be2a481 100644 --- a/src/main/java/ladder/view/OutputView.java +++ b/src/main/java/ladder/view/OutputView.java @@ -5,7 +5,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import ladder.domain.Line; +import ladder.domain.ladder.Line; public class OutputView { private static final int EMPTY_NAME_LENGTH = 0; diff --git a/src/test/java/ladder/domain/ItemNameTest.java b/src/test/java/ladder/domain/item/ItemNameTest.java similarity index 97% rename from src/test/java/ladder/domain/ItemNameTest.java rename to src/test/java/ladder/domain/item/ItemNameTest.java index f7f0b7bfdd..850ee2d426 100644 --- a/src/test/java/ladder/domain/ItemNameTest.java +++ b/src/test/java/ladder/domain/item/ItemNameTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.item; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/ItemTest.java b/src/test/java/ladder/domain/item/ItemTest.java similarity index 92% rename from src/test/java/ladder/domain/ItemTest.java rename to src/test/java/ladder/domain/item/ItemTest.java index 56e19cb0ce..bcfe44678c 100644 --- a/src/test/java/ladder/domain/ItemTest.java +++ b/src/test/java/ladder/domain/item/ItemTest.java @@ -1,6 +1,6 @@ -package ladder.domain; +package ladder.domain.item; -import static ladder.domain.Position.valueOf; +import static ladder.domain.ladder.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.DisplayNameGeneration; diff --git a/src/test/java/ladder/domain/ItemsTest.java b/src/test/java/ladder/domain/item/ItemsTest.java similarity index 95% rename from src/test/java/ladder/domain/ItemsTest.java rename to src/test/java/ladder/domain/item/ItemsTest.java index 1f1a67a64f..b2971f1347 100644 --- a/src/test/java/ladder/domain/ItemsTest.java +++ b/src/test/java/ladder/domain/item/ItemsTest.java @@ -1,6 +1,6 @@ -package ladder.domain; +package ladder.domain.item; -import static ladder.domain.Position.valueOf; +import static ladder.domain.ladder.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/HeightTest.java b/src/test/java/ladder/domain/ladder/HeightTest.java similarity index 97% rename from src/test/java/ladder/domain/HeightTest.java rename to src/test/java/ladder/domain/ladder/HeightTest.java index 70c2942cd2..5dca628fa5 100644 --- a/src/test/java/ladder/domain/HeightTest.java +++ b/src/test/java/ladder/domain/ladder/HeightTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/LadderGameResultTest.java b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java similarity index 98% rename from src/test/java/ladder/domain/LadderGameResultTest.java rename to src/test/java/ladder/domain/ladder/LadderGameResultTest.java index 077be44de7..4c25ccf8b1 100644 --- a/src/test/java/ladder/domain/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/ladder/LadderGameTest.java similarity index 96% rename from src/test/java/ladder/domain/LadderGameTest.java rename to src/test/java/ladder/domain/ladder/LadderGameTest.java index 827210aabd..de90f7682e 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/ladder/LadderGameTest.java @@ -1,9 +1,11 @@ -package ladder.domain; +package ladder.domain.ladder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import java.util.List; +import ladder.domain.item.Items; +import ladder.domain.player.Players; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/LadderTest.java b/src/test/java/ladder/domain/ladder/LadderTest.java similarity index 92% rename from src/test/java/ladder/domain/LadderTest.java rename to src/test/java/ladder/domain/ladder/LadderTest.java index 6d07cc9b8e..a70388ddbe 100644 --- a/src/test/java/ladder/domain/LadderTest.java +++ b/src/test/java/ladder/domain/ladder/LadderTest.java @@ -1,7 +1,7 @@ -package ladder.domain; +package ladder.domain.ladder; -import static ladder.domain.LineStatus.CONNECTED; -import static ladder.domain.LineStatus.DISCONNECTED; +import static ladder.domain.ladder.LineStatus.CONNECTED; +import static ladder.domain.ladder.LineStatus.DISCONNECTED; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; diff --git a/src/test/java/ladder/domain/LineStatusTest.java b/src/test/java/ladder/domain/ladder/LineStatusTest.java similarity index 97% rename from src/test/java/ladder/domain/LineStatusTest.java rename to src/test/java/ladder/domain/ladder/LineStatusTest.java index c5351297fe..45848b0b71 100644 --- a/src/test/java/ladder/domain/LineStatusTest.java +++ b/src/test/java/ladder/domain/ladder/LineStatusTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/ladder/domain/LineTest.java b/src/test/java/ladder/domain/ladder/LineTest.java similarity index 93% rename from src/test/java/ladder/domain/LineTest.java rename to src/test/java/ladder/domain/ladder/LineTest.java index 79b7334cfa..234ccfbbe6 100644 --- a/src/test/java/ladder/domain/LineTest.java +++ b/src/test/java/ladder/domain/ladder/LineTest.java @@ -1,7 +1,7 @@ -package ladder.domain; +package ladder.domain.ladder; -import static ladder.domain.LineStatus.CONNECTED; -import static ladder.domain.LineStatus.DISCONNECTED; +import static ladder.domain.ladder.LineStatus.CONNECTED; +import static ladder.domain.ladder.LineStatus.DISCONNECTED; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/ladder/PositionTest.java similarity index 98% rename from src/test/java/ladder/domain/PositionTest.java rename to src/test/java/ladder/domain/ladder/PositionTest.java index 432b45cbcc..4c6f42d316 100644 --- a/src/test/java/ladder/domain/PositionTest.java +++ b/src/test/java/ladder/domain/ladder/PositionTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.ladder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/PlayerNameTest.java b/src/test/java/ladder/domain/player/PlayerNameTest.java similarity index 98% rename from src/test/java/ladder/domain/PlayerNameTest.java rename to src/test/java/ladder/domain/player/PlayerNameTest.java index c1b7b786aa..eff68908f7 100644 --- a/src/test/java/ladder/domain/PlayerNameTest.java +++ b/src/test/java/ladder/domain/player/PlayerNameTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.player; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/player/PlayerTest.java similarity index 91% rename from src/test/java/ladder/domain/PlayerTest.java rename to src/test/java/ladder/domain/player/PlayerTest.java index b3229c7c21..544ad9035a 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/player/PlayerTest.java @@ -1,8 +1,11 @@ -package ladder.domain; +package ladder.domain.player; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import ladder.domain.ladder.BooleanGenerator; +import ladder.domain.ladder.Ladder; +import ladder.domain.ladder.Position; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/player/PlayersTest.java similarity index 95% rename from src/test/java/ladder/domain/PlayersTest.java rename to src/test/java/ladder/domain/player/PlayersTest.java index 7a68c78860..94e77f00a7 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/player/PlayersTest.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.domain.player; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; @@ -9,6 +9,9 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; +import ladder.domain.ladder.BooleanGenerator; +import ladder.domain.ladder.Ladder; +import ladder.domain.ladder.Position; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/util/TestBooleanGenerator.java b/src/test/java/ladder/util/TestBooleanGenerator.java index 61c58e9661..87a956d05e 100644 --- a/src/test/java/ladder/util/TestBooleanGenerator.java +++ b/src/test/java/ladder/util/TestBooleanGenerator.java @@ -1,7 +1,7 @@ package ladder.util; import java.util.List; -import ladder.domain.BooleanGenerator; +import ladder.domain.ladder.BooleanGenerator; public class TestBooleanGenerator implements BooleanGenerator { diff --git a/src/test/java/ladder/view/LadderMessageGeneratorTest.java b/src/test/java/ladder/view/LadderMessageGeneratorTest.java index 0b248ac13a..6a4f40dd85 100644 --- a/src/test/java/ladder/view/LadderMessageGeneratorTest.java +++ b/src/test/java/ladder/view/LadderMessageGeneratorTest.java @@ -3,8 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import ladder.domain.BooleanGenerator; -import ladder.domain.Ladder; +import ladder.domain.ladder.BooleanGenerator; +import ladder.domain.ladder.Ladder; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; From 85a8b51ec053e35bb67f0f0ea9758ee01e37a91b Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 14:07:24 +0900 Subject: [PATCH 52/71] =?UTF-8?q?refactor:=20=EC=82=AC=EB=8B=A4=EB=A6=AC?= =?UTF-8?q?=20=EA=B2=8C=EC=9E=84=20=EA=B2=B0=EA=B3=BC=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=20=EC=9E=AC=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ladder/domain/ladder/LadderGame.java | 9 +++--- .../domain/ladder/LadderGameResult.java | 30 ++++++++++++++----- .../domain/ladder/LadderGameResultTest.java | 13 ++++---- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/ladder/domain/ladder/LadderGame.java b/src/main/java/ladder/domain/ladder/LadderGame.java index 243bb8b3e5..d5cc0e7061 100644 --- a/src/main/java/ladder/domain/ladder/LadderGame.java +++ b/src/main/java/ladder/domain/ladder/LadderGame.java @@ -3,6 +3,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import ladder.domain.item.Item; import ladder.domain.item.Items; import ladder.domain.player.Player; import ladder.domain.player.Players; @@ -34,15 +35,15 @@ public static LadderGame initialize( public LadderGameResult play() { final Map playResult = players.play(ladder); - final Map result = new LinkedHashMap<>(); + final Map result = new LinkedHashMap<>(); for (Player player : playResult.keySet()) { - result.put(player.getName(), toItemName(playResult.get(player))); + result.put(player, toItem(playResult.get(player))); } return new LadderGameResult(result); } - private String toItemName(final Position position) { - return items.findByPosition(position).getName(); + private Item toItem(final Position position) { + return items.findByPosition(position); } public List getPlayers() { diff --git a/src/main/java/ladder/domain/ladder/LadderGameResult.java b/src/main/java/ladder/domain/ladder/LadderGameResult.java index 29af2d190c..f9187945c6 100644 --- a/src/main/java/ladder/domain/ladder/LadderGameResult.java +++ b/src/main/java/ladder/domain/ladder/LadderGameResult.java @@ -2,14 +2,16 @@ import java.util.LinkedHashMap; import java.util.Map; +import ladder.domain.item.Item; +import ladder.domain.player.Player; public class LadderGameResult { private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; - private final Map result; + private final Map result; - public LadderGameResult(final Map result) { + public LadderGameResult(final Map result) { this.result = result; } @@ -21,13 +23,27 @@ public Map get(final String name) { } private Map getMultipleResult() { - return new LinkedHashMap<>(result); + final Map playerToItem = new LinkedHashMap<>(); + for (Player player : result.keySet()) { + playerToItem.put(player.getName(), findItemName(player)); + } + return playerToItem; + } + + private String findItemName(final Player player) { + return result.get(player).getName(); } private Map getSingleResult(final String name) { - if (!result.containsKey(name)) { - throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); - } - return Map.of(name, result.get(name)); + final Player player = findPlayer(name); + final Item item = result.get(player); + return Map.of(player.getName(), item.getName()); + } + + private Player findPlayer(final String name) { + return result.keySet().stream() + .filter(player -> player.getName().equals(name)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(INVALID_PLAYER_MESSAGE)); } } diff --git a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java index 4c25ccf8b1..edd1166d99 100644 --- a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java @@ -1,10 +1,13 @@ package ladder.domain.ladder; +import static ladder.domain.ladder.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; import java.util.Map; +import ladder.domain.item.Item; +import ladder.domain.player.Player; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -16,7 +19,7 @@ public class LadderGameResultTest { @Test void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - "name", "1000" + new Player("name", valueOf(0)), new Item("1000", valueOf(0)) )); assertThatThrownBy(() -> ladderGameResult.get("whois")) @@ -27,19 +30,19 @@ public class LadderGameResultTest { @Test void 한_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - "name", "1000" + new Player("name", valueOf(0)), new Item("1000", valueOf(0)) )); final Map result = ladderGameResult.get("name"); - assertThat(result).containsExactly(entry("name", "1000")); + assertThat(result).containsEntry("name", "1000"); } @Test void 모든_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - "name", "0", - "name2", "1000" + new Player("name", valueOf(0)), new Item("0", valueOf(0)), + new Player("name2", valueOf(1)), new Item("1000", valueOf(1)) )); final Map result = ladderGameResult.get("all"); From 6457ea783c651dffecf7fe988a9f79af41a82c18 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 14:07:50 +0900 Subject: [PATCH 53/71] =?UTF-8?q?remove:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20equals=20&=20hashcode=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ladder/domain/player/PlayerName.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/main/java/ladder/domain/player/PlayerName.java b/src/main/java/ladder/domain/player/PlayerName.java index d9f5bff058..6c78b69ac1 100644 --- a/src/main/java/ladder/domain/player/PlayerName.java +++ b/src/main/java/ladder/domain/player/PlayerName.java @@ -1,7 +1,5 @@ package ladder.domain.player; -import java.util.Objects; - public class PlayerName { private static final int NAME_LENGTH_UPPER_BOUND = 5; private static final String INVALID_NAME_LENGTH_MESSAGE = @@ -41,23 +39,6 @@ private boolean isReservedName(final String name) { return RESERVED_NAME.equals(name); } - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final PlayerName that = (PlayerName) o; - return Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(value); - } - public String getValue() { return value; } From 576cdbbaf877060e009281d9a9d434d7e35aed22 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 14:22:43 +0900 Subject: [PATCH 54/71] =?UTF-8?q?docs:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e5d168b86e..c991642a27 100644 --- a/README.md +++ b/README.md @@ -18,21 +18,25 @@ graph TD Ladder --> Line Line --> LineStatus - - LadderGame --> Position - Ladder --> Position - Items --> Position Line --> Position - Players --> Position + + Players --> Ladder + Player --> Ladder + + Item --> Position + Player --> Position + LadderGame --> LadderGameResult - Items --> Item - Players --> Player + Items --> Item --> ItemName + Players --> Player --> PlayerName LadderGameController --> InputView LadderGameController --> OutputView + OutputView --> LadderMessageGenerator + ``` ### 참가자 From e96ec857aa79e14e3248ed18cccdac56e12dd446 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Fri, 24 Feb 2023 17:28:59 +0900 Subject: [PATCH 55/71] =?UTF-8?q?refactor:=20final=20=EB=B9=A0=EC=A7=84=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/controller/LadderGameController.java | 2 +- src/main/java/ladder/view/InputView.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 0c3b1be647..4d3aa19a44 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -44,7 +44,7 @@ private LadderGame initialize() { return LadderGame.initialize(players, booleanGenerator, height, items); } - private T repeatUntilGetValidInput(Supplier inputReader) { + private T repeatUntilGetValidInput(final Supplier inputReader) { try { return inputReader.get(); } catch (IllegalArgumentException e) { diff --git a/src/main/java/ladder/view/InputView.java b/src/main/java/ladder/view/InputView.java index f57cfd9986..650c053fc7 100644 --- a/src/main/java/ladder/view/InputView.java +++ b/src/main/java/ladder/view/InputView.java @@ -27,7 +27,7 @@ public List readPlayerNames() { return splitCsvInput(input); } - private List splitCsvInput(String input) { + private List splitCsvInput(final String input) { return Arrays.stream(input.split(DELIMITER, SPLIT_LIMIT)) .map(String::trim) .collect(Collectors.toList()); From 64db4b6705d758063b3b6aef557310dcafde698d Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 18:31:40 +0900 Subject: [PATCH 56/71] =?UTF-8?q?refactor:=20Items=EB=A5=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EB=8A=94=20=EC=A0=95=EC=A0=81=ED=8C=A9?= =?UTF-8?q?=ED=84=B0=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20of?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/controller/LadderGameController.java | 2 +- src/main/java/ladder/domain/item/Items.java | 2 +- src/test/java/ladder/domain/item/ItemsTest.java | 8 ++++---- src/test/java/ladder/domain/ladder/LadderGameTest.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 4d3aa19a44..7f362ca827 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -38,7 +38,7 @@ public void run() { private LadderGame initialize() { final Players players = repeatUntilGetValidInput(() -> Players.from(inputView.readPlayerNames())); - final Items items = repeatUntilGetValidInput(() -> Items.from(inputView.readItemNames(), players.count())); + final Items items = repeatUntilGetValidInput(() -> Items.of(inputView.readItemNames(), players.count())); final Height height = repeatUntilGetValidInput(() -> new Height(inputView.readLadderHeight())); return LadderGame.initialize(players, booleanGenerator, height, items); diff --git a/src/main/java/ladder/domain/item/Items.java b/src/main/java/ladder/domain/item/Items.java index 8c3ac957e2..a91f65d41d 100644 --- a/src/main/java/ladder/domain/item/Items.java +++ b/src/main/java/ladder/domain/item/Items.java @@ -17,7 +17,7 @@ private Items(final List items) { this.items = items; } - public static Items from(final List names, int playerCount) { + public static Items of(final List names, int playerCount) { validateItemCount(names, playerCount); return IntStream.range(0, names.size()) .mapToObj(index -> new Item(names.get(index), Position.valueOf(index))) diff --git a/src/test/java/ladder/domain/item/ItemsTest.java b/src/test/java/ladder/domain/item/ItemsTest.java index b2971f1347..d902046771 100644 --- a/src/test/java/ladder/domain/item/ItemsTest.java +++ b/src/test/java/ladder/domain/item/ItemsTest.java @@ -15,14 +15,14 @@ public class ItemsTest { @Test void 실행결과는_참가인원과_동일한_개수가_아니라면_예외를_던진다() { - assertThatThrownBy(() -> Items.from(List.of("item1", "item2"), 3)) + assertThatThrownBy(() -> Items.of(List.of("item1", "item2"), 3)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("참가인원과 동일한 개수의 실행결과를 입력해야 합니다."); } @Test void 입력받은_위치에_해당하는_실행결과가_없다면_예외를_던진다() { - final Items items = Items.from(List.of("item1", "item2", "item3"), 3); + final Items items = Items.of(List.of("item1", "item2", "item3"), 3); assertThatThrownBy(() -> items.findByPosition(valueOf(10))) .isInstanceOf(IllegalArgumentException.class) @@ -31,7 +31,7 @@ public class ItemsTest { @Test void 입력받은_위치에_해당하는_실행결과를_반환한다() { - final Items items = Items.from(List.of("item1", "item2", "item3"), 3); + final Items items = Items.of(List.of("item1", "item2", "item3"), 3); final Item item = items.findByPosition(valueOf(1)); @@ -40,7 +40,7 @@ public class ItemsTest { @Test void 모든_실행결과의_이름을_반환한다() { - final Items items = Items.from(List.of("item1", "item2", "item3"), 3); + final Items items = Items.of(List.of("item1", "item2", "item3"), 3); assertThat(items.getNames()).containsExactly("item1", "item2", "item3"); } diff --git a/src/test/java/ladder/domain/ladder/LadderGameTest.java b/src/test/java/ladder/domain/ladder/LadderGameTest.java index de90f7682e..e8ba625bd2 100644 --- a/src/test/java/ladder/domain/ladder/LadderGameTest.java +++ b/src/test/java/ladder/domain/ladder/LadderGameTest.java @@ -24,7 +24,7 @@ private LadderGame initializeLadderGame( final Players players = Players.from(playerNames); final BooleanGenerator booleanGenerator = new TestBooleanGenerator(ladder); final Height height = new Height(String.valueOf(value)); - final Items items = Items.from(itemNames, players.count()); + final Items items = Items.of(itemNames, players.count()); return LadderGame.initialize(players, booleanGenerator, height, items); } From 3b4c7f487a2c2bb8a9935f3563d0231abf805511 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 21:14:11 +0900 Subject: [PATCH 57/71] =?UTF-8?q?refactor:=20OutputView=EB=A1=9C=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EB=B0=94=EB=A1=9C=20=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LadderGameController.java | 38 ++++++------------- src/main/java/ladder/view/OutputView.java | 15 +++++--- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 7f362ca827..62fbee9faa 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -1,14 +1,11 @@ package ladder.controller; -import java.util.List; -import java.util.Map; import java.util.function.Supplier; import ladder.domain.item.Items; import ladder.domain.ladder.BooleanGenerator; import ladder.domain.ladder.Height; import ladder.domain.ladder.LadderGame; import ladder.domain.ladder.LadderGameResult; -import ladder.domain.ladder.Line; import ladder.domain.player.Players; import ladder.view.InputView; import ladder.view.OutputView; @@ -31,7 +28,7 @@ public LadderGameController( public void run() { final LadderGame ladderGame = initialize(); - printLadderResult(ladderGame); + outputView.printLadderResult(ladderGame); final LadderGameResult ladderGameResult = ladderGame.play(); printLadderGameResult(ladderGameResult); } @@ -53,39 +50,26 @@ private T repeatUntilGetValidInput(final Supplier inputReader) { } } - private void printLadderResult(final LadderGame ladderGame) { - final List players = ladderGame.getPlayers(); - final List ladder = ladderGame.getLadder(); - final List items = ladderGame.getItems(); - - outputView.printLadderResult(players, ladder, items); - } - private void printLadderGameResult(final LadderGameResult ladderGameResult) { LadderGameCommand command = LadderGameCommand.SINGLE; while (command.isContinued()) { - final Map result = repeatUntilGetValidInput(() -> getLadderGameResult(ladderGameResult)); - command = LadderGameCommand.from(result.size()); - outputView.printLadderGameResult(result); + final String name = repeatUntilGetValidInput(inputView::readPlayerName); + command = LadderGameCommand.from(name); + outputView.printLadderGameResult(ladderGameResult, name); } } - private Map getLadderGameResult(final LadderGameResult ladderGameResult) { - final String name = inputView.readPlayerName(); - return ladderGameResult.get(name); - } - - enum LadderGameCommand { - ALL, + private enum LadderGameCommand { + MULTIPLE, SINGLE; - private static final int SINGLE_RESULT_SIZE = 1; + private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; - public static LadderGameCommand from(final int size) { - if (size == SINGLE_RESULT_SIZE) { - return SINGLE; + public static LadderGameCommand from(final String name) { + if (MULTIPLE_RESULT_RESERVED_NAME.equals(name)) { + return MULTIPLE; } - return ALL; + return SINGLE; } public boolean isContinued() { diff --git a/src/main/java/ladder/view/OutputView.java b/src/main/java/ladder/view/OutputView.java index 590be2a481..e2cf6574e2 100644 --- a/src/main/java/ladder/view/OutputView.java +++ b/src/main/java/ladder/view/OutputView.java @@ -5,7 +5,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import ladder.domain.ladder.Line; +import ladder.domain.ladder.LadderGame; +import ladder.domain.ladder.LadderGameResult; public class OutputView { private static final int EMPTY_NAME_LENGTH = 0; @@ -18,11 +19,15 @@ public class OutputView { private static final String LADDER_GAME_RESULT_MESSAGE = NEXT_LINE + "실행 결과"; private static final String LADDER_GAME_RESULT_MESSAGE_FORMAT = "%s : %s"; - public void printLadderResult(final List players, final List ladder, final List items) { + public void printLadderResult(final LadderGame ladderGame) { System.out.println(LADDER_RESULT_MESSAGE); + + final List players = ladderGame.getPlayers(); + final List items = ladderGame.getItems(); final int maxNameLength = calculateMaxNameLength(List.of(players, items)); + System.out.println(generateNameMessages(players, maxNameLength)); - System.out.println(LadderMessageGenerator.generate(maxNameLength, ladder)); + System.out.println(LadderMessageGenerator.generate(maxNameLength, ladderGame.getLadder())); System.out.println(generateNameMessages(items, maxNameLength)); } @@ -45,9 +50,9 @@ private String generateNameMessage(final String name, int maxNameLength) { return String.format(nameSizeFormat, name); } - public void printLadderGameResult(final Map result) { + public void printLadderGameResult(final LadderGameResult ladderGameResult, final String name) { System.out.println(LADDER_GAME_RESULT_MESSAGE); - System.out.println(generateLadderGameResultMessage(result)); + System.out.println(generateLadderGameResultMessage(ladderGameResult.get(name))); } private String generateLadderGameResultMessage(final Map result) { From 46bdddfa3c325830c8c5fbf92afb4f0a9e9eafc1 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 21:29:58 +0900 Subject: [PATCH 58/71] =?UTF-8?q?refactor:=20Position=EC=9D=98=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=B1=85=EC=9E=84=EC=9D=84=20Items=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Item=EC=97=90=EA=B2=8C=20=ED=95=A0=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/item/Item.java | 8 ++++++-- src/main/java/ladder/domain/item/Items.java | 2 +- src/test/java/ladder/domain/item/ItemTest.java | 8 ++++---- .../java/ladder/domain/ladder/LadderGameResultTest.java | 8 ++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/ladder/domain/item/Item.java b/src/main/java/ladder/domain/item/Item.java index 4136e8868e..094972c8e2 100644 --- a/src/main/java/ladder/domain/item/Item.java +++ b/src/main/java/ladder/domain/item/Item.java @@ -6,11 +6,15 @@ public class Item { private final ItemName name; private final Position position; - public Item(final String name, final Position position) { - this.name = new ItemName(name); + private Item(final ItemName name, final Position position) { + this.name = name; this.position = position; } + public static Item of(final String name, final int index) { + return new Item(new ItemName(name), Position.valueOf(index)); + } + public boolean isSamePosition(final Position position) { return this.position == position; } diff --git a/src/main/java/ladder/domain/item/Items.java b/src/main/java/ladder/domain/item/Items.java index a91f65d41d..02ef88f10a 100644 --- a/src/main/java/ladder/domain/item/Items.java +++ b/src/main/java/ladder/domain/item/Items.java @@ -20,7 +20,7 @@ private Items(final List items) { public static Items of(final List names, int playerCount) { validateItemCount(names, playerCount); return IntStream.range(0, names.size()) - .mapToObj(index -> new Item(names.get(index), Position.valueOf(index))) + .mapToObj(index -> Item.of(names.get(index), index)) .collect(Collectors.collectingAndThen(Collectors.toList(), Items::new)); } diff --git a/src/test/java/ladder/domain/item/ItemTest.java b/src/test/java/ladder/domain/item/ItemTest.java index bcfe44678c..72588c32d3 100644 --- a/src/test/java/ladder/domain/item/ItemTest.java +++ b/src/test/java/ladder/domain/item/ItemTest.java @@ -1,8 +1,8 @@ package ladder.domain.item; -import static ladder.domain.ladder.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; +import ladder.domain.ladder.Position; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -15,7 +15,7 @@ public class ItemTest { @Test void 실행결과가_정상적으로_생성된다() { - final Item item = new Item("name", valueOf(0)); + final Item item = Item.of("name", 0); assertThat(item.getName()).isEqualTo("name"); } @@ -23,8 +23,8 @@ public class ItemTest { @ParameterizedTest(name = "입력받은 위치와 같은 위치인지 확인한다. 위치: {0}, 결과 {1}") @CsvSource({"0,true", "1,false"}) void 입력받은_위치와_같은_위치인지_확인한다(final int position, final boolean result) { - final Item item = new Item("item", valueOf(0)); + final Item item = Item.of("item", 0); - assertThat(item.isSamePosition(valueOf(position))).isEqualTo(result); + assertThat(item.isSamePosition(Position.valueOf(position))).isEqualTo(result); } } diff --git a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java index edd1166d99..5d2b90361f 100644 --- a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java @@ -19,7 +19,7 @@ public class LadderGameResultTest { @Test void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name", valueOf(0)), new Item("1000", valueOf(0)) + new Player("name", valueOf(0)), Item.of("1000", 0) )); assertThatThrownBy(() -> ladderGameResult.get("whois")) @@ -30,7 +30,7 @@ public class LadderGameResultTest { @Test void 한_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name", valueOf(0)), new Item("1000", valueOf(0)) + new Player("name", valueOf(0)), Item.of("1000", 0) )); final Map result = ladderGameResult.get("name"); @@ -41,8 +41,8 @@ public class LadderGameResultTest { @Test void 모든_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name", valueOf(0)), new Item("0", valueOf(0)), - new Player("name2", valueOf(1)), new Item("1000", valueOf(1)) + new Player("name", valueOf(0)), Item.of("0", 0), + new Player("name2", valueOf(1)), Item.of("1000", 1) )); final Map result = ladderGameResult.get("all"); From a79b0448c852e6452975d475cac27aec6200ccca Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 21:32:26 +0900 Subject: [PATCH 59/71] =?UTF-8?q?refactor:=20Position=EC=9D=98=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=B1=85=EC=9E=84=EC=9D=84=20Players=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Player=EC=97=90=EA=B2=8C=20=ED=95=A0=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/player/Player.java | 8 ++++++-- src/main/java/ladder/domain/player/Players.java | 2 +- .../java/ladder/domain/ladder/LadderGameResultTest.java | 9 ++++----- src/test/java/ladder/domain/player/PlayerTest.java | 6 +++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/ladder/domain/player/Player.java b/src/main/java/ladder/domain/player/Player.java index 0a09b9a851..4fdd976b24 100644 --- a/src/main/java/ladder/domain/player/Player.java +++ b/src/main/java/ladder/domain/player/Player.java @@ -7,11 +7,15 @@ public class Player { private final PlayerName name; private final Position position; - public Player(final String name, final Position position) { - this.name = new PlayerName(name); + private Player(final PlayerName name, final Position position) { + this.name = name; this.position = position; } + public static Player of(final String name, final int index) { + return new Player(new PlayerName(name), Position.valueOf(index)); + } + public Position play(final Ladder ladder) { return ladder.play(position); } diff --git a/src/main/java/ladder/domain/player/Players.java b/src/main/java/ladder/domain/player/Players.java index d28c384c73..b937979df3 100644 --- a/src/main/java/ladder/domain/player/Players.java +++ b/src/main/java/ladder/domain/player/Players.java @@ -29,7 +29,7 @@ private Players(final List players) { public static Players from(final List names) { validate(names); return IntStream.range(0, names.size()) - .mapToObj(index -> new Player(names.get(index), Position.valueOf(index))) + .mapToObj(index -> Player.of(names.get(index), index)) .collect(Collectors.collectingAndThen(Collectors.toList(), Players::new)); } diff --git a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java index 5d2b90361f..1b7ea429b6 100644 --- a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/ladder/LadderGameResultTest.java @@ -1,6 +1,5 @@ package ladder.domain.ladder; -import static ladder.domain.ladder.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; @@ -19,7 +18,7 @@ public class LadderGameResultTest { @Test void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name", valueOf(0)), Item.of("1000", 0) + Player.of("name", 0), Item.of("1000", 0) )); assertThatThrownBy(() -> ladderGameResult.get("whois")) @@ -30,7 +29,7 @@ public class LadderGameResultTest { @Test void 한_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name", valueOf(0)), Item.of("1000", 0) + Player.of("name", 0), Item.of("1000", 0) )); final Map result = ladderGameResult.get("name"); @@ -41,8 +40,8 @@ public class LadderGameResultTest { @Test void 모든_사람에_대한_게임_결과를_반환한다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( - new Player("name", valueOf(0)), Item.of("0", 0), - new Player("name2", valueOf(1)), Item.of("1000", 1) + Player.of("name", 0), Item.of("0", 0), + Player.of("name2", 1), Item.of("1000", 1) )); final Map result = ladderGameResult.get("all"); diff --git a/src/test/java/ladder/domain/player/PlayerTest.java b/src/test/java/ladder/domain/player/PlayerTest.java index 544ad9035a..6118ed622f 100644 --- a/src/test/java/ladder/domain/player/PlayerTest.java +++ b/src/test/java/ladder/domain/player/PlayerTest.java @@ -19,7 +19,7 @@ public class PlayerTest { @Test void 참가자가_정상적으로_생성된다() { - final Player player = new Player("name", Position.valueOf(0)); + final Player player = Player.of("name", 0); assertThat(player.getName()).isEqualTo("name"); } @@ -27,14 +27,14 @@ public class PlayerTest { @ParameterizedTest(name = "입력받은 위치와 같은 위치인지 확인한다. 위치: {0}, 결과 {1}") @CsvSource({"0,true", "1,false"}) void 입력받은_위치와_같은_위치인지_확인한다(final int position, final boolean result) { - final Player player = new Player("item", Position.valueOf(0)); + final Player player = Player.of("item", 0); assertThat(player.isSamePosition(Position.valueOf(position))).isEqualTo(result); } @Test void 참가자는_사다리를_받아_사다리타기를_진행한다() { - final Player player = new Player("item", Position.valueOf(0)); + final Player player = Player.of("item", 0); final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( false, false, true, false, true, false, From e8918afcb13493115a8363fb6f0458ec7029720c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 21:41:12 +0900 Subject: [PATCH 60/71] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=A6=84=EC=9D=84?= =?UTF-8?q?=20=ED=99=95=EC=9D=B8=ED=95=A0=20=EB=95=8C=20getter=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ladder/domain/ladder/LadderGameResult.java | 2 +- src/main/java/ladder/domain/player/Player.java | 4 ++++ src/main/java/ladder/domain/player/PlayerName.java | 4 ++++ .../java/ladder/domain/player/PlayerNameTest.java | 9 +++++++++ src/test/java/ladder/domain/player/PlayerTest.java | 12 ++++++++++-- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/ladder/domain/ladder/LadderGameResult.java b/src/main/java/ladder/domain/ladder/LadderGameResult.java index f9187945c6..70c4194722 100644 --- a/src/main/java/ladder/domain/ladder/LadderGameResult.java +++ b/src/main/java/ladder/domain/ladder/LadderGameResult.java @@ -42,7 +42,7 @@ private Map getSingleResult(final String name) { private Player findPlayer(final String name) { return result.keySet().stream() - .filter(player -> player.getName().equals(name)) + .filter(player -> player.isSameName(name)) .findFirst() .orElseThrow(() -> new IllegalArgumentException(INVALID_PLAYER_MESSAGE)); } diff --git a/src/main/java/ladder/domain/player/Player.java b/src/main/java/ladder/domain/player/Player.java index 4fdd976b24..beb50180ef 100644 --- a/src/main/java/ladder/domain/player/Player.java +++ b/src/main/java/ladder/domain/player/Player.java @@ -20,6 +20,10 @@ public Position play(final Ladder ladder) { return ladder.play(position); } + public boolean isSameName(final String name) { + return this.name.isSameAs(name); + } + public boolean isSamePosition(final Position position) { return this.position == position; } diff --git a/src/main/java/ladder/domain/player/PlayerName.java b/src/main/java/ladder/domain/player/PlayerName.java index 6c78b69ac1..7842f5c784 100644 --- a/src/main/java/ladder/domain/player/PlayerName.java +++ b/src/main/java/ladder/domain/player/PlayerName.java @@ -35,6 +35,10 @@ private void validateReservedName(final String name) { } } + public boolean isSameAs(final String name) { + return value.equals(name); + } + private boolean isReservedName(final String name) { return RESERVED_NAME.equals(name); } diff --git a/src/test/java/ladder/domain/player/PlayerNameTest.java b/src/test/java/ladder/domain/player/PlayerNameTest.java index eff68908f7..646b0ded2d 100644 --- a/src/test/java/ladder/domain/player/PlayerNameTest.java +++ b/src/test/java/ladder/domain/player/PlayerNameTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; @@ -31,6 +32,14 @@ public class PlayerNameTest { assertThat(name.getValue()).isEqualTo("name"); } + @ParameterizedTest(name = "입력받은 이름과 같은 이름인지 확인한다. 이름: name, 입력받은이름: {0}, 결과 {1}") + @CsvSource({"name,true", "notSameName,false"}) + void 입력받은_이름과_같은_이름인지_확인한다(final String name, final boolean result) { + final PlayerName playerName = new PlayerName("name"); + + assertThat(playerName.isSameAs(name)).isEqualTo(result); + } + @Test void all을_이름으로_사용할_수_없다() { assertThatThrownBy(() -> new PlayerName("all")) diff --git a/src/test/java/ladder/domain/player/PlayerTest.java b/src/test/java/ladder/domain/player/PlayerTest.java index 6118ed622f..d0861ec36c 100644 --- a/src/test/java/ladder/domain/player/PlayerTest.java +++ b/src/test/java/ladder/domain/player/PlayerTest.java @@ -24,17 +24,25 @@ public class PlayerTest { assertThat(player.getName()).isEqualTo("name"); } + @ParameterizedTest(name = "입력받은 이름과 같은 이름인지 확인한다. 이름: name, 입력받은이름: {0}, 결과 {1}") + @CsvSource({"name,true", "notSameName,false"}) + void 입력받은_이름과_같은_이름인지_확인한다(final String name, final boolean result) { + final Player player = Player.of("name", 0); + + assertThat(player.isSameName(name)).isEqualTo(result); + } + @ParameterizedTest(name = "입력받은 위치와 같은 위치인지 확인한다. 위치: {0}, 결과 {1}") @CsvSource({"0,true", "1,false"}) void 입력받은_위치와_같은_위치인지_확인한다(final int position, final boolean result) { - final Player player = Player.of("item", 0); + final Player player = Player.of("name", 0); assertThat(player.isSamePosition(Position.valueOf(position))).isEqualTo(result); } @Test void 참가자는_사다리를_받아_사다리타기를_진행한다() { - final Player player = Player.of("item", 0); + final Player player = Player.of("name", 0); final BooleanGenerator booleanGenerator = new TestBooleanGenerator(List.of( false, false, true, false, true, false, From b64ae2fce64f4378775e69d0bab7fefd6dce746c Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 22:38:13 +0900 Subject: [PATCH 61/71] =?UTF-8?q?refactor:=20=EA=B9=8A=EC=9D=80=20?= =?UTF-8?q?=EA=B3=A0=EB=AF=BC=EC=97=86=EC=9D=B4=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EB=B6=84=EB=A6=AC=ED=95=9C=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=EC=9B=90=EB=9E=98=EB=8C=80=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/Application.java | 2 +- .../java/ladder/controller/LadderGameController.java | 12 ++++++------ .../ladder/domain/{ladder => }/BooleanGenerator.java | 2 +- src/main/java/ladder/domain/{ladder => }/Height.java | 2 +- src/main/java/ladder/domain/{item => }/Item.java | 4 +--- src/main/java/ladder/domain/{item => }/ItemName.java | 2 +- src/main/java/ladder/domain/{item => }/Items.java | 3 +-- src/main/java/ladder/domain/{ladder => }/Ladder.java | 2 +- .../java/ladder/domain/{ladder => }/LadderGame.java | 6 +----- .../ladder/domain/{ladder => }/LadderGameResult.java | 4 +--- src/main/java/ladder/domain/{ladder => }/Line.java | 2 +- .../java/ladder/domain/{ladder => }/LineStatus.java | 2 +- src/main/java/ladder/domain/{player => }/Player.java | 5 +---- .../java/ladder/domain/{player => }/PlayerName.java | 2 +- .../java/ladder/domain/{player => }/Players.java | 4 +--- .../java/ladder/domain/{ladder => }/Position.java | 2 +- .../domain/{ladder => }/RandomBooleanGenerator.java | 2 +- .../java/ladder/view/LadderMessageGenerator.java | 4 ++-- src/main/java/ladder/view/OutputView.java | 4 ++-- .../java/ladder/domain/{ladder => }/HeightTest.java | 2 +- .../java/ladder/domain/{item => }/ItemNameTest.java | 2 +- src/test/java/ladder/domain/{item => }/ItemTest.java | 3 +-- .../java/ladder/domain/{item => }/ItemsTest.java | 4 ++-- .../domain/{ladder => }/LadderGameResultTest.java | 4 +--- .../ladder/domain/{ladder => }/LadderGameTest.java | 4 +--- .../java/ladder/domain/{ladder => }/LadderTest.java | 6 +++--- .../ladder/domain/{ladder => }/LineStatusTest.java | 2 +- .../java/ladder/domain/{ladder => }/LineTest.java | 6 +++--- .../ladder/domain/{player => }/PlayerNameTest.java | 2 +- .../java/ladder/domain/{player => }/PlayerTest.java | 5 +---- .../java/ladder/domain/{player => }/PlayersTest.java | 5 +---- .../ladder/domain/{ladder => }/PositionTest.java | 2 +- src/test/java/ladder/util/TestBooleanGenerator.java | 2 +- .../java/ladder/view/LadderMessageGeneratorTest.java | 4 ++-- 34 files changed, 47 insertions(+), 72 deletions(-) rename src/main/java/ladder/domain/{ladder => }/BooleanGenerator.java (67%) rename src/main/java/ladder/domain/{ladder => }/Height.java (97%) rename src/main/java/ladder/domain/{item => }/Item.java (89%) rename src/main/java/ladder/domain/{item => }/ItemName.java (96%) rename src/main/java/ladder/domain/{item => }/Items.java (95%) rename src/main/java/ladder/domain/{ladder => }/Ladder.java (96%) rename src/main/java/ladder/domain/{ladder => }/LadderGame.java (90%) rename src/main/java/ladder/domain/{ladder => }/LadderGameResult.java (94%) rename src/main/java/ladder/domain/{ladder => }/Line.java (98%) rename src/main/java/ladder/domain/{ladder => }/LineStatus.java (92%) rename src/main/java/ladder/domain/{player => }/Player.java (87%) rename src/main/java/ladder/domain/{player => }/PlayerName.java (97%) rename src/main/java/ladder/domain/{player => }/Players.java (96%) rename src/main/java/ladder/domain/{ladder => }/Position.java (98%) rename src/main/java/ladder/domain/{ladder => }/RandomBooleanGenerator.java (88%) rename src/test/java/ladder/domain/{ladder => }/HeightTest.java (97%) rename src/test/java/ladder/domain/{item => }/ItemNameTest.java (97%) rename src/test/java/ladder/domain/{item => }/ItemTest.java (93%) rename src/test/java/ladder/domain/{item => }/ItemsTest.java (95%) rename src/test/java/ladder/domain/{ladder => }/LadderGameResultTest.java (94%) rename src/test/java/ladder/domain/{ladder => }/LadderGameTest.java (96%) rename src/test/java/ladder/domain/{ladder => }/LadderTest.java (92%) rename src/test/java/ladder/domain/{ladder => }/LineStatusTest.java (97%) rename src/test/java/ladder/domain/{ladder => }/LineTest.java (93%) rename src/test/java/ladder/domain/{player => }/PlayerNameTest.java (98%) rename src/test/java/ladder/domain/{player => }/PlayerTest.java (93%) rename src/test/java/ladder/domain/{player => }/PlayersTest.java (95%) rename src/test/java/ladder/domain/{ladder => }/PositionTest.java (98%) diff --git a/src/main/java/ladder/Application.java b/src/main/java/ladder/Application.java index 8cdf172467..0aaabd0954 100644 --- a/src/main/java/ladder/Application.java +++ b/src/main/java/ladder/Application.java @@ -2,7 +2,7 @@ import java.util.Scanner; import ladder.controller.LadderGameController; -import ladder.domain.ladder.RandomBooleanGenerator; +import ladder.domain.RandomBooleanGenerator; import ladder.view.InputView; import ladder.view.OutputView; diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 62fbee9faa..aefc8eb849 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -1,12 +1,12 @@ package ladder.controller; import java.util.function.Supplier; -import ladder.domain.item.Items; -import ladder.domain.ladder.BooleanGenerator; -import ladder.domain.ladder.Height; -import ladder.domain.ladder.LadderGame; -import ladder.domain.ladder.LadderGameResult; -import ladder.domain.player.Players; +import ladder.domain.BooleanGenerator; +import ladder.domain.Height; +import ladder.domain.Items; +import ladder.domain.LadderGame; +import ladder.domain.LadderGameResult; +import ladder.domain.Players; import ladder.view.InputView; import ladder.view.OutputView; diff --git a/src/main/java/ladder/domain/ladder/BooleanGenerator.java b/src/main/java/ladder/domain/BooleanGenerator.java similarity index 67% rename from src/main/java/ladder/domain/ladder/BooleanGenerator.java rename to src/main/java/ladder/domain/BooleanGenerator.java index 7c04f2c280..5178e70d40 100644 --- a/src/main/java/ladder/domain/ladder/BooleanGenerator.java +++ b/src/main/java/ladder/domain/BooleanGenerator.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; public interface BooleanGenerator { boolean generate(); diff --git a/src/main/java/ladder/domain/ladder/Height.java b/src/main/java/ladder/domain/Height.java similarity index 97% rename from src/main/java/ladder/domain/ladder/Height.java rename to src/main/java/ladder/domain/Height.java index 5de4b2d744..7d0ecc5d0a 100644 --- a/src/main/java/ladder/domain/ladder/Height.java +++ b/src/main/java/ladder/domain/Height.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; public class Height { private static final int HEIGHT_LOWER_BOUND = 1; diff --git a/src/main/java/ladder/domain/item/Item.java b/src/main/java/ladder/domain/Item.java similarity index 89% rename from src/main/java/ladder/domain/item/Item.java rename to src/main/java/ladder/domain/Item.java index 094972c8e2..1a03a6a9b9 100644 --- a/src/main/java/ladder/domain/item/Item.java +++ b/src/main/java/ladder/domain/Item.java @@ -1,6 +1,4 @@ -package ladder.domain.item; - -import ladder.domain.ladder.Position; +package ladder.domain; public class Item { private final ItemName name; diff --git a/src/main/java/ladder/domain/item/ItemName.java b/src/main/java/ladder/domain/ItemName.java similarity index 96% rename from src/main/java/ladder/domain/item/ItemName.java rename to src/main/java/ladder/domain/ItemName.java index 14c4a284d5..2d101eaff6 100644 --- a/src/main/java/ladder/domain/item/ItemName.java +++ b/src/main/java/ladder/domain/ItemName.java @@ -1,4 +1,4 @@ -package ladder.domain.item; +package ladder.domain; public class ItemName { private static final int NAME_LENGTH_UPPER_BOUND = 5; diff --git a/src/main/java/ladder/domain/item/Items.java b/src/main/java/ladder/domain/Items.java similarity index 95% rename from src/main/java/ladder/domain/item/Items.java rename to src/main/java/ladder/domain/Items.java index 02ef88f10a..df1b9c78d2 100644 --- a/src/main/java/ladder/domain/item/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -1,11 +1,10 @@ -package ladder.domain.item; +package ladder.domain; import static java.util.stream.Collectors.toUnmodifiableList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -import ladder.domain.ladder.Position; public class Items { private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; diff --git a/src/main/java/ladder/domain/ladder/Ladder.java b/src/main/java/ladder/domain/Ladder.java similarity index 96% rename from src/main/java/ladder/domain/ladder/Ladder.java rename to src/main/java/ladder/domain/Ladder.java index 1b4ff97f98..5b1a188cf7 100644 --- a/src/main/java/ladder/domain/ladder/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; diff --git a/src/main/java/ladder/domain/ladder/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java similarity index 90% rename from src/main/java/ladder/domain/ladder/LadderGame.java rename to src/main/java/ladder/domain/LadderGame.java index d5cc0e7061..fbc0a5b81f 100644 --- a/src/main/java/ladder/domain/ladder/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -1,12 +1,8 @@ -package ladder.domain.ladder; +package ladder.domain; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import ladder.domain.item.Item; -import ladder.domain.item.Items; -import ladder.domain.player.Player; -import ladder.domain.player.Players; public class LadderGame { private static final int SUBTRACT_LADDER_WIDTH_VALUE = 1; diff --git a/src/main/java/ladder/domain/ladder/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java similarity index 94% rename from src/main/java/ladder/domain/ladder/LadderGameResult.java rename to src/main/java/ladder/domain/LadderGameResult.java index 70c4194722..05683c7996 100644 --- a/src/main/java/ladder/domain/ladder/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -1,9 +1,7 @@ -package ladder.domain.ladder; +package ladder.domain; import java.util.LinkedHashMap; import java.util.Map; -import ladder.domain.item.Item; -import ladder.domain.player.Player; public class LadderGameResult { private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; diff --git a/src/main/java/ladder/domain/ladder/Line.java b/src/main/java/ladder/domain/Line.java similarity index 98% rename from src/main/java/ladder/domain/ladder/Line.java rename to src/main/java/ladder/domain/Line.java index f3c18a8741..b628254b3b 100644 --- a/src/main/java/ladder/domain/ladder/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import java.util.ArrayList; import java.util.LinkedHashMap; diff --git a/src/main/java/ladder/domain/ladder/LineStatus.java b/src/main/java/ladder/domain/LineStatus.java similarity index 92% rename from src/main/java/ladder/domain/ladder/LineStatus.java rename to src/main/java/ladder/domain/LineStatus.java index 3d3cba5b5e..58309f666e 100644 --- a/src/main/java/ladder/domain/ladder/LineStatus.java +++ b/src/main/java/ladder/domain/LineStatus.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; public enum LineStatus { CONNECTED, diff --git a/src/main/java/ladder/domain/player/Player.java b/src/main/java/ladder/domain/Player.java similarity index 87% rename from src/main/java/ladder/domain/player/Player.java rename to src/main/java/ladder/domain/Player.java index beb50180ef..07fbfb3538 100644 --- a/src/main/java/ladder/domain/player/Player.java +++ b/src/main/java/ladder/domain/Player.java @@ -1,7 +1,4 @@ -package ladder.domain.player; - -import ladder.domain.ladder.Ladder; -import ladder.domain.ladder.Position; +package ladder.domain; public class Player { private final PlayerName name; diff --git a/src/main/java/ladder/domain/player/PlayerName.java b/src/main/java/ladder/domain/PlayerName.java similarity index 97% rename from src/main/java/ladder/domain/player/PlayerName.java rename to src/main/java/ladder/domain/PlayerName.java index 7842f5c784..67427d5ed2 100644 --- a/src/main/java/ladder/domain/player/PlayerName.java +++ b/src/main/java/ladder/domain/PlayerName.java @@ -1,4 +1,4 @@ -package ladder.domain.player; +package ladder.domain; public class PlayerName { private static final int NAME_LENGTH_UPPER_BOUND = 5; diff --git a/src/main/java/ladder/domain/player/Players.java b/src/main/java/ladder/domain/Players.java similarity index 96% rename from src/main/java/ladder/domain/player/Players.java rename to src/main/java/ladder/domain/Players.java index b937979df3..44b279cf12 100644 --- a/src/main/java/ladder/domain/player/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -1,4 +1,4 @@ -package ladder.domain.player; +package ladder.domain; import static java.util.stream.Collectors.toUnmodifiableList; @@ -9,8 +9,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; -import ladder.domain.ladder.Ladder; -import ladder.domain.ladder.Position; public class Players { private static final int PLAYERS_SIZE_LOWER_BOUND = 2; diff --git a/src/main/java/ladder/domain/ladder/Position.java b/src/main/java/ladder/domain/Position.java similarity index 98% rename from src/main/java/ladder/domain/ladder/Position.java rename to src/main/java/ladder/domain/Position.java index 75aea93b71..c61ddec1da 100644 --- a/src/main/java/ladder/domain/ladder/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ladder/domain/ladder/RandomBooleanGenerator.java b/src/main/java/ladder/domain/RandomBooleanGenerator.java similarity index 88% rename from src/main/java/ladder/domain/ladder/RandomBooleanGenerator.java rename to src/main/java/ladder/domain/RandomBooleanGenerator.java index 7c9c5b84c5..61d1244551 100644 --- a/src/main/java/ladder/domain/ladder/RandomBooleanGenerator.java +++ b/src/main/java/ladder/domain/RandomBooleanGenerator.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import java.util.Random; diff --git a/src/main/java/ladder/view/LadderMessageGenerator.java b/src/main/java/ladder/view/LadderMessageGenerator.java index 4599565ed4..dcc428bfbf 100644 --- a/src/main/java/ladder/view/LadderMessageGenerator.java +++ b/src/main/java/ladder/view/LadderMessageGenerator.java @@ -3,8 +3,8 @@ import static java.util.stream.Collectors.joining; import java.util.List; -import ladder.domain.ladder.Line; -import ladder.domain.ladder.LineStatus; +import ladder.domain.Line; +import ladder.domain.LineStatus; class LadderMessageGenerator { diff --git a/src/main/java/ladder/view/OutputView.java b/src/main/java/ladder/view/OutputView.java index e2cf6574e2..7ff0ea6baa 100644 --- a/src/main/java/ladder/view/OutputView.java +++ b/src/main/java/ladder/view/OutputView.java @@ -5,8 +5,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import ladder.domain.ladder.LadderGame; -import ladder.domain.ladder.LadderGameResult; +import ladder.domain.LadderGame; +import ladder.domain.LadderGameResult; public class OutputView { private static final int EMPTY_NAME_LENGTH = 0; diff --git a/src/test/java/ladder/domain/ladder/HeightTest.java b/src/test/java/ladder/domain/HeightTest.java similarity index 97% rename from src/test/java/ladder/domain/ladder/HeightTest.java rename to src/test/java/ladder/domain/HeightTest.java index 5dca628fa5..70c2942cd2 100644 --- a/src/test/java/ladder/domain/ladder/HeightTest.java +++ b/src/test/java/ladder/domain/HeightTest.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/item/ItemNameTest.java b/src/test/java/ladder/domain/ItemNameTest.java similarity index 97% rename from src/test/java/ladder/domain/item/ItemNameTest.java rename to src/test/java/ladder/domain/ItemNameTest.java index 850ee2d426..f7f0b7bfdd 100644 --- a/src/test/java/ladder/domain/item/ItemNameTest.java +++ b/src/test/java/ladder/domain/ItemNameTest.java @@ -1,4 +1,4 @@ -package ladder.domain.item; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/item/ItemTest.java b/src/test/java/ladder/domain/ItemTest.java similarity index 93% rename from src/test/java/ladder/domain/item/ItemTest.java rename to src/test/java/ladder/domain/ItemTest.java index 72588c32d3..2263e2c3a5 100644 --- a/src/test/java/ladder/domain/item/ItemTest.java +++ b/src/test/java/ladder/domain/ItemTest.java @@ -1,8 +1,7 @@ -package ladder.domain.item; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; -import ladder.domain.ladder.Position; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/src/test/java/ladder/domain/item/ItemsTest.java b/src/test/java/ladder/domain/ItemsTest.java similarity index 95% rename from src/test/java/ladder/domain/item/ItemsTest.java rename to src/test/java/ladder/domain/ItemsTest.java index d902046771..dd0446fab7 100644 --- a/src/test/java/ladder/domain/item/ItemsTest.java +++ b/src/test/java/ladder/domain/ItemsTest.java @@ -1,6 +1,6 @@ -package ladder.domain.item; +package ladder.domain; -import static ladder.domain.ladder.Position.valueOf; +import static ladder.domain.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java b/src/test/java/ladder/domain/LadderGameResultTest.java similarity index 94% rename from src/test/java/ladder/domain/ladder/LadderGameResultTest.java rename to src/test/java/ladder/domain/LadderGameResultTest.java index 1b7ea429b6..04a8c2b407 100644 --- a/src/test/java/ladder/domain/ladder/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/LadderGameResultTest.java @@ -1,12 +1,10 @@ -package ladder.domain.ladder; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; import java.util.Map; -import ladder.domain.item.Item; -import ladder.domain.player.Player; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/src/test/java/ladder/domain/ladder/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java similarity index 96% rename from src/test/java/ladder/domain/ladder/LadderGameTest.java rename to src/test/java/ladder/domain/LadderGameTest.java index e8ba625bd2..f0651704ae 100644 --- a/src/test/java/ladder/domain/ladder/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -1,11 +1,9 @@ -package ladder.domain.ladder; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import java.util.List; -import ladder.domain.item.Items; -import ladder.domain.player.Players; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/ladder/LadderTest.java b/src/test/java/ladder/domain/LadderTest.java similarity index 92% rename from src/test/java/ladder/domain/ladder/LadderTest.java rename to src/test/java/ladder/domain/LadderTest.java index a70388ddbe..6d07cc9b8e 100644 --- a/src/test/java/ladder/domain/ladder/LadderTest.java +++ b/src/test/java/ladder/domain/LadderTest.java @@ -1,7 +1,7 @@ -package ladder.domain.ladder; +package ladder.domain; -import static ladder.domain.ladder.LineStatus.CONNECTED; -import static ladder.domain.ladder.LineStatus.DISCONNECTED; +import static ladder.domain.LineStatus.CONNECTED; +import static ladder.domain.LineStatus.DISCONNECTED; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; diff --git a/src/test/java/ladder/domain/ladder/LineStatusTest.java b/src/test/java/ladder/domain/LineStatusTest.java similarity index 97% rename from src/test/java/ladder/domain/ladder/LineStatusTest.java rename to src/test/java/ladder/domain/LineStatusTest.java index 45848b0b71..c5351297fe 100644 --- a/src/test/java/ladder/domain/ladder/LineStatusTest.java +++ b/src/test/java/ladder/domain/LineStatusTest.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/ladder/domain/ladder/LineTest.java b/src/test/java/ladder/domain/LineTest.java similarity index 93% rename from src/test/java/ladder/domain/ladder/LineTest.java rename to src/test/java/ladder/domain/LineTest.java index 234ccfbbe6..79b7334cfa 100644 --- a/src/test/java/ladder/domain/ladder/LineTest.java +++ b/src/test/java/ladder/domain/LineTest.java @@ -1,7 +1,7 @@ -package ladder.domain.ladder; +package ladder.domain; -import static ladder.domain.ladder.LineStatus.CONNECTED; -import static ladder.domain.ladder.LineStatus.DISCONNECTED; +import static ladder.domain.LineStatus.CONNECTED; +import static ladder.domain.LineStatus.DISCONNECTED; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; diff --git a/src/test/java/ladder/domain/player/PlayerNameTest.java b/src/test/java/ladder/domain/PlayerNameTest.java similarity index 98% rename from src/test/java/ladder/domain/player/PlayerNameTest.java rename to src/test/java/ladder/domain/PlayerNameTest.java index 646b0ded2d..119a02b07c 100644 --- a/src/test/java/ladder/domain/player/PlayerNameTest.java +++ b/src/test/java/ladder/domain/PlayerNameTest.java @@ -1,4 +1,4 @@ -package ladder.domain.player; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/ladder/domain/player/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java similarity index 93% rename from src/test/java/ladder/domain/player/PlayerTest.java rename to src/test/java/ladder/domain/PlayerTest.java index d0861ec36c..b52f3cb127 100644 --- a/src/test/java/ladder/domain/player/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -1,11 +1,8 @@ -package ladder.domain.player; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import ladder.domain.ladder.BooleanGenerator; -import ladder.domain.ladder.Ladder; -import ladder.domain.ladder.Position; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/player/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java similarity index 95% rename from src/test/java/ladder/domain/player/PlayersTest.java rename to src/test/java/ladder/domain/PlayersTest.java index 94e77f00a7..7a68c78860 100644 --- a/src/test/java/ladder/domain/player/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -1,4 +1,4 @@ -package ladder.domain.player; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; @@ -9,9 +9,6 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; -import ladder.domain.ladder.BooleanGenerator; -import ladder.domain.ladder.Ladder; -import ladder.domain.ladder.Position; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/ladder/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java similarity index 98% rename from src/test/java/ladder/domain/ladder/PositionTest.java rename to src/test/java/ladder/domain/PositionTest.java index 4c6f42d316..432b45cbcc 100644 --- a/src/test/java/ladder/domain/ladder/PositionTest.java +++ b/src/test/java/ladder/domain/PositionTest.java @@ -1,4 +1,4 @@ -package ladder.domain.ladder; +package ladder.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/ladder/util/TestBooleanGenerator.java b/src/test/java/ladder/util/TestBooleanGenerator.java index 87a956d05e..61c58e9661 100644 --- a/src/test/java/ladder/util/TestBooleanGenerator.java +++ b/src/test/java/ladder/util/TestBooleanGenerator.java @@ -1,7 +1,7 @@ package ladder.util; import java.util.List; -import ladder.domain.ladder.BooleanGenerator; +import ladder.domain.BooleanGenerator; public class TestBooleanGenerator implements BooleanGenerator { diff --git a/src/test/java/ladder/view/LadderMessageGeneratorTest.java b/src/test/java/ladder/view/LadderMessageGeneratorTest.java index 6a4f40dd85..0b248ac13a 100644 --- a/src/test/java/ladder/view/LadderMessageGeneratorTest.java +++ b/src/test/java/ladder/view/LadderMessageGeneratorTest.java @@ -3,8 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import ladder.domain.ladder.BooleanGenerator; -import ladder.domain.ladder.Ladder; +import ladder.domain.BooleanGenerator; +import ladder.domain.Ladder; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; From c4565fde25a8e5a5239e683fdc8f348b9ddaab33 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 22:52:42 +0900 Subject: [PATCH 62/71] =?UTF-8?q?refactor:=20BooleanGenerator=EC=99=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=B2=B4=20util=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/Application.java | 2 +- src/main/java/ladder/controller/LadderGameController.java | 2 +- src/main/java/ladder/domain/Ladder.java | 1 + src/main/java/ladder/domain/LadderGame.java | 1 + src/main/java/ladder/domain/Line.java | 1 + src/main/java/ladder/{domain => util}/BooleanGenerator.java | 2 +- .../java/ladder/{domain => util}/RandomBooleanGenerator.java | 2 +- src/test/java/ladder/domain/LadderGameTest.java | 1 + src/test/java/ladder/domain/LadderTest.java | 1 + src/test/java/ladder/domain/LineTest.java | 1 + src/test/java/ladder/domain/PlayerTest.java | 1 + src/test/java/ladder/domain/PlayersTest.java | 1 + src/test/java/ladder/util/TestBooleanGenerator.java | 1 - src/test/java/ladder/view/LadderMessageGeneratorTest.java | 2 +- 14 files changed, 13 insertions(+), 6 deletions(-) rename src/main/java/ladder/{domain => util}/BooleanGenerator.java (73%) rename src/main/java/ladder/{domain => util}/RandomBooleanGenerator.java (91%) diff --git a/src/main/java/ladder/Application.java b/src/main/java/ladder/Application.java index 0aaabd0954..e1fb21eb4b 100644 --- a/src/main/java/ladder/Application.java +++ b/src/main/java/ladder/Application.java @@ -2,7 +2,7 @@ import java.util.Scanner; import ladder.controller.LadderGameController; -import ladder.domain.RandomBooleanGenerator; +import ladder.util.RandomBooleanGenerator; import ladder.view.InputView; import ladder.view.OutputView; diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index aefc8eb849..905868280e 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -1,12 +1,12 @@ package ladder.controller; import java.util.function.Supplier; -import ladder.domain.BooleanGenerator; import ladder.domain.Height; import ladder.domain.Items; import ladder.domain.LadderGame; import ladder.domain.LadderGameResult; import ladder.domain.Players; +import ladder.util.BooleanGenerator; import ladder.view.InputView; import ladder.view.OutputView; diff --git a/src/main/java/ladder/domain/Ladder.java b/src/main/java/ladder/domain/Ladder.java index 5b1a188cf7..184be106d7 100644 --- a/src/main/java/ladder/domain/Ladder.java +++ b/src/main/java/ladder/domain/Ladder.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Stream; +import ladder.util.BooleanGenerator; public class Ladder { diff --git a/src/main/java/ladder/domain/LadderGame.java b/src/main/java/ladder/domain/LadderGame.java index fbc0a5b81f..743ee516f0 100644 --- a/src/main/java/ladder/domain/LadderGame.java +++ b/src/main/java/ladder/domain/LadderGame.java @@ -3,6 +3,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import ladder.util.BooleanGenerator; public class LadderGame { private static final int SUBTRACT_LADDER_WIDTH_VALUE = 1; diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index b628254b3b..d2d4856826 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -4,6 +4,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import ladder.util.BooleanGenerator; public class Line { diff --git a/src/main/java/ladder/domain/BooleanGenerator.java b/src/main/java/ladder/util/BooleanGenerator.java similarity index 73% rename from src/main/java/ladder/domain/BooleanGenerator.java rename to src/main/java/ladder/util/BooleanGenerator.java index 5178e70d40..1a1488bc1d 100644 --- a/src/main/java/ladder/domain/BooleanGenerator.java +++ b/src/main/java/ladder/util/BooleanGenerator.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.util; public interface BooleanGenerator { boolean generate(); diff --git a/src/main/java/ladder/domain/RandomBooleanGenerator.java b/src/main/java/ladder/util/RandomBooleanGenerator.java similarity index 91% rename from src/main/java/ladder/domain/RandomBooleanGenerator.java rename to src/main/java/ladder/util/RandomBooleanGenerator.java index 61d1244551..6463246c81 100644 --- a/src/main/java/ladder/domain/RandomBooleanGenerator.java +++ b/src/main/java/ladder/util/RandomBooleanGenerator.java @@ -1,4 +1,4 @@ -package ladder.domain; +package ladder.util; import java.util.Random; diff --git a/src/test/java/ladder/domain/LadderGameTest.java b/src/test/java/ladder/domain/LadderGameTest.java index f0651704ae..80e2f62c3f 100644 --- a/src/test/java/ladder/domain/LadderGameTest.java +++ b/src/test/java/ladder/domain/LadderGameTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.entry; import java.util.List; +import ladder.util.BooleanGenerator; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/LadderTest.java b/src/test/java/ladder/domain/LadderTest.java index 6d07cc9b8e..4e26e4975d 100644 --- a/src/test/java/ladder/domain/LadderTest.java +++ b/src/test/java/ladder/domain/LadderTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import ladder.util.BooleanGenerator; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/LineTest.java b/src/test/java/ladder/domain/LineTest.java index 79b7334cfa..4eb37de61e 100644 --- a/src/test/java/ladder/domain/LineTest.java +++ b/src/test/java/ladder/domain/LineTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import ladder.util.BooleanGenerator; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/PlayerTest.java b/src/test/java/ladder/domain/PlayerTest.java index b52f3cb127..9919c7d165 100644 --- a/src/test/java/ladder/domain/PlayerTest.java +++ b/src/test/java/ladder/domain/PlayerTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import ladder.util.BooleanGenerator; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index 7a68c78860..54b7b5391e 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; +import ladder.util.BooleanGenerator; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/ladder/util/TestBooleanGenerator.java b/src/test/java/ladder/util/TestBooleanGenerator.java index 61c58e9661..be73ae1133 100644 --- a/src/test/java/ladder/util/TestBooleanGenerator.java +++ b/src/test/java/ladder/util/TestBooleanGenerator.java @@ -1,7 +1,6 @@ package ladder.util; import java.util.List; -import ladder.domain.BooleanGenerator; public class TestBooleanGenerator implements BooleanGenerator { diff --git a/src/test/java/ladder/view/LadderMessageGeneratorTest.java b/src/test/java/ladder/view/LadderMessageGeneratorTest.java index 0b248ac13a..be6c1d9e4d 100644 --- a/src/test/java/ladder/view/LadderMessageGeneratorTest.java +++ b/src/test/java/ladder/view/LadderMessageGeneratorTest.java @@ -3,8 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import ladder.domain.BooleanGenerator; import ladder.domain.Ladder; +import ladder.util.BooleanGenerator; import ladder.util.TestBooleanGenerator; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; From 2f844e6baf84a4eb74d53957720923fe7b8061f1 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 23:20:37 +0900 Subject: [PATCH 63/71] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=A6=84=EC=97=90?= =?UTF-8?q?=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/ladder/domain/ItemNameTest.java | 4 ++-- src/test/java/ladder/domain/PlayerNameTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/ladder/domain/ItemNameTest.java b/src/test/java/ladder/domain/ItemNameTest.java index f7f0b7bfdd..e92a079615 100644 --- a/src/test/java/ladder/domain/ItemNameTest.java +++ b/src/test/java/ladder/domain/ItemNameTest.java @@ -10,10 +10,10 @@ public class ItemNameTest { - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @ParameterizedTest(name = "이름이 NULL, 빈값, 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") @NullAndEmptySource @ValueSource(strings = {"우아한상품들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + void 이름이_NULL_빈값_6자_이상인_경우_예외를_던진다(final String name) { assertThatThrownBy(() -> new ItemName(name)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); diff --git a/src/test/java/ladder/domain/PlayerNameTest.java b/src/test/java/ladder/domain/PlayerNameTest.java index 119a02b07c..f8a01c7739 100644 --- a/src/test/java/ladder/domain/PlayerNameTest.java +++ b/src/test/java/ladder/domain/PlayerNameTest.java @@ -16,10 +16,10 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class PlayerNameTest { - @ParameterizedTest(name = "이름이 비어있거나 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") + @ParameterizedTest(name = "이름이 NULL, 빈값, 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") @NullAndEmptySource @ValueSource(strings = {"우아한형제들"}) - void 이름이_비어있거나_6자_이상인_경우_예외를_던진다(final String name) { + void 이름이_NULL_빈값_6자_이상인_경우_예외를_던진다(final String name) { assertThatThrownBy(() -> new PlayerName(name)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("이름은 1자 이상, 5자 이하여야 합니다."); From 082d975c85c852ef4fe546d9478cfd655739ea2b Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sat, 25 Feb 2023 23:31:18 +0900 Subject: [PATCH 64/71] =?UTF-8?q?refactor:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20package-private=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Height.java | 2 +- src/main/java/ladder/domain/ItemName.java | 4 +-- src/main/java/ladder/domain/Items.java | 4 +-- .../java/ladder/domain/LadderGameResult.java | 4 +-- src/main/java/ladder/domain/PlayerName.java | 5 ++-- src/main/java/ladder/domain/Players.java | 8 +++--- src/main/java/ladder/domain/Position.java | 4 +-- src/test/java/ladder/domain/HeightTest.java | 3 ++- src/test/java/ladder/domain/ItemNameTest.java | 3 ++- src/test/java/ladder/domain/ItemsTest.java | 6 +++-- .../ladder/domain/LadderGameResultTest.java | 3 ++- .../java/ladder/domain/PlayerNameTest.java | 6 +++-- src/test/java/ladder/domain/PlayersTest.java | 27 ++++++++++++++----- src/test/java/ladder/domain/PositionTest.java | 5 ++-- 14 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/main/java/ladder/domain/Height.java b/src/main/java/ladder/domain/Height.java index 7d0ecc5d0a..a56cc3e6c6 100644 --- a/src/main/java/ladder/domain/Height.java +++ b/src/main/java/ladder/domain/Height.java @@ -3,7 +3,7 @@ public class Height { private static final int HEIGHT_LOWER_BOUND = 1; private static final int HEIGHT_UPPER_BOUND = 100; - private static final String INVALID_HEIGHT_MESSAGE = + static final String INVALID_HEIGHT_MESSAGE = "높이는 " + HEIGHT_LOWER_BOUND + "이상, " + HEIGHT_UPPER_BOUND + "이하의 값이어야 합니다."; private final int value; diff --git a/src/main/java/ladder/domain/ItemName.java b/src/main/java/ladder/domain/ItemName.java index 2d101eaff6..4637effd78 100644 --- a/src/main/java/ladder/domain/ItemName.java +++ b/src/main/java/ladder/domain/ItemName.java @@ -2,9 +2,9 @@ public class ItemName { private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = + static final String INVALID_NAME_LENGTH_MESSAGE = "실행 결과명은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; - + private final String value; public ItemName(final String name) { diff --git a/src/main/java/ladder/domain/Items.java b/src/main/java/ladder/domain/Items.java index df1b9c78d2..932313f759 100644 --- a/src/main/java/ladder/domain/Items.java +++ b/src/main/java/ladder/domain/Items.java @@ -7,8 +7,8 @@ import java.util.stream.IntStream; public class Items { - private static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; - private static final String INVALID_ITEM_MESSAGE = "해당 위치에 있는 아이템이 존재하지 않습니다."; + static final String INVALID_ITEM_COUNT_MESSAGE = "참가인원과 동일한 개수의 실행결과를 입력해야 합니다."; + static final String INVALID_ITEM_MESSAGE = "해당 위치에 있는 아이템이 존재하지 않습니다."; private final List items; diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 05683c7996..40480e345d 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -4,9 +4,9 @@ import java.util.Map; public class LadderGameResult { + static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; - private static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; - + private final Map result; public LadderGameResult(final Map result) { diff --git a/src/main/java/ladder/domain/PlayerName.java b/src/main/java/ladder/domain/PlayerName.java index 67427d5ed2..d27f0914f2 100644 --- a/src/main/java/ladder/domain/PlayerName.java +++ b/src/main/java/ladder/domain/PlayerName.java @@ -1,11 +1,10 @@ package ladder.domain; public class PlayerName { + static final String RESERVED_NAME_MESSAGE = "all은 사용할 수 없는 이름입니다."; private static final int NAME_LENGTH_UPPER_BOUND = 5; - private static final String INVALID_NAME_LENGTH_MESSAGE = - "이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; + static final String INVALID_NAME_LENGTH_MESSAGE = "이름은 1자 이상, " + NAME_LENGTH_UPPER_BOUND + "자 이하여야 합니다."; private static final String RESERVED_NAME = "all"; - private static final String RESERVED_NAME_MESSAGE = "all은 사용할 수 없는 이름입니다."; private final String value; diff --git a/src/main/java/ladder/domain/Players.java b/src/main/java/ladder/domain/Players.java index 44b279cf12..e382883e94 100644 --- a/src/main/java/ladder/domain/Players.java +++ b/src/main/java/ladder/domain/Players.java @@ -11,13 +11,13 @@ import java.util.stream.IntStream; public class Players { + static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; + static final String INVALID_PLAYER_MESSAGE = "해당 위치에 있는 참가자가 존재하지 않습니다."; private static final int PLAYERS_SIZE_LOWER_BOUND = 2; private static final int PLAYERS_SIZE_UPPER_BOUND = 20; - private static final String INVALID_PLAYERS_SIZE_MESSAGE = + static final String INVALID_PLAYERS_SIZE_MESSAGE = "참가자는 최소 " + PLAYERS_SIZE_LOWER_BOUND + "명, 최대 " + PLAYERS_SIZE_UPPER_BOUND + "명이어야 합니다."; - private static final String DUPLICATE_NAMES_MESSAGE = "참가자의 이름은 중복되지 않아야 합니다."; - private static final String INVALID_PLAYER_MESSAGE = "해당 위치에 있는 참가자가 존재하지 않습니다."; - + private final List players; private Players(final List players) { diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index c61ddec1da..0b38c3ae20 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -9,9 +9,9 @@ public class Position { private static final int POSITION_VALUE_LOWER_BOUND = 0; private static final int POSITION_VALUE_UPPER_BOUND = 20; - private static final int MOVE_COUNT = 1; - private static final String INVALID_VALUE_MESSAGE = + static final String INVALID_VALUE_MESSAGE = "위치값은 " + POSITION_VALUE_LOWER_BOUND + "이상, " + POSITION_VALUE_UPPER_BOUND + "미만이어야 합니다."; + private static final int MOVE_COUNT = 1; private static final Position EMPTY = new Position(Integer.MIN_VALUE); private static final Map CACHE = new HashMap<>(); diff --git a/src/test/java/ladder/domain/HeightTest.java b/src/test/java/ladder/domain/HeightTest.java index 70c2942cd2..2801a7a931 100644 --- a/src/test/java/ladder/domain/HeightTest.java +++ b/src/test/java/ladder/domain/HeightTest.java @@ -1,5 +1,6 @@ package ladder.domain; +import static ladder.domain.Height.INVALID_HEIGHT_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -13,7 +14,7 @@ public class HeightTest { void 높이는_올바른_입력값이_아니라면_예외를_던진다(final String value) { assertThatThrownBy(() -> new Height(value)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("높이는 1이상, 100이하의 값이어야 합니다."); + .hasMessage(INVALID_HEIGHT_MESSAGE); } @ParameterizedTest(name = "높이가 정상적으로 생성된다. 입력값: {0}") diff --git a/src/test/java/ladder/domain/ItemNameTest.java b/src/test/java/ladder/domain/ItemNameTest.java index e92a079615..1ef81f2bd5 100644 --- a/src/test/java/ladder/domain/ItemNameTest.java +++ b/src/test/java/ladder/domain/ItemNameTest.java @@ -1,5 +1,6 @@ package ladder.domain; +import static ladder.domain.ItemName.INVALID_NAME_LENGTH_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -16,7 +17,7 @@ public class ItemNameTest { void 이름이_NULL_빈값_6자_이상인_경우_예외를_던진다(final String name) { assertThatThrownBy(() -> new ItemName(name)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("실행 결과명은 1자 이상, 5자 이하여야 합니다."); + .hasMessage(INVALID_NAME_LENGTH_MESSAGE); } @Test diff --git a/src/test/java/ladder/domain/ItemsTest.java b/src/test/java/ladder/domain/ItemsTest.java index dd0446fab7..f1f9746340 100644 --- a/src/test/java/ladder/domain/ItemsTest.java +++ b/src/test/java/ladder/domain/ItemsTest.java @@ -1,5 +1,7 @@ package ladder.domain; +import static ladder.domain.Items.INVALID_ITEM_COUNT_MESSAGE; +import static ladder.domain.Items.INVALID_ITEM_MESSAGE; import static ladder.domain.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -17,7 +19,7 @@ public class ItemsTest { void 실행결과는_참가인원과_동일한_개수가_아니라면_예외를_던진다() { assertThatThrownBy(() -> Items.of(List.of("item1", "item2"), 3)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("참가인원과 동일한 개수의 실행결과를 입력해야 합니다."); + .hasMessage(INVALID_ITEM_COUNT_MESSAGE); } @Test @@ -26,7 +28,7 @@ public class ItemsTest { assertThatThrownBy(() -> items.findByPosition(valueOf(10))) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("해당 위치에 있는 아이템이 존재하지 않습니다."); + .hasMessage(INVALID_ITEM_MESSAGE); } @Test diff --git a/src/test/java/ladder/domain/LadderGameResultTest.java b/src/test/java/ladder/domain/LadderGameResultTest.java index 04a8c2b407..e5deb958ee 100644 --- a/src/test/java/ladder/domain/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/LadderGameResultTest.java @@ -1,5 +1,6 @@ package ladder.domain; +import static ladder.domain.LadderGameResult.INVALID_PLAYER_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; @@ -21,7 +22,7 @@ public class LadderGameResultTest { assertThatThrownBy(() -> ladderGameResult.get("whois")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("사다리 게임에 참가한 사람의 이름을 입력해야합니다."); + .hasMessage(INVALID_PLAYER_MESSAGE); } @Test diff --git a/src/test/java/ladder/domain/PlayerNameTest.java b/src/test/java/ladder/domain/PlayerNameTest.java index f8a01c7739..ec3762d2c1 100644 --- a/src/test/java/ladder/domain/PlayerNameTest.java +++ b/src/test/java/ladder/domain/PlayerNameTest.java @@ -1,6 +1,8 @@ package ladder.domain; +import static ladder.domain.PlayerName.INVALID_NAME_LENGTH_MESSAGE; +import static ladder.domain.PlayerName.RESERVED_NAME_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -22,7 +24,7 @@ public class PlayerNameTest { void 이름이_NULL_빈값_6자_이상인_경우_예외를_던진다(final String name) { assertThatThrownBy(() -> new PlayerName(name)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("이름은 1자 이상, 5자 이하여야 합니다."); + .hasMessage(INVALID_NAME_LENGTH_MESSAGE); } @Test @@ -44,6 +46,6 @@ public class PlayerNameTest { void all을_이름으로_사용할_수_없다() { assertThatThrownBy(() -> new PlayerName("all")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("all은 사용할 수 없는 이름입니다."); + .hasMessage(RESERVED_NAME_MESSAGE); } } diff --git a/src/test/java/ladder/domain/PlayersTest.java b/src/test/java/ladder/domain/PlayersTest.java index 54b7b5391e..15adcb68d5 100644 --- a/src/test/java/ladder/domain/PlayersTest.java +++ b/src/test/java/ladder/domain/PlayersTest.java @@ -1,5 +1,9 @@ package ladder.domain; +import static ladder.domain.Players.DUPLICATE_NAMES_MESSAGE; +import static ladder.domain.Players.INVALID_PLAYERS_SIZE_MESSAGE; +import static ladder.domain.Players.INVALID_PLAYER_MESSAGE; +import static ladder.domain.Position.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -31,7 +35,7 @@ public class PlayersTest { assertThatThrownBy(() -> Players.from(names)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("참가자는 최소 2명, 최대 20명이어야 합니다."); + .hasMessage(INVALID_PLAYERS_SIZE_MESSAGE); } @Test @@ -43,7 +47,7 @@ public class PlayersTest { void 참가자의_이름은_중복되는_경우_예외를_던진다() { assertThatThrownBy(() -> Players.from(List.of("name", "name"))) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("참가자의 이름은 중복되지 않아야 합니다."); + .hasMessage(DUPLICATE_NAMES_MESSAGE); } @Test @@ -57,11 +61,20 @@ public class PlayersTest { void 입력받은_위치에_해당하는_참가자를_반환한다() { final Players players = Players.from(List.of("name1", "name2")); - final Player result = players.findByPosition(Position.valueOf(0)); + final Player result = players.findByPosition(valueOf(0)); assertThat(result.getName()).isEqualTo("name1"); } + @Test + void 입력받은_위치에_참가자가_없는경우_예외를_던진다() { + final Players players = Players.from(List.of("name1", "name2")); + + assertThatThrownBy(() -> players.findByPosition(valueOf(5))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(INVALID_PLAYER_MESSAGE); + } + @Test void 모든_참가자의_이름을_반환한다() { final Players players = Players.from(List.of("name1", "name2")); @@ -82,10 +95,10 @@ public class PlayersTest { final Map result = players.play(ladder); assertThat(result).containsExactly( - entry(players.findByPosition(Position.valueOf(0)), Position.valueOf(1)), - entry(players.findByPosition(Position.valueOf(1)), Position.valueOf(3)), - entry(players.findByPosition(Position.valueOf(2)), Position.valueOf(2)), - entry(players.findByPosition(Position.valueOf(3)), Position.valueOf(0)) + entry(players.findByPosition(valueOf(0)), valueOf(1)), + entry(players.findByPosition(valueOf(1)), valueOf(3)), + entry(players.findByPosition(valueOf(2)), valueOf(2)), + entry(players.findByPosition(valueOf(3)), valueOf(0)) ); } } diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java index 432b45cbcc..2e42049002 100644 --- a/src/test/java/ladder/domain/PositionTest.java +++ b/src/test/java/ladder/domain/PositionTest.java @@ -1,5 +1,6 @@ package ladder.domain; +import static ladder.domain.Position.INVALID_VALUE_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -19,7 +20,7 @@ public class PositionTest { void 위치값이_0보다_작거나_20이상인_경우_예외를_던진다(final int value) { assertThatThrownBy(() -> Position.valueOf(value)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("위치값은 0이상, 20미만이어야 합니다."); + .hasMessage(INVALID_VALUE_MESSAGE); } @ParameterizedTest(name = "올바른 위치값을 받으면 정상적으로 생성된다. 입력값: {0}") @@ -41,7 +42,7 @@ public class PositionTest { void 허용범위_밖_위치값을_입력하는_경우_예외를_던진다() { assertThatThrownBy(() -> Position.range(21)) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("위치값은 0이상, 20미만이어야 합니다."); + .hasMessage(INVALID_VALUE_MESSAGE); } @Test From 2aee49b77c6470b7792f95a5ee27d2d946348f46 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 26 Feb 2023 00:23:06 +0900 Subject: [PATCH 65/71] =?UTF-8?q?fix:=20=EA=B2=B0=EA=B3=BC=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=A0=20=EB=95=8C=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=9D=B4=EB=A6=84=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EC=8B=9C=20=EC=A2=85=EB=A3=8C=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LadderGameController.java | 8 +++++- .../java/ladder/domain/LadderGameResult.java | 17 ++++++++++- .../ladder/domain/LadderGameResultTest.java | 28 ++++++++++++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 905868280e..219f6dfd6d 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -53,12 +53,18 @@ private T repeatUntilGetValidInput(final Supplier inputReader) { private void printLadderGameResult(final LadderGameResult ladderGameResult) { LadderGameCommand command = LadderGameCommand.SINGLE; while (command.isContinued()) { - final String name = repeatUntilGetValidInput(inputView::readPlayerName); + final String name = repeatUntilGetValidInput(() -> getValidPlayerName(ladderGameResult)); command = LadderGameCommand.from(name); outputView.printLadderGameResult(ladderGameResult, name); } } + private String getValidPlayerName(final LadderGameResult ladderGameResult) { + final String name = inputView.readPlayerName(); + ladderGameResult.validatePlayerName(name); + return name; + } + private enum LadderGameCommand { MULTIPLE, SINGLE; diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 40480e345d..44509f8196 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -6,7 +6,7 @@ public class LadderGameResult { static final String INVALID_PLAYER_MESSAGE = "사다리 게임에 참가한 사람의 이름을 입력해야합니다."; private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; - + private final Map result; public LadderGameResult(final Map result) { @@ -44,4 +44,19 @@ private Player findPlayer(final String name) { .findFirst() .orElseThrow(() -> new IllegalArgumentException(INVALID_PLAYER_MESSAGE)); } + + public void validatePlayerName(final String name) { + if (isInvalidPlayerName(name) && isNotReservedName(name)) { + throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); + } + } + + private boolean isInvalidPlayerName(final String name) { + return this.result.keySet().stream() + .noneMatch(player -> player.isSameName(name)); + } + + private boolean isNotReservedName(final String name) { + return !MULTIPLE_RESULT_RESERVED_NAME.equals(name); + } } diff --git a/src/test/java/ladder/domain/LadderGameResultTest.java b/src/test/java/ladder/domain/LadderGameResultTest.java index e5deb958ee..968d9bc7ea 100644 --- a/src/test/java/ladder/domain/LadderGameResultTest.java +++ b/src/test/java/ladder/domain/LadderGameResultTest.java @@ -2,6 +2,7 @@ import static ladder.domain.LadderGameResult.INVALID_PLAYER_MESSAGE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; @@ -9,13 +10,15 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class LadderGameResultTest { @Test - void 사다리게임에_참가하지_않은_사람을_입력하면_예외를_던진다() { + void 사다리게임에_참가하지_않은_사람의_게임_결과를_조회한다면_예외를_던진다() { final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( Player.of("name", 0), Item.of("1000", 0) )); @@ -47,4 +50,27 @@ public class LadderGameResultTest { assertThat(result).contains(entry("name", "0"), entry("name2", "1000")); } + + @ParameterizedTest(name = "입력한 참가자가 존재하거나 예약어인 경우 예외를 던지지 않는다. 입력값: {0}") + @ValueSource(strings = {"name", "all"}) + void 입력한_참가자가_존재하거나_예약어인_경우_예외를_던지지_않는다(final String name) { + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( + Player.of("name", 0), Item.of("0", 0), + Player.of("name2", 1), Item.of("1000", 1) + )); + + assertThatNoException().isThrownBy(() -> ladderGameResult.validatePlayerName(name)); + } + + @Test + void 입력한_참가자가_존재하지_않는다면_예외를_던진다() { + final LadderGameResult ladderGameResult = new LadderGameResult(Map.of( + Player.of("name", 0), Item.of("0", 0), + Player.of("name2", 1), Item.of("1000", 1) + )); + + assertThatThrownBy(() -> ladderGameResult.validatePlayerName("noName")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(INVALID_PLAYER_MESSAGE); + } } From 661cdf63713f3263f05f0b8361b5e4ffa0f0a22a Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 26 Feb 2023 00:25:40 +0900 Subject: [PATCH 66/71] =?UTF-8?q?refactor:=20=EA=B2=B0=EA=B3=BC=EB=A5=BC?= =?UTF-8?q?=20=EC=9C=84=ED=95=9C=20=EC=9E=85=EB=A0=A5=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=20=EB=B6=80=EB=B6=84=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/LadderGameResult.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/ladder/domain/LadderGameResult.java b/src/main/java/ladder/domain/LadderGameResult.java index 44509f8196..a65c489ba4 100644 --- a/src/main/java/ladder/domain/LadderGameResult.java +++ b/src/main/java/ladder/domain/LadderGameResult.java @@ -46,17 +46,17 @@ private Player findPlayer(final String name) { } public void validatePlayerName(final String name) { - if (isInvalidPlayerName(name) && isNotReservedName(name)) { + if (isNotReservedName(name) && isInvalidPlayerName(name)) { throw new IllegalArgumentException(INVALID_PLAYER_MESSAGE); } } + private boolean isNotReservedName(final String name) { + return !MULTIPLE_RESULT_RESERVED_NAME.equals(name); + } + private boolean isInvalidPlayerName(final String name) { return this.result.keySet().stream() .noneMatch(player -> player.isSameName(name)); } - - private boolean isNotReservedName(final String name) { - return !MULTIPLE_RESULT_RESERVED_NAME.equals(name); - } } From 3e3c4b932d63a9ee9123ef9d08a1a81411480b6a Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 26 Feb 2023 15:09:27 +0900 Subject: [PATCH 67/71] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20this=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Position.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index 0b38c3ae20..2a0083564d 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -12,7 +12,7 @@ public class Position { static final String INVALID_VALUE_MESSAGE = "위치값은 " + POSITION_VALUE_LOWER_BOUND + "이상, " + POSITION_VALUE_UPPER_BOUND + "미만이어야 합니다."; private static final int MOVE_COUNT = 1; - private static final Position EMPTY = new Position(Integer.MIN_VALUE); + private static final Position NULL = new Position(Integer.MIN_VALUE); private static final Map CACHE = new HashMap<>(); static { @@ -49,11 +49,11 @@ public static List range(final int endExclusive) { } public Position getPrevious() { - return CACHE.getOrDefault(this.value - MOVE_COUNT, EMPTY); + return CACHE.getOrDefault(value - MOVE_COUNT, NULL); } public Position getNext() { - return CACHE.getOrDefault(this.value + MOVE_COUNT, EMPTY); + return CACHE.getOrDefault(value + MOVE_COUNT, NULL); } public int getValue() { From 7e28ac75a0db076082537bebdb1c1982682cfacc Mon Sep 17 00:00:00 2001 From: greeng00se Date: Sun, 26 Feb 2023 16:49:17 +0900 Subject: [PATCH 68/71] =?UTF-8?q?refactor:=20LadderMessageGenerator=20?= =?UTF-8?q?=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=B6=88=EA=B0=80=EB=8A=A5=20=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/view/LadderMessageGenerator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/ladder/view/LadderMessageGenerator.java b/src/main/java/ladder/view/LadderMessageGenerator.java index dcc428bfbf..fd614ae09f 100644 --- a/src/main/java/ladder/view/LadderMessageGenerator.java +++ b/src/main/java/ladder/view/LadderMessageGenerator.java @@ -14,6 +14,9 @@ class LadderMessageGenerator { private static final String EMPTY_SYMBOL = " "; private static final String LINE_STATUS_MESSAGE_FORMAT = "%s|"; + private LadderMessageGenerator() { + } + public static String generate(final int maxNameLength, final List lines) { return lines.stream() .map(line -> generateLineMessage(maxNameLength, line)) From 08dc6db70af050b286c05285fdef6f220292eb44 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 27 Feb 2023 08:35:28 +0900 Subject: [PATCH 69/71] =?UTF-8?q?refactor:=20LadderGameCommand=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ladder/controller/LadderGameCommand.java | 19 ++++++++++++++ .../controller/LadderGameController.java | 17 ------------ .../controller/LadderGameCommandTest.java | 26 +++++++++++++++++++ 3 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 src/main/java/ladder/controller/LadderGameCommand.java create mode 100644 src/test/java/ladder/controller/LadderGameCommandTest.java diff --git a/src/main/java/ladder/controller/LadderGameCommand.java b/src/main/java/ladder/controller/LadderGameCommand.java new file mode 100644 index 0000000000..0afcff6617 --- /dev/null +++ b/src/main/java/ladder/controller/LadderGameCommand.java @@ -0,0 +1,19 @@ +package ladder.controller; + +enum LadderGameCommand { + MULTIPLE, + SINGLE; + + private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; + + public static LadderGameCommand from(final String name) { + if (MULTIPLE_RESULT_RESERVED_NAME.equals(name)) { + return MULTIPLE; + } + return SINGLE; + } + + public boolean isContinued() { + return this == SINGLE; + } +} diff --git a/src/main/java/ladder/controller/LadderGameController.java b/src/main/java/ladder/controller/LadderGameController.java index 219f6dfd6d..26b090660b 100644 --- a/src/main/java/ladder/controller/LadderGameController.java +++ b/src/main/java/ladder/controller/LadderGameController.java @@ -65,21 +65,4 @@ private String getValidPlayerName(final LadderGameResult ladderGameResult) { return name; } - private enum LadderGameCommand { - MULTIPLE, - SINGLE; - - private static final String MULTIPLE_RESULT_RESERVED_NAME = "all"; - - public static LadderGameCommand from(final String name) { - if (MULTIPLE_RESULT_RESERVED_NAME.equals(name)) { - return MULTIPLE; - } - return SINGLE; - } - - public boolean isContinued() { - return this == SINGLE; - } - } } diff --git a/src/test/java/ladder/controller/LadderGameCommandTest.java b/src/test/java/ladder/controller/LadderGameCommandTest.java new file mode 100644 index 0000000000..0ae02aa0c3 --- /dev/null +++ b/src/test/java/ladder/controller/LadderGameCommandTest.java @@ -0,0 +1,26 @@ +package ladder.controller; + +import static ladder.controller.LadderGameCommand.from; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class LadderGameCommandTest { + + @ParameterizedTest(name = "all을 입력하면 MULTIPLE을 반환하고 나머지의 경우 SINGLE을 반환한다. 입력: {0}, 결과: {1}") + @CsvSource({"all,MULTIPLE", "herb,SINGLE"}) + void all을_입력하면_MULTIPLE을_반환하고_나머지의_경우_SINGLE을_반환한다(final String input, final LadderGameCommand command) { + assertThat(from(input)).isEqualTo(command); + } + + @ParameterizedTest(name = "Command에 따라서 결과출력을 계속할지 결정한다. 커맨드: {0}, 결과: {1}") + @CsvSource({"MULTIPLE,false", "SINGLE,true"}) + void Command에_따라서_결과출력을_계속할지_결정한다(final LadderGameCommand command, final boolean result) { + assertThat(command.isContinued()).isEqualTo(result); + } +} From e0c224a9b5a9a502edf46f2835a91b4edf5642c8 Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 27 Feb 2023 08:35:39 +0900 Subject: [PATCH 70/71] =?UTF-8?q?test:=20DisplayNameGeneration=20=EB=B9=A0?= =?UTF-8?q?=EC=A7=84=20=EB=B6=80=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/ladder/domain/HeightTest.java | 4 ++++ src/test/java/ladder/domain/ItemNameTest.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/test/java/ladder/domain/HeightTest.java b/src/test/java/ladder/domain/HeightTest.java index 2801a7a931..21b0fa2663 100644 --- a/src/test/java/ladder/domain/HeightTest.java +++ b/src/test/java/ladder/domain/HeightTest.java @@ -4,9 +4,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class HeightTest { @ParameterizedTest(name = "높이는 1이상, 100이하의 값이 아닌 경우 예외를 던진다. 입력값: \"{0}\"") diff --git a/src/test/java/ladder/domain/ItemNameTest.java b/src/test/java/ladder/domain/ItemNameTest.java index 1ef81f2bd5..5b90aed897 100644 --- a/src/test/java/ladder/domain/ItemNameTest.java +++ b/src/test/java/ladder/domain/ItemNameTest.java @@ -4,11 +4,15 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class ItemNameTest { @ParameterizedTest(name = "이름이 NULL, 빈값, 6자 이상인 경우 예외를 던진다. 입력값: \"{0}\"") From 8206c8b8d4423a3e16cbcab2987199213043bffe Mon Sep 17 00:00:00 2001 From: greeng00se Date: Mon, 27 Feb 2023 11:02:07 +0900 Subject: [PATCH 71/71] =?UTF-8?q?refactor:=20Position=EC=9D=84=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8A=94=20=EC=9E=85=EC=9E=A5=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AA=85=ED=99=95=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ladder/domain/Line.java | 30 +++++++++++++---- src/main/java/ladder/domain/Position.java | 20 +++++++++-- src/test/java/ladder/domain/PositionTest.java | 33 ++++++++++++++----- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/main/java/ladder/domain/Line.java b/src/main/java/ladder/domain/Line.java index d2d4856826..3fbbbcfa28 100644 --- a/src/main/java/ladder/domain/Line.java +++ b/src/main/java/ladder/domain/Line.java @@ -1,5 +1,8 @@ package ladder.domain; +import static ladder.domain.LineStatus.DISCONNECTED; +import static ladder.domain.LineStatus.from; + import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -24,7 +27,10 @@ public static Line generate(final BooleanGenerator booleanGenerator, final int w } private static LineStatus getPreviousLineStatus(final Map statuses, final Position position) { - return statuses.getOrDefault(position.getPrevious(), LineStatus.DISCONNECTED); + if (position.hasPrevious()) { + return statuses.get(position.getPrevious()); + } + return DISCONNECTED; } private static LineStatus generateLineStatus( @@ -33,25 +39,35 @@ private static LineStatus generateLineStatus( ) { final boolean status = booleanGenerator.generate(); if (previousLineStatus.isDisconnected()) { - return LineStatus.from(status); + return from(status); } - return LineStatus.DISCONNECTED; + return DISCONNECTED; } public Position play(final Position position) { - if (isConnected(position.getPrevious())) { + if (isPreviousConnected(position)) { return position.getPrevious(); } - if (isConnected(position)) { + if (isNextConnected(position)) { return position.getNext(); } return position; } - private boolean isConnected(final Position position) { - return statuses.getOrDefault(position, LineStatus.DISCONNECTED).isConnected(); + private boolean isPreviousConnected(final Position position) { + if (position.hasPrevious()) { + return statuses.getOrDefault(position.getPrevious(), DISCONNECTED).isConnected(); + } + return false; + } + + private boolean isNextConnected(final Position position) { + if (position.hasNext()) { + return statuses.getOrDefault(position, DISCONNECTED).isConnected(); + } + return false; } public List getLine() { diff --git a/src/main/java/ladder/domain/Position.java b/src/main/java/ladder/domain/Position.java index 2a0083564d..dd5e60fdbc 100644 --- a/src/main/java/ladder/domain/Position.java +++ b/src/main/java/ladder/domain/Position.java @@ -48,12 +48,28 @@ public static List range(final int endExclusive) { .collect(Collectors.toList()); } + public boolean hasPrevious() { + return !isInvalidPosition(value - MOVE_COUNT); + } + + public boolean hasNext() { + return !isInvalidPosition(value + MOVE_COUNT); + } + public Position getPrevious() { - return CACHE.getOrDefault(value - MOVE_COUNT, NULL); + final Position position = CACHE.get(value - MOVE_COUNT); + if (position == null) { + throw new IllegalArgumentException(INVALID_VALUE_MESSAGE); + } + return position; } public Position getNext() { - return CACHE.getOrDefault(value + MOVE_COUNT, NULL); + final Position position = CACHE.get(value + MOVE_COUNT); + if (position == null) { + throw new IllegalArgumentException(INVALID_VALUE_MESSAGE); + } + return position; } public int getValue() { diff --git a/src/test/java/ladder/domain/PositionTest.java b/src/test/java/ladder/domain/PositionTest.java index 2e42049002..9601dd02d4 100644 --- a/src/test/java/ladder/domain/PositionTest.java +++ b/src/test/java/ladder/domain/PositionTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @SuppressWarnings("NonAsciiCharacters") @@ -45,13 +46,29 @@ public class PositionTest { .hasMessage(INVALID_VALUE_MESSAGE); } + @ParameterizedTest + @CsvSource({"1,true", "0,false"}) + void 이전값이_올바른_값이라면_참_올바르지_않다면_거짓을_반환한다(final int value, final boolean result) { + final Position position = Position.valueOf(value); + + assertThat(position.hasPrevious()).isEqualTo(result); + } + + @ParameterizedTest + @CsvSource({"18,true", "19,false"}) + void 다음값이_올바른_값이라면_참_올바르지_않다면_거짓을_반환한다(final int value, final boolean result) { + final Position position = Position.valueOf(value); + + assertThat(position.hasNext()).isEqualTo(result); + } + @Test - void 이전_값이_존재하지_않는_경우_사용할_수_없는_위치값을_반환한다() { + void 이전_값이_올바른_값이_아닌_경우_예외를_던진다() { final Position position = Position.valueOf(0); - final Position previousPosition = position.getPrevious(); - - assertThat(previousPosition.getValue()).isEqualTo(Integer.MIN_VALUE); + assertThatThrownBy(position::getPrevious) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(INVALID_VALUE_MESSAGE); } @Test @@ -62,12 +79,12 @@ public class PositionTest { } @Test - void 다음_값이_존재하지_않는_경우_사용할_수_없는_위치값을_반환한다() { + void 다음_값이_올바른_값이_아닌_경우_예외를_던진다() { final Position position = Position.valueOf(19); - final Position nextPosition = position.getNext(); - - assertThat(nextPosition.getValue()).isEqualTo(Integer.MIN_VALUE); + assertThatThrownBy(position::getNext) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(INVALID_VALUE_MESSAGE); } @Test