Conversation
2. 도형 계산 테스트
ca1af
left a comment
There was a problem hiding this comment.
1차 리뷰 완료했습니다. 너무 멋집니다 👍 😄
src/main/java/Figure/Line.java
Outdated
|
|
||
| public class Line implements Calculator { | ||
|
|
||
| Points points; |
There was a problem hiding this comment.
기본적으로 변수는 private 로 숨겨야하는게 맞는데 ㅎㅎ 수정하겠습니다.
| List<Double> lens = new ArrayList<>(); | ||
|
|
||
| for(int i=1; i<4; i++) { | ||
| lens.add(stand.getDifferDistance(points.getPoint(i))); |
There was a problem hiding this comment.
이경우 직선만이 아닌 대각선의 길이도 구해야 하는데, 직선만 구해서 계산하는 방법은 어떤 것이 있을까요?
There was a problem hiding this comment.
넵,, 특정 한 점으로부터 나머지 세 점까지의 거리(getDifferDistance)를 구했습니다. 3개 중 가장 큰것이 대각선의 길이라서 나머지 두개만을 사용을 해봤는데 ㅎㅎ
이런식으로 계산하지않고 다른 방식이 있는지 고민해보겠습니다.
| double area = 0.5 * ( | ||
| pointA.getX() * (pointB.getY() - pointC.getY()) + | ||
| pointB.getX() * (pointC.getY() - pointA.getY()) + | ||
| pointC.getX() * (pointA.getY() - pointB.getY()) | ||
| ); |
There was a problem hiding this comment.
아뇨! ㅎㅎ 너무 좋습니다.
삼각형 넓이 식이 좀 복잡해서(계산식이 복잡해서), 해주신대로 조금 과하다싶을만큼 매소드로 빼도 괜찮은 것 같아요! 최대한 매소드 그 자체에서 무슨 일을 하는지 알 수 있으면 좋은 것 같습니다 ㅎㅎ
src/main/java/domain/Point.java
Outdated
| public static Point initPoint(int x, int y) { | ||
|
|
||
| if (x < 0 || x > 24 || y < 0 || y > 24) { | ||
| throw new IllegalArgumentException(Constants.INPUT_RANGE_CHECK); | ||
| } | ||
|
|
||
| return new Point(x, y); | ||
| } | ||
|
|
||
| public static Point inputStrSeparator(String inStr) { | ||
|
|
||
| String[] values = inStr.replaceAll("[()]", "").split(","); | ||
|
|
||
| return initPoint(Integer.parseInt(values[0]), Integer.parseInt(values[1])); | ||
|
|
||
| } |
There was a problem hiding this comment.
정적 팩토리 매서드 활용으로 용도를 나누신 점 너무 멋집니다.
다만 정적 팩토리 매서드는 몇가지 네이밍 패턴이 존재하는데요 (of, for 등)
해당 네이밍 패턴을 사용해보면 어떨까요?
| void 입력_좌표_포맷_Test() { | ||
|
|
||
| Throwable exception1 = assertThrows(RuntimeException.class, () -> { | ||
| InputView.validInputFormat("(3,4)"); | ||
| }); | ||
| assertEquals(Constants.INPUT_FORMAT_CHECK, exception1.getMessage()); | ||
|
|
||
| InputView.validInputFormat("(3,4)-(3,5)"); | ||
|
|
||
| Throwable exception3 = assertThrows(RuntimeException.class, () -> { | ||
| InputView.validInputFormat("(3,4)-(3,5)-(3,6)-(3,7)"); | ||
| }); | ||
| assertEquals(Constants.INPUT_FORMAT_CHECK, exception3.getMessage()); | ||
|
|
||
| Throwable exception4 = assertThrows(RuntimeException.class, () -> { | ||
| InputView.validInputFormat("(3,4)-(3,5,8)"); | ||
| }); | ||
| assertEquals(Constants.INPUT_FORMAT_CHECK, exception4.getMessage()); | ||
|
|
||
| Throwable exception5 = assertThrows(RuntimeException.class, () -> { | ||
| InputView.validInputFormat("(3,4)-(3,g)"); | ||
| }); | ||
| assertEquals(Constants.INPUT_FORMAT_CHECK, exception5.getMessage()); | ||
|
|
||
| } |
There was a problem hiding this comment.
효율적인 테스트 코드 작성을 위해 FIRST 라는 원칙에 기반하여 테스트를 작성하는 경우가 많습니다. 참고 링크
한 테스트 매서드 내에서 여러개를 검증하게 되면 어떤 것이 안좋을까요?
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class CalculatorTest { |
There was a problem hiding this comment.
관심사에 따라(Dot, Line, Triangle, Square) 테스트 클래스를 분리하면 어떨까요?
이렇게 하면 어떤 이점이 있을까요?
There was a problem hiding this comment.
(직선, 삼각형, 사각형)=> 을 계산하다 라는 테스트 케이스를 작성을 했었는데,
아무래도 각 도형에 따른 계산법이 다양하게 있다면 각각의 테스크를 분리하면 훨씬 가독성이 좋아지겠지요 !?
디테일하게 테스트가 가능하고 변경이 쉬울 것 같습니다.
2. 접근제한자 3. 정적 팩터리 메서드 패턴 리네이밍


1차 구현