Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c907d1c
feat: 사다리의 가로, 세로 값에 대한 원시값 포장
jinhyeongpark Feb 7, 2026
3df5893
feat: 사다리의 지점 상태를 관리하는 Point 도메인 구현
jinhyeongpark Feb 7, 2026
8d03131
feat: 사다리의 가로 한 줄을 담당하는 Line 도메인 구현
jinhyeongpark Feb 7, 2026
9b6cb0c
feat: 사다리의 전체 구조를 관리하는 Ladder 도메인 구현
jinhyeongpark Feb 7, 2026
0342e8f
feat: 사다리의 시각화를 위한 OutputView 구현\
jinhyeongpark Feb 7, 2026
301cd44
feat: 사용자 입력을 담당하는 InputView 구현
jinhyeongpark Feb 7, 2026
5ca9ff3
feat: 프로그램 실행을 담당하는 Application 메인 로직 구현
jinhyeongpark Feb 7, 2026
c5552c9
feat: Line의 유무를 판단하는 Point의 boolean에 대해 BooleanSupplier 적용
jinhyeongpark Feb 7, 2026
ae958f0
feat: 사용하지 않는 기존 canDraw 메서드 삭제
jinhyeongpark Feb 7, 2026
a6ea645
test: 값 객체(Point, Width, Height)에 대한 단위 테스트 추가
jinhyeongpark Feb 7, 2026
605275b
test: Line의 다리 생성 및 가로 중복 금지 로직 검증 테스트 추가
jinhyeongpark Feb 7, 2026
a9ff74b
test: 사다리 전체 구조 및 조립 로직 검증 테스트 추가
jinhyeongpark Feb 7, 2026
a5ed58a
feat: 하나의 Line 내에서의 이동 로직 메서드 move 구현
jinhyeongpark Feb 8, 2026
2071d3e
feat: Ladder에서 사다리 게임 수행 및 결과를 생성하는 메서드 구현
jinhyeongpark Feb 8, 2026
28fe4d9
feat: OutputView에서 사다리게임 결과 출력 메서드 구현
jinhyeongpark Feb 8, 2026
d101e00
test: move에 대한 테스트코드 작성
jinhyeongpark Feb 8, 2026
614c62d
test: climb과 generateResults에 대한 테스트코드 작성
jinhyeongpark Feb 8, 2026
49d73b3
refactor: LadderTest에서 반복되는 Participants 생성에 대해 상수 및 메서드로 분리
jinhyeongpark Feb 8, 2026
b3ac3e1
feat: Ladder의 정적 팩터리 메서드 파라미터 변경
jinhyeongpark Feb 8, 2026
349cf9f
feat: 사용하지 않는 LadderWidth 관련 클래스 삭제
jinhyeongpark Feb 8, 2026
ff2eb5e
feat: 실행 결과와 결과를 담는 일급 컬렉션 구현
jinhyeongpark Feb 8, 2026
10df688
feat: 참여자 명과 참여자들을 관리하는 일급 컬렉션 구현
jinhyeongpark Feb 8, 2026
076b917
feat: 참여자와 실행 결과에 대한 입력 로직 구현
jinhyeongpark Feb 8, 2026
b21eb78
feat: 단일 필드를 반환하는 메서드를 추가하여 toString() 없이 문자열로 출력되도록 함
jinhyeongpark Feb 8, 2026
11048f6
feat: 단일 필드를 반환하는 메서드를 추가하여 toString() 없이 문자열로 출력되도록 함
jinhyeongpark Feb 8, 2026
bbd4b73
feat: 사다리 게임 결과 매핑을 위한 LadderGameResult 클래스 추가
jinhyeongpark Feb 8, 2026
591482a
feat: 게임 결과 조회 흐름을 제어하는 LadderGameController 추가
jinhyeongpark Feb 8, 2026
3c81f19
feat: 특정 참여자의 결과를 요청하는 입력 메서드 구현
jinhyeongpark Feb 8, 2026
8dbf07e
feat: 사다리 시각화 정렬 및 게임 결과 출력 기능 구현
jinhyeongpark Feb 8, 2026
33f1f4f
feat: 사다리 게임 참가자 및 결과 입력 처리 로직 추가
jinhyeongpark Feb 8, 2026
d5090da
test: Name 클래스 단위 테스트 구현
jinhyeongpark Feb 8, 2026
6f66089
test: LadderResult 및 LadderResults 클래스 단위 테스트 구현
jinhyeongpark Feb 8, 2026
eb01867
test: LadderGameResultTest 클래스 단위 테스트 구현
jinhyeongpark Feb 8, 2026
19f0bd5
test: ParticipantsTest 구현
jinhyeongpark Feb 8, 2026
32e7fda
refactor: LadderResults의 results 반환 메서드에 대해 수정 방지를 위한 불변값으로 변경
jinhyeongpark Feb 13, 2026
dc96a90
refactor: Ladder 클래스 책임 분리 및 Lines 일급 컬렉션 도입
jinhyeongpark Feb 14, 2026
c23c944
test: Lines 단위 테스트 추가 및 LadderTest 리팩터링
jinhyeongpark Feb 14, 2026
0b9b1e5
refactor: 사용하지 않는 메서드 삭제
jinhyeongpark Feb 14, 2026
0b57f6f
refactor: climb 메서드 접근제어자 변경
jinhyeongpark Feb 14, 2026
0827136
refactor: Point 클래스에 대해 Enum으로 변경
jinhyeongpark Feb 14, 2026
d3b0264
refactor: Participants의 from 메서드 수정
jinhyeongpark Feb 14, 2026
5b08244
refactor: Line의 Point 리스트를 Points 일급 컬렉션으로 리팩터링
jinhyeongpark Feb 14, 2026
cb14f4b
refactor: Line의 Point 리스트를 Points 일급 컬렉션으로 리팩터링
jinhyeongpark Feb 14, 2026
b0e4e34
test: Points 단위 테스트 추가
jinhyeongpark Feb 14, 2026
8fda279
refactor: 완성된 Lines 주입 방식으로 Ladder 생성 로직 리팩터링 및 DI 적용
jinhyeongpark Feb 14, 2026
7f4a112
test: 리팩터링된 도메인 구조에 맞춰 Ladder 및 Lines 테스트 수정
jinhyeongpark Feb 14, 2026
402eb27
Merge branch 'jinhyeongpark' into step2
jinhyeongpark Feb 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/ladder/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ladder.domain.LadderGameResult;
import ladder.domain.LadderHeight;
import ladder.domain.LadderResults;
import ladder.domain.Lines;
import ladder.domain.Participants;
import ladder.view.InputView;
import ladder.view.OutputView;
Expand All @@ -21,15 +22,15 @@ public static void main(String[] args) {

LadderHeight height = InputView.inputHeight();

Ladder ladder = Ladder.of(participants, height, RANDOM::nextBoolean);
Lines lines = Lines.generate(participants.size(), height, RANDOM::nextBoolean);

Ladder ladder = Ladder.of(participants, lines);

Map<Integer, Integer> path = ladder.generateResults();

LadderGameResult gameResult = LadderGameResult.of(participants, results, path);

OutputView.printLadder(participants, ladder, results);
LadderGameController.runInquiry(gameResult);

}

}
48 changes: 17 additions & 31 deletions src/main/java/ladder/domain/Ladder.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,40 @@
package ladder.domain;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Ladder {

private final List<Line> lines;
private final Lines lines;
private final int width;

private Ladder(List<Line> lines, int width) {
private Ladder(Lines lines, int width) {
this.lines = lines;
this.width = width;
}

public static Ladder of(Participants participants, LadderHeight height, BooleanSupplier strategy) {
int participantCount = participants.size();
List<Line> lines = generateLines(participantCount, height, strategy);

return new Ladder(lines, participantCount);
public static Ladder of(Participants participants, Lines lines) {
return new Ladder(lines, participants.size());
}

public int climb(int startIndex) {
int currentIndex = startIndex;
for (Line line : lines) {
currentIndex = line.move(currentIndex);
}
return currentIndex;
int climb(int startIndex) {
return lines.move(startIndex);
Comment on lines +22 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 친구는 default로 설정한 이유가 있나요?

}

public Map<Integer, Integer> generateResults() {
Map<Integer, Integer> results = new LinkedHashMap<>();
for (int i = 0; i < width; i++) {
results.put(i, climb(i));
}
return results;
}

private static List<Line> generateLines(int participantCount, LadderHeight height, BooleanSupplier strategy) {
List<Line> lines = new ArrayList<>();
int pointCount = participantCount - 1;
for (int i = 0; i < height.getValue(); i++) {
lines.add(Line.from(pointCount, strategy));
}
return lines;
return IntStream.range(0, width)
.boxed()
.collect(Collectors.toMap(
index -> index,
this::climb,
(oldValue, newValue) -> newValue,
LinkedHashMap::new
));
Comment on lines +27 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 반복문 쓰는게 더 코드가 직관적일 것 같은데요??

public Map<Integer, Integer> generateREulsts2() {
        Map<Integer, Integer> results = new LinkedHashMap<>();
        for (int index = 0; index < width; index++) {
            results.put(index, climb(index));
        }
        return results;
    }

스트림을 선택한 이유가 있었나요??

}

public List<Line> getLines() {
public Lines getLines() {
return lines;
}
}
3 changes: 2 additions & 1 deletion src/main/java/ladder/domain/LadderResults.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ladder.domain;

import java.util.Collections;
import java.util.List;

public class LadderResults {
Expand All @@ -21,6 +22,6 @@ public static LadderResults of(List<String> rawResults, int participantCount) {
}

public List<LadderResult> getValues() {
return results;
return Collections.unmodifiableList(results);
}
}
35 changes: 6 additions & 29 deletions src/main/java/ladder/domain/Line.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
package ladder.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BooleanSupplier;

public class Line {

private final List<Point> points;
private final Points points;

private Line(List<Point> points) {
private Line(Points points) {
this.points = points;
}

public static Line from(int size, BooleanSupplier strategy) {
return new Line(generatePoints(size, strategy));
}

public List<Point> getPoints() {
return points;
public static Line generate(int size, BooleanSupplier strategy) {
return new Line(Points.generate(size, strategy));
}

public int move(int index) {
if (index < points.size() && points.get(index).hasBridge()) {
return index + 1;
}
if (index > 0 && points.get(index - 1).hasBridge()) {
return index - 1;
}
return index;
return points.move(index);
}

private static List<Point> generatePoints(int size, BooleanSupplier strategy) {
List<Point> points = new ArrayList<>();
boolean lastBridge = false;
for (int i = 0; i < size; i++) {
lastBridge = addPoint(points, lastBridge, strategy);
}
public Points getPoints() {
return points;
}

private static boolean addPoint(List<Point> points, boolean lastBridge, BooleanSupplier strategy) {
boolean currentBridge = !lastBridge && strategy.getAsBoolean();
points.add(Point.from(currentBridge));
return currentBridge;
}
}
45 changes: 45 additions & 0 deletions src/main/java/ladder/domain/Lines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ladder.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.BooleanSupplier;

public class Lines implements Iterable<Line> {
private final List<Line> lines;

private Lines(List<Line> lines) {
this.lines = lines;
}

public static Lines generate(int participantCount, LadderHeight height, BooleanSupplier strategy) {
List<Line> lines = new ArrayList<>();
int pointCount = participantCount - 1;
for (int i = 0; i < height.getValue(); i++) {
lines.add(Line.generate(pointCount, strategy));
}
return new Lines(lines);
}

public int move(int startIndex) {
int currentIndex = startIndex;
for (Line line : lines) {
currentIndex = line.move(currentIndex);
}
return currentIndex;
}

public Line get(int index) {
return lines.get(index);
}

public int size() {
return lines.size();
}

@Override
public Iterator<Line> iterator() {
return lines.iterator();
}
}
2 changes: 1 addition & 1 deletion src/main/java/ladder/domain/Participants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private Participants(List<Name> participants) {
public static Participants from(List<String> names) {
List<Name> nameList = names.stream()
.map(Name::from)
.collect(Collectors.toList());
.toList();
return new Participants(nameList);
}

Expand Down
18 changes: 6 additions & 12 deletions src/main/java/ladder/domain/Point.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package ladder.domain;

public class Point {

private static final Point BRIDGE = new Point(true);
private static final Point EMPTY = new Point(false);
public enum Point {
BRIDGE(true),
EMPTY(false);

private final boolean hasBridge;

private Point(boolean hasBridge) {
Point(boolean hasBridge) {
this.hasBridge = hasBridge;
}

public static Point from(boolean hasBridge) {
if (hasBridge) {
return BRIDGE;
}
return EMPTY;
return hasBridge ? BRIDGE : EMPTY;
}

public boolean hasBridge() {
return hasBridge;
}
public boolean hasBridge() { return hasBridge; }
}
65 changes: 65 additions & 0 deletions src/main/java/ladder/domain/Points.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ladder.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.BooleanSupplier;

public class Points implements Iterable<Point> {
private final List<Point> points;

private Points(List<Point> points) {
this.points = points;
}

public static Points generate(int size, BooleanSupplier strategy) {
List<Point> points = new ArrayList<>();
boolean lastBridge = false;
for (int i = 0; i < size; i++) {
lastBridge = addPoint(points, lastBridge, strategy);
}
return new Points(points);
}

private static boolean addPoint(List<Point> points, boolean lastBridge, BooleanSupplier strategy) {
boolean currentBridge = !lastBridge && strategy.getAsBoolean();
points.add(Point.from(currentBridge));
return currentBridge;
}

public int move(int index) {
if (isRightStep(index)) {
return index + 1;
}
if (isLeftStep(index)) {
return index - 1;
}
return index;
}

private boolean isRightStep(int index) {
return index < points.size() && points.get(index).hasBridge();
}

private boolean isLeftStep(int index) {
return index > 0 && points.get(index - 1).hasBridge();
}

public Point get(int index) {
return points.get(index);
}

public int size() {
return points.size();
}

public List<Point> getValues() {
return Collections.unmodifiableList(points);
}
Comment on lines +57 to +59

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collections.unmodifiableList를 사용하면 모든 경우에서 불변을 유지할 수 있는걸까요??


@Override
public Iterator<Point> iterator() {
return points.iterator();
}
}
16 changes: 9 additions & 7 deletions src/test/java/ladder/domain/LadderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ void createLadder_WidthCheck() {
void createLadder_StrategyCheck() {
Ladder ladder = createLadder(NAMES_3, 1);
Line firstLine = ladder.getLines().get(0);
Points points = firstLine.getPoints();

assertAll(
() -> assertThat(firstLine.getPoints().get(0).hasBridge()).isTrue(),
() -> assertThat(firstLine.getPoints().get(1).hasBridge()).isFalse()
() -> assertThat(points.get(0).hasBridge()).isTrue(),
() -> assertThat(points.get(1).hasBridge()).isFalse()
);
}

Expand Down Expand Up @@ -72,10 +73,11 @@ void generateResults() {
}

private Ladder createLadder(List<String> names, int height) {
return Ladder.of(
Participants.from(names),
LadderHeight.from(height),
() -> true
);
Participants participants = Participants.from(names);
LadderHeight ladderHeight = LadderHeight.from(height);

Lines lines = Lines.generate(participants.size(), ladderHeight, () -> true);

return Ladder.of(participants, lines);
}
}
10 changes: 5 additions & 5 deletions src/test/java/ladder/domain/LineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void createLine_AlwaysTrueStrategy() {
// given
int size = 3;
// when
Line line = Line.from(size, () -> true);
List<Point> points = line.getPoints();
Line line = Line.generate(size, () -> true);
Points points = line.getPoints();

// then
assertAll(
Expand All @@ -32,7 +32,7 @@ void createLine_AlwaysFalseStrategy() {
// given
int size = 5;
// when
Line line = Line.from(size, () -> false);
Line line = Line.generate(size, () -> false);

// then
assertThat(line.getPoints())
Expand All @@ -44,14 +44,14 @@ void createLine_AlwaysFalseStrategy() {
@Test
void createLine_SizeCheck() {
int size = 10;
Line line = Line.from(size, () -> true);
Line line = Line.generate(size, () -> true);
assertThat(line.getPoints()).hasSize(size);
}

@DisplayName("다리 유무에 따라 인덱스가 좌, 우로 이동하거나 그대로 유지된다.")
@Test
void move() {
Line line = Line.from(3, () -> true);
Line line = Line.generate(3, () -> true);

assertAll(
// 0번 기둥: 0번 포인트가 T이므로 오른쪽(1)으로 이동
Expand Down
Loading