-
Notifications
You must be signed in to change notification settings - Fork 53
[3단계 - 사다리 타기] 최지수 미션 제출합니다 #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ladder.model; | ||
|
||
import java.util.List; | ||
|
||
public class LadderResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OutputView에서 출력을 담당하고 있는 것으로 보이는데, Result 객체에서도 출력 관련 로직이 있는 이유가 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 처음에 Controller클래스에서 분리를 했었는데 OutputView에서 출력을 담당하는 부분과 역할이 겹치는 구조네요 이 부분 고쳐볼게요! |
||
|
||
public void printResult(Ladder ladder) { | ||
List<List<Boolean>> lines = ladder.getLines(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일급 컬렉션을 만드신걸로 아는데 사용하지 않는 이유가 따로 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음 요구사항을 만족해주세요~!
|
||
int width = 0; | ||
if (!lines.isEmpty()) { | ||
width = lines.get(0).size() + 1; | ||
} | ||
|
||
for (int startLine = 0; startLine < width; startLine++) { | ||
int currentPosition = endPosition(startLine, lines); | ||
System.out.println(startLine + " -> " + currentPosition); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저 번에 StringBuilder를 사용하신 걸로 아는데 이 부분도 StringBuilder 사용하셔도 좋을 것 같아요! |
||
} | ||
} | ||
|
||
private int endPosition(int start, List<List<Boolean>> lines) { | ||
int currentPosition = start; | ||
for (List<Boolean> line : lines) { | ||
currentPosition = move(currentPosition, line); | ||
} | ||
return currentPosition; | ||
} | ||
|
||
private int move(int currentPosition, List<Boolean> line) { | ||
boolean rightPosition = currentPosition < line.size() && line.get(currentPosition); | ||
boolean leftPosition = currentPosition > 0 && line.get(currentPosition - 1); | ||
|
||
if (rightPosition) return currentPosition + 1; | ||
if (leftPosition) return currentPosition - 1; | ||
return currentPosition; | ||
} | ||
Comment on lines
+20
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음 요구사항을 만족해보면 좋을것 같아요 :)
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ladder.model; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
class LadderResultTest { | ||
|
||
@Test | ||
@DisplayName("사다리 위치 출력") | ||
void ladderPositionCheck() { | ||
// 임의로 만든 사다리 | ||
List<List<Boolean>> lines = new ArrayList<>(); | ||
lines.add(Arrays.asList(false, true)); | ||
lines.add(Arrays.asList(false, false)); | ||
|
||
Ladder ladder = new Ladder(lines); | ||
LadderResult ladderResult = new LadderResult(); | ||
|
||
ladderResult.printResult(ladder); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
13번 줄에서 이미 LadderOutputView 인스턴스를 선언해주셨더라고요!
여기 동일한 객체를 한 번 더 생성하고 계신데 기존 객체를 재사용하시면 중복도 줄이고 코드도 더 명확해질 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 그렇네요! 기존에 만든 객체를 다시 사용해볼게요