Skip to content

Conversation

@Nico1eKim
Copy link
Member

이번 주차도 부족함이 많은 코드입니다 🥲

저번 주차 코드 리뷰가 도움이 많이 되었습니다.
이번 주차도 잘부탁드립니다! 감사합니다 😊

Copy link

@JangIkhwan JangIkhwan left a comment

Choose a reason for hiding this comment

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

고생 많으셨습니다~ 👍

}

// 사다리 상태를 출력하는 메서드
private void printLadder(Position position, int currentRow) {

Choose a reason for hiding this comment

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

인자 row도 Position 객체이면 좋을 것 같네요

public class LadderSize {
private final GreaterThanOne numberOfRow;
private final GreaterThanOne numberOfPerson;
private static final double LINE_PROBABILITY = 0.3;

Choose a reason for hiding this comment

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

오 가로선 비율을 상수로 설정한 점 좋은 것 같아요! 나중에 봐도 이 값의 의미를 바로 알겠네요

public void printUserRow(Position position) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nodes.length; i++) {
if (i == position.getPosition()) {

Choose a reason for hiding this comment

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

getter를 쓰니 캡슐화가 깨지는 것 같아요. position 객체의 메소드 내부에서 값을 비교해보는 건 어떨까요?


while (positions.size() < linesToCreate) {
int row = random.nextInt(numberOfRow.getNumber());
int col = random.nextInt(numberOfPerson.getNumber() - 1); // 선이 열 사이에 있으므로 열 크기보다 1 작게 선택
Copy link

@JangIkhwan JangIkhwan Sep 28, 2024

Choose a reason for hiding this comment

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

아래에 있는 검증 메소드로 해결할 수 있겠지만, 미리 값의 범위를 제한한 부분에서 꼼꼼함이 보이네요!

LadderPosition newPosition = new LadderPosition(row, col);

// 해당 위치에 선을 그릴 수 있는지 확인
if (positions.contains(newPosition) || !canDrawLine(Position.from(row), Position.from(col))) {

Choose a reason for hiding this comment

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

중복 확인이 잘 되는지 확인해보셨나요? 제가 검색해본 바로는 HashSet의 contains()는 두 객체의 주소가 같은지 검증한다고 하거든요... 중복확인이 잘 동작할지 확신이 안 드네요.

}

@Override
public void drawLine(Position row, Position col) {
Copy link

@JangIkhwan JangIkhwan Sep 28, 2024

Choose a reason for hiding this comment

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

오버라이딩한 메소드가 모두 동일한 일을 하도록 구현해서 좋네요


import static org.assertj.core.api.Assertions.assertThat;

public class RandomLadderGameTest {

Choose a reason for hiding this comment

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

팩토리가 만든 객체도 테스트해보는 건 어떨까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants