Skip to content
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

Step1 구현 완료 #91

Merged
merged 9 commits into from
Mar 29, 2019
Merged

Step1 구현 완료 #91

merged 9 commits into from
Mar 29, 2019

Conversation

CheolHoJung
Copy link

안녕하세요.
사다리게임에서 리뷰를 받게 될 정철호라고 합니다. 잘 부탁드려요!


사다리 타기가 정상적으로 동작하려면 라인이 겹치지 않도록 해야 한다.

부울값 하나를 랜덤으로 생성하는 boolean generator와 해당 generator를 이용하여 겹치지 않는 부울목록을 생성하는 booleans generator를 이용해서 구현했습니다. 이 부분은 테스트 때문에 더 복잡해진 것 같습니다.

NonContinuousGenerator가 겹치지 않는 부울목록을 생성하는 클래스입니다.

  • booleanGenerator를 이용해서 랜덤 부울값을 생성
  • shouldNotBeContinuous로 전달된 부울값이 겹치면 안됨
// test
@Test
public void test_참이_겹치지_않는_부울목록_생성() {
    BooleansGenerator generator = new NonContinuousGenerator(() -> true, true);

    assertThat(generator.generate(6))
            .isEqualTo(Arrays.asList(true, false, true, false, true, false));
}

@Test
public void test_거짓이_겹치지_않는_부울목록_생성() {
    BooleansGenerator generator = new NonContinuousGenerator(() -> false, false);

    assertThat(generator.generate(6))
            .isEqualTo(Arrays.asList(false, true, false, true, false, true));
}

// 생성기
@Override
public List<Boolean> generate(int size) {
    Stack<Boolean> stack = new Stack<>();
    stack.push(booleanGenerator.getAsBoolean()); // 겉으로 드러나지 않음

    for (int i = 1; i < size; i++) {
        addNonContinuous(stack);
    }
    return new ArrayList<>(stack);
}

그런데 여기서 애매한 부분이, 내부 구현을 봐야만 알 수 있는 기능이 하나 있습니다. for문에 진입하기 전에 첫 부울값을 셋팅하는 부분입니다. 구현을 봐야만 결과의 시작값이 booleanGenerator로 생성한 부울값이라는 것을 알 수 있죠. 이를 겉으로 드러내고 싶은데, 클래스 이름에 넣자니 너무 길어져서 어떻게 해야할 지 모르겠습니다 😢

결과 출력

처음에는 사용자 이름과 사다리 정보를 출력하는 부분을 각 일급콜렉션의 toString으로 구현했습니다. 그런데 출력 format (%5s) 등이 겹쳐서 getter를 추가하고 ResultView에서 변환하도록 변경했습니다.


사다리를 연결하는 부분에서 애를 먹었네요. 그래서 힌트를 보고 구현했는데, 제대로 이해한건지 모르겠습니다.

Copy link
Contributor

@javajigi javajigi left a comment

Choose a reason for hiding this comment

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

전체적인 객체 구조와 단위 테스트 코드 구현 잘 했네요. 💯
소소한 피드백 몇 개 남겼으니 2단계에서 피드백 반영하세요.
2단계가 사다리 타기의 핵심인데요.
어떻게 하면 사다리 타기 이동하는 부분에 대해서 단위 테스트가 가능한 구조를 만들 수 있을지 고민해 보면 좋을 것 같아요. 이 부분은 가능하면 혼자 힘으로 구현해볼 것을 추천합니다.


public static void main(String[] args) {
Players players = InputView.inputPlayers();
Ladders ladders = InputView.inputLadders(players.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

InputView에서 직접 ladder를 생성하기 보다 LadderGenerator와 같이 Ladder 생성하는 역할을 담당하는 클래스를 두는 것은 어떨까?

}

public Ladder(int length, BooleanSupplier booleanSupplier) {
this.lines = Collections.unmodifiableList(createLines(length, booleanSupplier));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


public class RandomBooleanGenerator implements BooleanSupplier {

Random random;
Copy link
Contributor

Choose a reason for hiding this comment

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

인스턴스 변수는 특별한 이유가 없는 한 private으로 구현한다.

}

private void addNonContinuous(Stack<Boolean> stack) {
Boolean prevPoint = stack.peek();
Copy link
Contributor

Choose a reason for hiding this comment

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

특별한 이유가 없는 한 primitive type을 사용하는 것은 어떨까?

@javajigi javajigi merged commit ce5f703 into next-step:CheolHoJung Mar 29, 2019
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.

None yet

2 participants