Skip to content

Point, Points 도메인 구현 #2

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 3 commits into
base: feature/fuel-injection
Choose a base branch
from

Conversation

dongKos
Copy link
Contributor

@dongKos dongKos commented May 5, 2023

TDD로 구현해본 도메인

@dongKos dongKos requested review from chs1234 and wapago May 5, 2023 13:57
@dongKos dongKos self-assigned this May 5, 2023
@dongKos dongKos marked this pull request as draft May 5, 2023 14:01
@dongKos dongKos force-pushed the feature/coordinate-calculator-line branch from b903e7b to d547f04 Compare May 5, 2023 14:15
@dongKos dongKos marked this pull request as ready for review May 5, 2023 14:15

@Test
void 객체비교테스트2() {
assertNotEquals(new Points("(10,10)-(14,15)"), new Points("(10,9)-(14,15)"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

객체간의 비교는 getter를 사용하는것이 아닌 equals, hashcode를 구현해서 객체간 비교를 한다

Copy link

Choose a reason for hiding this comment

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

흠,,, 객체비교를 해야 하는 군요

Copy link

@chs1234 chs1234 left a comment

Choose a reason for hiding this comment

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

음주 리뷰,,(술냄새가 풍긴다면 죄송쓰)

class PointsTest {

@ParameterizedTest
@CsvSource({"ashjkd", "(10,10,123)-(14,15)", "(10,10)-(14,151,123)", "12379612679"})
Copy link

Choose a reason for hiding this comment

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

valueSource, methodSource말고 csvsource도 있었군요..!

Copy link

Choose a reason for hiding this comment

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

근데 valueSource랑 어떤 차이가 있나요..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

원래는 csv file에서 테스트 stub을 가져오기 위해 사용하는 어노테이션.. 파일경로 입력가능. 근데 valueSource처럼 쓸 수도 있습니다. methodSource는 첨들어보는데 무엇에 쓰는 물건인고?

Copy link

Choose a reason for hiding this comment

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

지난번 레이싱 경주 코드 중 CarsTest에서 가져왔습니당
Stream를 리턴해서 테스트 데이터s의 인자들을 정의해서 넘길 수 있습니당!

    @ParameterizedTest
    @MethodSource("invalidParameters")
    @DisplayName("잘못된 자동차 이름 에러 테스트")
    void test(String parameter, String name) {
        InvalidCarNameException invalidCarNameException = assertThrows(InvalidCarNameException.class, () -> new Cars(parameter));
        assertEquals(name, invalidCarNameException.getMessage());
    }

    static Stream<Arguments> invalidParameters() {
        return Stream.of(
                Arguments.of("", ErrorMessage.CarName.NOT_ALLOW_EMPTY_OR_CONTAINS_WHITE_SPACE),
                Arguments.of(" ", ErrorMessage.CarName.NOT_ALLOW_EMPTY_OR_CONTAINS_WHITE_SPACE),
                Arguments.of("onlyOneCar", ErrorMessage.CarName.NOT_EXIST_COMMA),
                Arguments.of("12345,123456", ErrorMessage.CarName.NOT_EXCEED_CAR_NAME_LENGTH),
                Arguments.of(",car", ErrorMessage.CarName.NOT_START_WITH_COMMA),
                Arguments.of("car,", ErrorMessage.CarName.NOT_END_WITH_COMMA),
                Arguments.of("car1,car1,car2", ErrorMessage.CarName.NOT_DUPLICATE_CAR_NAME)
        );
    }


@Override
public int hashCode() {
return Objects.hash(points);
Copy link

Choose a reason for hiding this comment

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

혹시 인텔리제이 자동 추천 코드인가요?
전 커뮤니티 라이센스가 종료되서 부득이하게 VSCode로 작성했는데
VScode에서는 @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((points == null) ? 0 : points.hashCode()); return result; }

이런 식으로 추천해주더라구요..

Copy link

Choose a reason for hiding this comment

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

아 이거 인덴트가 안먹나 보기 힘드네;;;

Copy link
Contributor Author

@dongKos dongKos May 5, 2023

Choose a reason for hiding this comment

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

인텔리제이 기본 추천 코드고 내부까보니 비슷하게 생겼네용
인덴트 먹일라면 ``` 이렇게 세번 쓰면 됩니당

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hash collision 막기 위해서 상대적으로 작은 소수를 곱하는데 그게 보통 31입니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

전 오늘 인텔리제이 라이선스 샀습니당.. 후..

Copy link

Choose a reason for hiding this comment

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

테스트 stub, hashcollision,,, 공부할게 많네여ㅎㅎ


Copy link

Choose a reason for hiding this comment

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

문서가 자세해서 너무 좋습니다ㅎㅎ 덩달아 힌트도 얻어가네요!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants