From adb3d07a52bf4769049c9415e0b2f4b97a2763ed Mon Sep 17 00:00:00 2001 From: hamhyeongju Date: Tue, 17 Sep 2024 11:10:49 +0900 Subject: [PATCH 01/10] feat : add basic code and test --- src/main/java/Ladder.java | 20 ++++- src/main/java/Row.java | 52 ++++++++++++ src/test/java/LadderTest.java | 60 +++++++++++++- src/test/java/RowTest.java | 152 ++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 4 deletions(-) create mode 100644 src/main/java/Row.java create mode 100644 src/test/java/RowTest.java diff --git a/src/main/java/Ladder.java b/src/main/java/Ladder.java index 0d2b070..f3c57ee 100644 --- a/src/main/java/Ladder.java +++ b/src/main/java/Ladder.java @@ -1,8 +1,22 @@ public class Ladder { - private final int[][] rows; + private final Row[] rows; - public Ladder(int row, int numberOfPerson) { - rows = new int[row][numberOfPerson]; + public Ladder(int numberOfRow, int numberOfPerson) { + rows = new Row[numberOfRow]; + for (int i = 0; i < numberOfRow; i++) { + rows[i] = new Row(numberOfPerson); + } + } + + public void drawLine(int row, int col) { + rows[row].drawLine(col); + } + + public int run(int position) { + for (int i = 0; i < rows.length; i++) { + position = rows[i].nextPosition(position); + } + return position; } } diff --git a/src/main/java/Row.java b/src/main/java/Row.java new file mode 100644 index 0000000..f1cf299 --- /dev/null +++ b/src/main/java/Row.java @@ -0,0 +1,52 @@ +public class Row { + int[] row; + + public Row(int numberOfPerson) { + validateNumberOfPerson(numberOfPerson); + row = new int[numberOfPerson]; + } + + public void drawLine(int startPosition) { + validateDrawLinePosition(startPosition); + row[startPosition] = 1; + row[startPosition + 1] = -1; + } + + public int nextPosition(int position) { + validatePosition(position); + + if (isRight(position)) { + return position + 1; + } + if (isLeft(position)) { + return position - 1; + } + return position; + } + + private boolean isLeft(int position) { + return row[position] == -1; + } + + private boolean isRight(int position) { + return row[position] == 1; + } + + private void validateNumberOfPerson(int numberOfPerson) { + if (numberOfPerson < 1) { + throw new IllegalArgumentException("참여 인원은 1명 이상이어야 합니다."); + } + } + + private void validatePosition(int position) { + if (position >= row.length || position < 0) { + throw new IllegalArgumentException("유효하지 않은 위치입니다."); + } + } + + private void validateDrawLinePosition(int startPosition) { + if (startPosition >= row.length - 1 || startPosition < 0 || row[startPosition] == -1 || row[startPosition + 1] == 1) { + throw new IllegalArgumentException("사다리를 그릴 수 없는 위치입니다."); + } + } +} \ No newline at end of file diff --git a/src/test/java/LadderTest.java b/src/test/java/LadderTest.java index 741a915..0279a0e 100644 --- a/src/test/java/LadderTest.java +++ b/src/test/java/LadderTest.java @@ -1,5 +1,63 @@ -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; class LadderTest { + @Test + void 사다리_생성_확인() { + //given + int numberOfRow = 3; + int numberOfPerson = 5; + + //when + Ladder ladder = new Ladder(numberOfRow, numberOfPerson); + + //then + assertThat(ladder).isNotNull(); + } + + @Test + void 사다리_사람_예외_처리_확인() { + //when + int numberOfPerson = 3; + Ladder ladder = new Ladder(1, numberOfPerson); + + //given + int nthOfPerson = 4; + + //then + assertThatThrownBy(() -> ladder.run(nthOfPerson)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_결과_확인() { + //when + int numberOfPerson = 4; + int row = 3; + Ladder ladder = new Ladder(row, numberOfPerson); + + ladder.drawLine(0,0); + ladder.drawLine(1,1); + ladder.drawLine(2,0); + + //given + int nthOfPerson = 0; + + //then + assertThat(ladder.run(nthOfPerson)).isEqualTo(2); + + //given + nthOfPerson = 1; + + //then + assertThat(ladder.run(nthOfPerson)).isEqualTo(1); + + //given + nthOfPerson = 2; + + //then + assertThat(ladder.run(nthOfPerson)).isEqualTo(0); + } } \ No newline at end of file diff --git a/src/test/java/RowTest.java b/src/test/java/RowTest.java new file mode 100644 index 0000000..ffaa72e --- /dev/null +++ b/src/test/java/RowTest.java @@ -0,0 +1,152 @@ +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + +class RowTest { + + @Test + void 한_칸_사다리_이동() { + //when + int numberOfPerson = 1; + Row row = new Row(numberOfPerson); + + //given + int position = 0; + + //then + assertThat(row.nextPosition(position)).isEqualTo(0); + } + + @Test + void 두_칸_사다리_선_이동() { + //when + int numberOfPerson = 2; + Row row = new Row(numberOfPerson); + row.drawLine(0); + + //given + int position = 0; + + //then + assertThat(row.nextPosition(position)).isEqualTo(1); + + //given + position = 1; + + //then + assertThat(row.nextPosition(position)).isEqualTo(0); + } + + @Test + void 세_칸_사다리_선_이동() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + row.drawLine(0); + + //given + int position = 0; + + //then + assertThat(row.nextPosition(position)).isEqualTo(1); + + //given + position = 1; + + //then + assertThat(row.nextPosition(position)).isEqualTo(0); + + //given + position = 2; + + //then + assertThat(row.nextPosition(position)).isEqualTo(2); + } + + @Test + void 사다리_사람수_예외_처리() { + assertThatThrownBy(() -> new Row(0)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_최대_사람수_초과_예외() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + + //given + int position = 3; + + //then + assertThatThrownBy(() -> row.nextPosition(position)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_최소_사람수_미만_예외() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + + //given + int position = -1; + + //then + assertThatThrownBy(() -> row.nextPosition(position)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_그리기_위치_초과_예외() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + + //given + int position = 3; + + //then + assertThatThrownBy(() -> row.drawLine(position)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_그리기_위치_미만_예외() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + + //given + int position = -1; + + //then + assertThatThrownBy(() -> row.drawLine(position)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_그리기_좌측_선_중복_예외() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + row.drawLine(0); + + //then + assertThatThrownBy(() -> row.drawLine(1)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_그리기_우측_선_중복_예외() { + //when + int numberOfPerson = 3; + Row row = new Row(numberOfPerson); + row.drawLine(1); + + //then + assertThatThrownBy(() -> row.drawLine(0)) + .isInstanceOf(IllegalArgumentException.class); + + } +} \ No newline at end of file From 7c319083801ad786726bd531895a577c61198dfc Mon Sep 17 00:00:00 2001 From: hamhyeongju Date: Thu, 19 Sep 2024 17:01:21 +0900 Subject: [PATCH 02/10] move : move domain to ladder package --- src/main/java/{ => ladder}/Ladder.java | 2 ++ src/main/java/{ => ladder}/Row.java | 2 ++ src/test/java/{ => ladder}/LadderTest.java | 2 ++ src/test/java/{ => ladder}/RowTest.java | 2 ++ 4 files changed, 8 insertions(+) rename src/main/java/{ => ladder}/Ladder.java (96%) rename src/main/java/{ => ladder}/Row.java (98%) rename src/test/java/{ => ladder}/LadderTest.java (98%) rename src/test/java/{ => ladder}/RowTest.java (99%) diff --git a/src/main/java/Ladder.java b/src/main/java/ladder/Ladder.java similarity index 96% rename from src/main/java/Ladder.java rename to src/main/java/ladder/Ladder.java index f3c57ee..de2b84e 100644 --- a/src/main/java/Ladder.java +++ b/src/main/java/ladder/Ladder.java @@ -1,3 +1,5 @@ +package ladder; + public class Ladder { private final Row[] rows; diff --git a/src/main/java/Row.java b/src/main/java/ladder/Row.java similarity index 98% rename from src/main/java/Row.java rename to src/main/java/ladder/Row.java index f1cf299..00ada79 100644 --- a/src/main/java/Row.java +++ b/src/main/java/ladder/Row.java @@ -1,3 +1,5 @@ +package ladder; + public class Row { int[] row; diff --git a/src/test/java/LadderTest.java b/src/test/java/ladder/LadderTest.java similarity index 98% rename from src/test/java/LadderTest.java rename to src/test/java/ladder/LadderTest.java index 0279a0e..0328fdd 100644 --- a/src/test/java/LadderTest.java +++ b/src/test/java/ladder/LadderTest.java @@ -1,3 +1,5 @@ +package ladder; + import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/RowTest.java b/src/test/java/ladder/RowTest.java similarity index 99% rename from src/test/java/RowTest.java rename to src/test/java/ladder/RowTest.java index ffaa72e..c72ad5e 100644 --- a/src/test/java/RowTest.java +++ b/src/test/java/ladder/RowTest.java @@ -1,3 +1,5 @@ +package ladder; + import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; From 1b840fa788394db9d5344041187191df057d6b33 Mon Sep 17 00:00:00 2001 From: hamhyeongju Date: Fri, 20 Sep 2024 15:26:00 +0900 Subject: [PATCH 03/10] refactor : change access modifier of row to private and add final keyword in Row class --- src/main/java/ladder/Row.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ladder/Row.java b/src/main/java/ladder/Row.java index 00ada79..09203ad 100644 --- a/src/main/java/ladder/Row.java +++ b/src/main/java/ladder/Row.java @@ -1,7 +1,7 @@ package ladder; public class Row { - int[] row; + private final int[] row; public Row(int numberOfPerson) { validateNumberOfPerson(numberOfPerson); From 1fe87579662060393942a79a887bb54c778b442b Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Tue, 24 Sep 2024 09:40:40 +0900 Subject: [PATCH 04/10] [feat] : 2nd seminar practice --- src/main/java/ladder/Direction.java | 16 ++++ src/main/java/ladder/ExceptionMessage.java | 19 +++++ src/main/java/ladder/GreaterThanOne.java | 25 +++++++ src/main/java/ladder/Ladder.java | 24 ------ src/main/java/ladder/LadderGame.java | 22 ++++++ src/main/java/ladder/LadderRunner.java | 17 +++++ src/main/java/ladder/Node.java | 51 +++++++++++++ src/main/java/ladder/Position.java | 45 ++++++++++++ src/main/java/ladder/Row.java | 70 ++++++++++-------- .../java/ladder/creator/LadderCreator.java | 25 +++++++ src/test/java/ladder/LadderGameTest.java | 69 ++++++++++++++++++ src/test/java/ladder/LadderTest.java | 65 ----------------- src/test/java/ladder/NodeTest.java | 43 +++++++++++ src/test/java/ladder/RowTest.java | 73 ++++++++++--------- 14 files changed, 409 insertions(+), 155 deletions(-) create mode 100644 src/main/java/ladder/Direction.java create mode 100644 src/main/java/ladder/ExceptionMessage.java create mode 100644 src/main/java/ladder/GreaterThanOne.java delete mode 100644 src/main/java/ladder/Ladder.java create mode 100644 src/main/java/ladder/LadderGame.java create mode 100644 src/main/java/ladder/LadderRunner.java create mode 100644 src/main/java/ladder/Node.java create mode 100644 src/main/java/ladder/Position.java create mode 100644 src/main/java/ladder/creator/LadderCreator.java create mode 100644 src/test/java/ladder/LadderGameTest.java delete mode 100644 src/test/java/ladder/LadderTest.java create mode 100644 src/test/java/ladder/NodeTest.java diff --git a/src/main/java/ladder/Direction.java b/src/main/java/ladder/Direction.java new file mode 100644 index 0000000..da92119 --- /dev/null +++ b/src/main/java/ladder/Direction.java @@ -0,0 +1,16 @@ +package ladder; + +public enum Direction { + + LEFT(-1), RIGHT(1), NONE(0); + + private final int value; + + Direction(int value) { + this.value = value; + } + + public int getValue() { + return value; + } +} diff --git a/src/main/java/ladder/ExceptionMessage.java b/src/main/java/ladder/ExceptionMessage.java new file mode 100644 index 0000000..f487157 --- /dev/null +++ b/src/main/java/ladder/ExceptionMessage.java @@ -0,0 +1,19 @@ +package ladder; + +public enum ExceptionMessage { + + INVALID_LADDER_POSITION("사다리 위치는 1이상 자연수입니다."), + INVALID_LADDER_NUMBER("사다리의 행과 열은 2 이상이어야 합니다."), + INVALID_POSITION("유효하지 않은 위치입니다."), + INVALID_DRAW_POSITION("사다리를 그릴 수 없는 위치입니다."); + + private final String message; + + ExceptionMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/ladder/GreaterThanOne.java b/src/main/java/ladder/GreaterThanOne.java new file mode 100644 index 0000000..f7ccc30 --- /dev/null +++ b/src/main/java/ladder/GreaterThanOne.java @@ -0,0 +1,25 @@ +package ladder; + +public class GreaterThanOne { + + private final int number; + + public GreaterThanOne(int number) { + this.number = number; + } + + public static GreaterThanOne from(int number) { + if (!isGreaterThanOne(number)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_LADDER_NUMBER.getMessage()); + } + return new GreaterThanOne(number); + } + + private static boolean isGreaterThanOne(int number) { + return number > 1; + } + + public int getNumber() { + return number; + } +} diff --git a/src/main/java/ladder/Ladder.java b/src/main/java/ladder/Ladder.java deleted file mode 100644 index de2b84e..0000000 --- a/src/main/java/ladder/Ladder.java +++ /dev/null @@ -1,24 +0,0 @@ -package ladder; - -public class Ladder { - - private final Row[] rows; - - public Ladder(int numberOfRow, int numberOfPerson) { - rows = new Row[numberOfRow]; - for (int i = 0; i < numberOfRow; i++) { - rows[i] = new Row(numberOfPerson); - } - } - - public void drawLine(int row, int col) { - rows[row].drawLine(col); - } - - public int run(int position) { - for (int i = 0; i < rows.length; i++) { - position = rows[i].nextPosition(position); - } - return position; - } -} diff --git a/src/main/java/ladder/LadderGame.java b/src/main/java/ladder/LadderGame.java new file mode 100644 index 0000000..a4a2498 --- /dev/null +++ b/src/main/java/ladder/LadderGame.java @@ -0,0 +1,22 @@ +package ladder; + +import ladder.creator.LadderCreator; + +public class LadderGame { + + private final LadderCreator ladderCreator; + + // todo Ladder 생성자 래퍼 클래스 -> 완 + public LadderGame(LadderCreator ladderCreator) { + this.ladderCreator = ladderCreator; + } + + // todo LadderCreator, LadderRunner -> 완 + + // todo 인덱스 값 Position 래퍼 클래스 -> 완 + public int run(Position position) { + LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); + ladderRunner.run(position); + return position.getPosition(); + } +} diff --git a/src/main/java/ladder/LadderRunner.java b/src/main/java/ladder/LadderRunner.java new file mode 100644 index 0000000..dc5739e --- /dev/null +++ b/src/main/java/ladder/LadderRunner.java @@ -0,0 +1,17 @@ +package ladder; + +public class LadderRunner { + + private final Row[] rows; + + public LadderRunner(Row[] rows) { + this.rows = rows; + } + + public int run(Position position) { + for (int i = 0; i < rows.length; i++) { + rows[i].nextPosition(position); + } + return position.getPosition(); + } +} diff --git a/src/main/java/ladder/Node.java b/src/main/java/ladder/Node.java new file mode 100644 index 0000000..f9ce729 --- /dev/null +++ b/src/main/java/ladder/Node.java @@ -0,0 +1,51 @@ +package ladder; + +import static ladder.Direction.*; + +public class Node { + + private Direction direction; + + private Node(Direction direction) { + this.direction = direction; + } + + public static Node from(Direction direction) { + return new Node(direction); + } + + public void setRightNode(Position position) { + direction = RIGHT; + } + + public void setLeftNode(Position position) { + direction = LEFT; + } + + public void move(Position position) { + if (isRight()) { + position.next(); + return; + } + if (isLeft()) { + position.prev(); + return; + } + } + + public boolean isAlreadySetDirection() { + return isNone(); + } + + private boolean isRight() { + return direction == RIGHT; + } + + private boolean isLeft() { + return direction == LEFT; + } + + private boolean isNone() { + return direction == NONE; + } +} diff --git a/src/main/java/ladder/Position.java b/src/main/java/ladder/Position.java new file mode 100644 index 0000000..0841bd7 --- /dev/null +++ b/src/main/java/ladder/Position.java @@ -0,0 +1,45 @@ +package ladder; + +public class Position { + + private int position; + + private Position(int position) { + this.position = position; + } + + public int getPosition() { + return position; + } + + public static Position from(int position) { + validatePosition(position); + return new Position(position); + } + + public boolean isBiggerThan(int position) { + return this.position > position; + } + + public boolean isSmallerThan(int position) { + return this.position < position; + } + + public void next() { + position++; + } + + public void prev() { + position--; + } + + private static void validatePosition(int position) { + if (!isPosition(position)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_LADDER_POSITION.getMessage()); + } + } + + private static boolean isPosition(int position) { + return position >= 0; + } +} diff --git a/src/main/java/ladder/Row.java b/src/main/java/ladder/Row.java index 09203ad..ba4dbb8 100644 --- a/src/main/java/ladder/Row.java +++ b/src/main/java/ladder/Row.java @@ -1,54 +1,62 @@ package ladder; +import static ladder.Direction.*; + public class Row { - private final int[] row; - public Row(int numberOfPerson) { - validateNumberOfPerson(numberOfPerson); - row = new int[numberOfPerson]; + // todo Node 클래스 분리 -> 완 + Node[] nodes; + + public Row(GreaterThanOne numberOfPerson) { + nodes = new Node[numberOfPerson.getNumber()]; + for (int i = 0; i < numberOfPerson.getNumber(); i++) { + nodes[i] = Node.from(NONE); + } } - public void drawLine(int startPosition) { + // todo 1, -1, 0 상수 리팩토링 -> 완 + public void drawLine(Position startPosition) { validateDrawLinePosition(startPosition); - row[startPosition] = 1; - row[startPosition + 1] = -1; + + setDirectionBetweenNextPosition(startPosition); } - public int nextPosition(int position) { + private void setDirectionBetweenNextPosition(Position position) { + nodes[position.getPosition()].setRightNode(position); + position.next(); + nodes[position.getPosition()].setLeftNode(position); + } + + public void nextPosition(Position position) { validatePosition(position); - if (isRight(position)) { - return position + 1; - } - if (isLeft(position)) { - return position - 1; - } - return position; + nodes[position.getPosition()].move(position); } - private boolean isLeft(int position) { - return row[position] == -1; + private void validatePosition(Position position) { + if (position.isBiggerThan(nodes.length - 1)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_POSITION.getMessage()); + } } - private boolean isRight(int position) { - return row[position] == 1; + private void validateDrawLinePosition(Position startPosition) { + if (isInvalidPosition(startPosition) || isLineAtPosition(startPosition) || isLineAtNextPosition(startPosition)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_DRAW_POSITION.getMessage()); + } } - private void validateNumberOfPerson(int numberOfPerson) { - if (numberOfPerson < 1) { - throw new IllegalArgumentException("참여 인원은 1명 이상이어야 합니다."); - } + private boolean isInvalidPosition(Position startPosition) { + return startPosition.isBiggerThan(nodes.length - 1); } - private void validatePosition(int position) { - if (position >= row.length || position < 0) { - throw new IllegalArgumentException("유효하지 않은 위치입니다."); - } + private boolean isLineAtPosition(Position startPosition) { + return !nodes[startPosition.getPosition()].isAlreadySetDirection(); } - private void validateDrawLinePosition(int startPosition) { - if (startPosition >= row.length - 1 || startPosition < 0 || row[startPosition] == -1 || row[startPosition + 1] == 1) { - throw new IllegalArgumentException("사다리를 그릴 수 없는 위치입니다."); - } + private boolean isLineAtNextPosition(Position startPosition) { + startPosition.next(); + boolean IsLineAtPosition = !nodes[startPosition.getPosition()].isAlreadySetDirection(); + startPosition.prev(); + return IsLineAtPosition; } } \ No newline at end of file diff --git a/src/main/java/ladder/creator/LadderCreator.java b/src/main/java/ladder/creator/LadderCreator.java new file mode 100644 index 0000000..0071ea3 --- /dev/null +++ b/src/main/java/ladder/creator/LadderCreator.java @@ -0,0 +1,25 @@ +package ladder.creator; + +import ladder.GreaterThanOne; +import ladder.Position; +import ladder.Row; + +public class LadderCreator { + + private final Row[] rows; + + public LadderCreator(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { + rows = new Row[numberOfRow.getNumber()]; + for (int i = 0; i < numberOfRow.getNumber(); i++) { + rows[i] = new Row(numberOfPerson); + } + } + + public void drawLine(Position row, Position col) { + rows[row.getPosition()].drawLine(col); + } + + public Row[] getRows() { + return rows; + } +} diff --git a/src/test/java/ladder/LadderGameTest.java b/src/test/java/ladder/LadderGameTest.java new file mode 100644 index 0000000..6eba8a8 --- /dev/null +++ b/src/test/java/ladder/LadderGameTest.java @@ -0,0 +1,69 @@ +package ladder; + +import ladder.creator.LadderCreator; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + +class LadderGameTest { + + @Test + void 사다리_생성_확인() { + //given + GreaterThanOne numberOfRow = GreaterThanOne.from(3); + GreaterThanOne numberOfPerson = GreaterThanOne.from(5); + + //when + LadderCreator ladderCreator = new LadderCreator(numberOfRow, numberOfPerson); + + //then + assertThat(ladderCreator).isNotNull(); + } + + @Test + void 사다리_사람_예외_처리_확인() { + //when + GreaterThanOne row = GreaterThanOne.from(2); + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); + LadderCreator ladderCreator = new LadderCreator(row, numberOfPerson); + LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); + + //given + Position nthOfPerson = Position.from(4); + + //then + assertThatThrownBy(() -> ladderRunner.run(nthOfPerson)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void 사다리_결과_확인() { + //when + GreaterThanOne numberOfPerson = GreaterThanOne.from(4); + GreaterThanOne row = GreaterThanOne.from(3); + LadderCreator ladderCreator = new LadderCreator(row, numberOfPerson); + LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); + + ladderCreator.drawLine(Position.from(0), Position.from(0)); + ladderCreator.drawLine(Position.from(1), Position.from(1)); + ladderCreator.drawLine(Position.from(2), Position.from(0)); + + //given + Position nthOfPerson = Position.from(0); + + //then + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(2); + + //given + nthOfPerson = Position.from(1); + + //then + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(1); + + //given + nthOfPerson = Position.from(2); + + //then + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(0); + } +} \ No newline at end of file diff --git a/src/test/java/ladder/LadderTest.java b/src/test/java/ladder/LadderTest.java deleted file mode 100644 index 0328fdd..0000000 --- a/src/test/java/ladder/LadderTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package ladder; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.*; - -class LadderTest { - - @Test - void 사다리_생성_확인() { - //given - int numberOfRow = 3; - int numberOfPerson = 5; - - //when - Ladder ladder = new Ladder(numberOfRow, numberOfPerson); - - //then - assertThat(ladder).isNotNull(); - } - - @Test - void 사다리_사람_예외_처리_확인() { - //when - int numberOfPerson = 3; - Ladder ladder = new Ladder(1, numberOfPerson); - - //given - int nthOfPerson = 4; - - //then - assertThatThrownBy(() -> ladder.run(nthOfPerson)) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void 사다리_결과_확인() { - //when - int numberOfPerson = 4; - int row = 3; - Ladder ladder = new Ladder(row, numberOfPerson); - - ladder.drawLine(0,0); - ladder.drawLine(1,1); - ladder.drawLine(2,0); - - //given - int nthOfPerson = 0; - - //then - assertThat(ladder.run(nthOfPerson)).isEqualTo(2); - - //given - nthOfPerson = 1; - - //then - assertThat(ladder.run(nthOfPerson)).isEqualTo(1); - - //given - nthOfPerson = 2; - - //then - assertThat(ladder.run(nthOfPerson)).isEqualTo(0); - } -} \ No newline at end of file diff --git a/src/test/java/ladder/NodeTest.java b/src/test/java/ladder/NodeTest.java new file mode 100644 index 0000000..db066e8 --- /dev/null +++ b/src/test/java/ladder/NodeTest.java @@ -0,0 +1,43 @@ +package ladder; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import static ladder.Direction.*; +import static org.assertj.core.api.Assertions.*; + +public class NodeTest { + + @Test + void 오른쪽_방향_위치_이동_확인() { + Node node = Node.from(RIGHT); + + Position position = Position.from(0); + + node.move(position); + + assertThat(position.getPosition()).isEqualTo(1); + } + + @Test + void NONE_방향_위치_이동_확인() { + Node node = Node.from(NONE); + + Position position = Position.from(0); + + node.move(position); + + assertThat(position.getPosition()).isEqualTo(0); + } + + @Test + void 왼쪽_방향_위치_이동_확인() { + Node node = Node.from(LEFT); + + Position position = Position.from(1); + + node.move(position); + + assertThat(position.getPosition()).isEqualTo(0); + } +} diff --git a/src/test/java/ladder/RowTest.java b/src/test/java/ladder/RowTest.java index c72ad5e..3f8008a 100644 --- a/src/test/java/ladder/RowTest.java +++ b/src/test/java/ladder/RowTest.java @@ -9,104 +9,108 @@ class RowTest { @Test void 한_칸_사다리_이동() { //when - int numberOfPerson = 1; + GreaterThanOne numberOfPerson = GreaterThanOne.from(2); Row row = new Row(numberOfPerson); //given - int position = 0; + Position position = Position.from(0); + row.nextPosition(position); //then - assertThat(row.nextPosition(position)).isEqualTo(0); + assertThat(position.getPosition()).isEqualTo(0); } @Test void 두_칸_사다리_선_이동() { //when - int numberOfPerson = 2; + GreaterThanOne numberOfPerson = GreaterThanOne.from(2); Row row = new Row(numberOfPerson); - row.drawLine(0); + row.drawLine(Position.from(0)); //given - int position = 0; + Position position = Position.from(0); + row.nextPosition(position); //then - assertThat(row.nextPosition(position)).isEqualTo(1); + assertThat(position.getPosition()).isEqualTo(1); //given - position = 1; + position = Position.from(1); + row.nextPosition(position); //then - assertThat(row.nextPosition(position)).isEqualTo(0); + assertThat(position.getPosition()).isEqualTo(0); } @Test void 세_칸_사다리_선_이동() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); - row.drawLine(0); + row.drawLine(Position.from(0)); //given - int position = 0; + Position position = Position.from(0); + row.nextPosition(position); //then - assertThat(row.nextPosition(position)).isEqualTo(1); + assertThat(position.getPosition()).isEqualTo(1); //given - position = 1; + position = Position.from(1); + row.nextPosition(position); //then - assertThat(row.nextPosition(position)).isEqualTo(0); + assertThat(position.getPosition()).isEqualTo(0); //given - position = 2; + position = Position.from(2); + row.nextPosition(position); //then - assertThat(row.nextPosition(position)).isEqualTo(2); + assertThat(position.getPosition()).isEqualTo(2); } @Test void 사다리_사람수_예외_처리() { - assertThatThrownBy(() -> new Row(0)) + assertThatThrownBy(() -> new Row(GreaterThanOne.from(0))) .isInstanceOf(IllegalArgumentException.class); } @Test void 사다리_최대_사람수_초과_예외() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); //given - int position = 3; //then - assertThatThrownBy(() -> row.nextPosition(position)) + assertThatThrownBy(() -> row.nextPosition(Position.from(3))) .isInstanceOf(IllegalArgumentException.class); } @Test void 사다리_최소_사람수_미만_예외() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); //given - int position = -1; //then - assertThatThrownBy(() -> row.nextPosition(position)) + assertThatThrownBy(() -> row.nextPosition(Position.from(-1))) .isInstanceOf(IllegalArgumentException.class); } @Test void 사다리_그리기_위치_초과_예외() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); //given - int position = 3; + Position position = Position.from(3); //then assertThatThrownBy(() -> row.drawLine(position)) @@ -116,38 +120,37 @@ class RowTest { @Test void 사다리_그리기_위치_미만_예외() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); //given - int position = -1; //then - assertThatThrownBy(() -> row.drawLine(position)) + assertThatThrownBy(() -> row.drawLine(Position.from(-1))) .isInstanceOf(IllegalArgumentException.class); } @Test void 사다리_그리기_좌측_선_중복_예외() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); - row.drawLine(0); + row.drawLine(Position.from(0)); //then - assertThatThrownBy(() -> row.drawLine(1)) + assertThatThrownBy(() -> row.drawLine(Position.from(1))) .isInstanceOf(IllegalArgumentException.class); } @Test void 사다리_그리기_우측_선_중복_예외() { //when - int numberOfPerson = 3; + GreaterThanOne numberOfPerson = GreaterThanOne.from(3); Row row = new Row(numberOfPerson); - row.drawLine(1); + row.drawLine(Position.from(1)); //then - assertThatThrownBy(() -> row.drawLine(0)) + assertThatThrownBy(() -> row.drawLine(Position.from(0))) .isInstanceOf(IllegalArgumentException.class); } From 975846308de56e1bc4ac51bc6c29cdd477b5895d Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Fri, 27 Sep 2024 16:43:35 +0900 Subject: [PATCH 05/10] [feat] : print ladder --- src/main/java/ladder/LadderRunner.java | 19 ++++++++++++++++++ src/main/java/ladder/Node.java | 10 +++++++--- src/main/java/ladder/Row.java | 25 ++++++++++++++++++++++-- src/test/java/ladder/LadderGameTest.java | 6 ++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/main/java/ladder/LadderRunner.java b/src/main/java/ladder/LadderRunner.java index dc5739e..3d63181 100644 --- a/src/main/java/ladder/LadderRunner.java +++ b/src/main/java/ladder/LadderRunner.java @@ -10,8 +10,27 @@ public LadderRunner(Row[] rows) { public int run(Position position) { for (int i = 0; i < rows.length; i++) { + System.out.println("Before"); + printLadder(position, i); + System.out.println(); + rows[i].nextPosition(position); + + System.out.println("After"); + printLadder(position, i); + System.out.println(); } return position.getPosition(); } + + private void printLadder(Position position, int currentRow) { + StringBuilder ladderBuilder = new StringBuilder(); + + for (int i = 0; i < rows.length; i++) { + ladderBuilder.append(rows[i].printRow(position, i == currentRow)); + ladderBuilder.append("\n"); + } + + System.out.print(ladderBuilder.toString()); + } } diff --git a/src/main/java/ladder/Node.java b/src/main/java/ladder/Node.java index f9ce729..9edb007 100644 --- a/src/main/java/ladder/Node.java +++ b/src/main/java/ladder/Node.java @@ -10,6 +10,10 @@ private Node(Direction direction) { this.direction = direction; } + public Direction getDirection() { + return direction; + } + public static Node from(Direction direction) { return new Node(direction); } @@ -37,15 +41,15 @@ public boolean isAlreadySetDirection() { return isNone(); } - private boolean isRight() { + public boolean isRight() { return direction == RIGHT; } - private boolean isLeft() { + public boolean isLeft() { return direction == LEFT; } - private boolean isNone() { + public boolean isNone() { return direction == NONE; } } diff --git a/src/main/java/ladder/Row.java b/src/main/java/ladder/Row.java index ba4dbb8..fe4a77c 100644 --- a/src/main/java/ladder/Row.java +++ b/src/main/java/ladder/Row.java @@ -4,7 +4,6 @@ public class Row { - // todo Node 클래스 분리 -> 완 Node[] nodes; public Row(GreaterThanOne numberOfPerson) { @@ -14,7 +13,6 @@ public Row(GreaterThanOne numberOfPerson) { } } - // todo 1, -1, 0 상수 리팩토링 -> 완 public void drawLine(Position startPosition) { validateDrawLinePosition(startPosition); @@ -33,6 +31,17 @@ public void nextPosition(Position position) { nodes[position.getPosition()].move(position); } + public String printRow(Position position, boolean isCurrentRow) { + StringBuilder rowBuilder = new StringBuilder(); + + for (int i = 0; i < nodes.length; i++) { + rowBuilder.append(getNodeIndex(i)) + .append((isCurrentRow && i == position.getPosition()) ? "*" : "") + .append(i < nodes.length - 1 ? " " : ""); + } + return rowBuilder.toString(); + } + private void validatePosition(Position position) { if (position.isBiggerThan(nodes.length - 1)) { throw new IllegalArgumentException(ExceptionMessage.INVALID_POSITION.getMessage()); @@ -59,4 +68,16 @@ private boolean isLineAtNextPosition(Position startPosition) { startPosition.prev(); return IsLineAtPosition; } + + private String getNodeIndex(int index) { + switch (nodes[index].getDirection()) { + case RIGHT: + return "1"; + case LEFT: + return "-1"; + case NONE: + default: + return "0"; + } + } } \ No newline at end of file diff --git a/src/test/java/ladder/LadderGameTest.java b/src/test/java/ladder/LadderGameTest.java index 6eba8a8..6e6e67e 100644 --- a/src/test/java/ladder/LadderGameTest.java +++ b/src/test/java/ladder/LadderGameTest.java @@ -65,5 +65,11 @@ class LadderGameTest { //then assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(0); + + //given + nthOfPerson = Position.from(3); + + //then + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(3); } } \ No newline at end of file From 8f7b96a1b65402707939f46fc9358984fbaab4fe Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Fri, 27 Sep 2024 16:48:56 +0900 Subject: [PATCH 06/10] [chore] : check ladder printing --- src/test/java/ladder/LadderGameTest.java | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/java/ladder/LadderGameTest.java b/src/test/java/ladder/LadderGameTest.java index 6e6e67e..3f877c1 100644 --- a/src/test/java/ladder/LadderGameTest.java +++ b/src/test/java/ladder/LadderGameTest.java @@ -10,7 +10,7 @@ class LadderGameTest { @Test void 사다리_생성_확인() { //given - GreaterThanOne numberOfRow = GreaterThanOne.from(3); + GreaterThanOne numberOfRow = GreaterThanOne.from(5); GreaterThanOne numberOfPerson = GreaterThanOne.from(5); //when @@ -23,13 +23,13 @@ class LadderGameTest { @Test void 사다리_사람_예외_처리_확인() { //when - GreaterThanOne row = GreaterThanOne.from(2); - GreaterThanOne numberOfPerson = GreaterThanOne.from(3); + GreaterThanOne row = GreaterThanOne.from(5); + GreaterThanOne numberOfPerson = GreaterThanOne.from(5); LadderCreator ladderCreator = new LadderCreator(row, numberOfPerson); LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); //given - Position nthOfPerson = Position.from(4); + Position nthOfPerson = Position.from(5); //then assertThatThrownBy(() -> ladderRunner.run(nthOfPerson)) @@ -39,20 +39,22 @@ class LadderGameTest { @Test void 사다리_결과_확인() { //when - GreaterThanOne numberOfPerson = GreaterThanOne.from(4); - GreaterThanOne row = GreaterThanOne.from(3); + GreaterThanOne numberOfPerson = GreaterThanOne.from(5); + GreaterThanOne row = GreaterThanOne.from(5); LadderCreator ladderCreator = new LadderCreator(row, numberOfPerson); LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); ladderCreator.drawLine(Position.from(0), Position.from(0)); ladderCreator.drawLine(Position.from(1), Position.from(1)); ladderCreator.drawLine(Position.from(2), Position.from(0)); + ladderCreator.drawLine(Position.from(3), Position.from(2)); + ladderCreator.drawLine(Position.from(2), Position.from(3)); //given Position nthOfPerson = Position.from(0); //then - assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(2); + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(3); //given nthOfPerson = Position.from(1); @@ -70,6 +72,12 @@ class LadderGameTest { nthOfPerson = Position.from(3); //then - assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(3); + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(4); + + //given + nthOfPerson = Position.from(4); + + //then + assertThat(ladderRunner.run(nthOfPerson)).isEqualTo(2); } } \ No newline at end of file From ba6023dff076d99f4c80b48beb1b704013b4530a Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Fri, 27 Sep 2024 20:52:41 +0900 Subject: [PATCH 07/10] [feat] : di --- src/main/java/ladder/LadderCreatorInterface.java | 6 ++++++ src/main/java/ladder/LadderGameFactory.java | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/main/java/ladder/LadderCreatorInterface.java create mode 100644 src/main/java/ladder/LadderGameFactory.java diff --git a/src/main/java/ladder/LadderCreatorInterface.java b/src/main/java/ladder/LadderCreatorInterface.java new file mode 100644 index 0000000..feac01a --- /dev/null +++ b/src/main/java/ladder/LadderCreatorInterface.java @@ -0,0 +1,6 @@ +package ladder; + +public interface LadderCreatorInterface { + Row[] getRows(); + void drawLine(Position row, Position col); +} diff --git a/src/main/java/ladder/LadderGameFactory.java b/src/main/java/ladder/LadderGameFactory.java new file mode 100644 index 0000000..be2027c --- /dev/null +++ b/src/main/java/ladder/LadderGameFactory.java @@ -0,0 +1,11 @@ +package ladder; + +import ladder.creator.LadderAutoCreator; + +public class LadderGameFactory { + + public static LadderGame createRandomLadderGame(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { + LadderCreatorInterface ladderCreator = new LadderAutoCreator(numberOfRow, numberOfPerson); + return new LadderGame(ladderCreator); + } +} From df5a5c0f3cdc96385cac88bf5039c357df0fc039 Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Fri, 27 Sep 2024 20:53:58 +0900 Subject: [PATCH 08/10] [chore] : clean code --- src/main/java/ladder/LadderGame.java | 10 ++-------- src/main/java/ladder/creator/LadderCreator.java | 1 + src/test/java/ladder/NodeTest.java | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/ladder/LadderGame.java b/src/main/java/ladder/LadderGame.java index a4a2498..b035192 100644 --- a/src/main/java/ladder/LadderGame.java +++ b/src/main/java/ladder/LadderGame.java @@ -1,19 +1,13 @@ package ladder; -import ladder.creator.LadderCreator; - public class LadderGame { - private final LadderCreator ladderCreator; + private final LadderCreatorInterface ladderCreator; - // todo Ladder 생성자 래퍼 클래스 -> 완 - public LadderGame(LadderCreator ladderCreator) { + public LadderGame(LadderCreatorInterface ladderCreator) { this.ladderCreator = ladderCreator; } - // todo LadderCreator, LadderRunner -> 완 - - // todo 인덱스 값 Position 래퍼 클래스 -> 완 public int run(Position position) { LadderRunner ladderRunner = new LadderRunner(ladderCreator.getRows()); ladderRunner.run(position); diff --git a/src/main/java/ladder/creator/LadderCreator.java b/src/main/java/ladder/creator/LadderCreator.java index 0071ea3..5936257 100644 --- a/src/main/java/ladder/creator/LadderCreator.java +++ b/src/main/java/ladder/creator/LadderCreator.java @@ -1,6 +1,7 @@ package ladder.creator; import ladder.GreaterThanOne; +import ladder.LadderCreatorInterface; import ladder.Position; import ladder.Row; diff --git a/src/test/java/ladder/NodeTest.java b/src/test/java/ladder/NodeTest.java index db066e8..feb5892 100644 --- a/src/test/java/ladder/NodeTest.java +++ b/src/test/java/ladder/NodeTest.java @@ -1,6 +1,5 @@ package ladder; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import static ladder.Direction.*; From c99b9903568da420311e05debe3c5fd3197d1035 Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Fri, 27 Sep 2024 20:54:59 +0900 Subject: [PATCH 09/10] [feat] : print random ladder --- src/main/java/ladder/Row.java | 7 +++ .../ladder/creator/LadderAutoCreator.java | 50 +++++++++++++++++++ .../java/ladder/RandomLadderGameTest.java | 33 ++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/main/java/ladder/creator/LadderAutoCreator.java create mode 100644 src/test/java/ladder/RandomLadderGameTest.java diff --git a/src/main/java/ladder/Row.java b/src/main/java/ladder/Row.java index fe4a77c..f35f46b 100644 --- a/src/main/java/ladder/Row.java +++ b/src/main/java/ladder/Row.java @@ -13,6 +13,13 @@ public Row(GreaterThanOne numberOfPerson) { } } + public boolean canDrawLineAt(int col) { + if (col < 0 || col >= nodes.length - 1) { + return false; + } + return nodes[col].isNone() && nodes[col + 1].isNone(); + } + public void drawLine(Position startPosition) { validateDrawLinePosition(startPosition); diff --git a/src/main/java/ladder/creator/LadderAutoCreator.java b/src/main/java/ladder/creator/LadderAutoCreator.java new file mode 100644 index 0000000..2ac8c9f --- /dev/null +++ b/src/main/java/ladder/creator/LadderAutoCreator.java @@ -0,0 +1,50 @@ +package ladder.creator; + +import ladder.GreaterThanOne; +import ladder.LadderCreatorInterface; +import ladder.Position; +import ladder.Row; + +import java.util.Random; + +public class LadderAutoCreator implements LadderCreatorInterface { + + private final Row[] rows; + private final int numberOfLines; + private final Random random = new Random(); + + public LadderAutoCreator(GreaterThanOne numberOfRow, GreaterThanOne numberOfPerson) { + rows = new Row[numberOfRow.getNumber()]; + + numberOfLines = (int) (numberOfRow.getNumber() * numberOfPerson.getNumber() * 0.3); + + for (int i = 0; i < numberOfRow.getNumber(); i++) { + rows[i] = new Row(numberOfPerson); + } + + createRandomLines(numberOfPerson); + } + + private void createRandomLines(GreaterThanOne numberOfPerson) { + int linesDrawn = 0; + while (linesDrawn < numberOfLines) { + int randomRow = random.nextInt(rows.length); + int randomCol = random.nextInt(numberOfPerson.getNumber() - 1); + + Position position = Position.from(randomCol); + + if (rows[randomRow].canDrawLineAt(position.getPosition())) { + rows[randomRow].drawLine(position); + linesDrawn++; + } + } + } + + public void drawLine(Position row, Position col) { + rows[row.getPosition()].drawLine(col); + } + + public Row[] getRows() { + return rows; + } +} diff --git a/src/test/java/ladder/RandomLadderGameTest.java b/src/test/java/ladder/RandomLadderGameTest.java new file mode 100644 index 0000000..48eb378 --- /dev/null +++ b/src/test/java/ladder/RandomLadderGameTest.java @@ -0,0 +1,33 @@ +package ladder; + +import ladder.creator.LadderAutoCreator; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RandomLadderGameTest { + @Test + void 사다리_자동_생성_확인() { + // given + GreaterThanOne row = GreaterThanOne.from(5); + GreaterThanOne numberOfPerson = GreaterThanOne.from(5); + + // when + LadderAutoCreator ladderCreator = new LadderAutoCreator(row, numberOfPerson); + + // then + assertThat(ladderCreator).isNotNull(); + } + + @Test + void 사다리_자동_생성_결과_확인() { + GreaterThanOne numberOfRow = GreaterThanOne.from(5); + GreaterThanOne numberOfPerson = GreaterThanOne.from(4); + + LadderGame ladderGame = LadderGameFactory.createRandomLadderGame(numberOfRow, numberOfPerson); + Position startPosition = Position.from(0); + int finalPosition = ladderGame.run(startPosition); + + assertThat(finalPosition).isNotNegative(); + } +} From e201a641e99b89321c7431d60fca7325bc720ef4 Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Fri, 27 Sep 2024 21:54:22 +0900 Subject: [PATCH 10/10] [chore] : add description --- src/test/java/ladder/RandomLadderGameTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/ladder/RandomLadderGameTest.java b/src/test/java/ladder/RandomLadderGameTest.java index 48eb378..04d2599 100644 --- a/src/test/java/ladder/RandomLadderGameTest.java +++ b/src/test/java/ladder/RandomLadderGameTest.java @@ -21,13 +21,16 @@ public class RandomLadderGameTest { @Test void 사다리_자동_생성_결과_확인() { + // given GreaterThanOne numberOfRow = GreaterThanOne.from(5); GreaterThanOne numberOfPerson = GreaterThanOne.from(4); + // when LadderGame ladderGame = LadderGameFactory.createRandomLadderGame(numberOfRow, numberOfPerson); Position startPosition = Position.from(0); int finalPosition = ladderGame.run(startPosition); + // then assertThat(finalPosition).isNotNegative(); } }