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

๐Ÿš€ 2๋‹จ๊ณ„ - ๋ฌธ์ž์—ด ๋ง์…ˆ ๊ณ„์‚ฐ๊ธฐ #5891

Merged
merged 3 commits into from
Mar 14, 2025

Conversation

hyoojuu
Copy link

@hyoojuu hyoojuu commented Mar 11, 2025

No description provided.

Copy link

@mskangg mskangg left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ํšจ์ฃผ๋‹˜! :)
์ด๋ฒˆ ๋ฏธ์…˜ ๋ฆฌ๋ทฐ๋ฅผ ๋งก์€ ๊ฐ•๋ฏผ์ˆ˜์ž…๋‹ˆ๋‹ค ๐Ÿ™‡

2๋‹จ๊ณ„ ๋ฏธ์…˜ ์ž˜ ๊ตฌํ˜„ํ•ด์ฃผ์…จ๋„ค์š”! ๐Ÿ‘ ๐Ÿ’ฏ
์†Œ์†Œํ•œ ํ”ผ๋“œ๋ฐฑ ๋‚จ๊ฒจ๋“œ๋ ธ๋Š”๋ฐ ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค! ๐Ÿ™

Comment on lines 39 to 41
if (parsedValue < 0) {
throw new NumberFormatException();
}
Copy link

Choose a reason for hiding this comment

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

NumberFormatException ์€ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์ผ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์™ธ์ž…๋‹ˆ๋‹ค :)
์Œ์ˆ˜๋Š” ์ˆซ์ž์ด๊ธฐ ๋•Œ๋ฌธ์— ์˜ฌ๋ฐ”๋ฅธ ์˜ˆ์™ธ๋Š” ์•„๋‹๊ฒƒ ๊ฐ™์•„์š”! ๐Ÿค”

์Œ์ˆ˜๋ฅผ ์ „๋‹ฌํ•  ๊ฒฝ์šฐ RuntimeException ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•ด์•ผ ํ•œ๋‹ค. (์˜ˆ : โ€œ-1,2,3โ€) ์ด ์š”๊ตฌ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ”๋กœ ์˜ˆ์™ธ๋ฅผ ์ „ํŒŒํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์–ด๋–จ๊นŒ์š”?

Suggested change
if (parsedValue < 0) {
throw new NumberFormatException();
}
if (parsedValue < 0) {
throw new RuntimeException();
}

Copy link
Author

Choose a reason for hiding this comment

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

๋„ต ํ•ด๋‹น ์กฐ๊ฑด์— ์ ์ ˆํ•œ ์˜ˆ์™ธ์ธ์ง€์— ๋Œ€ํ•œ ํŒ๋‹จ์„ ๋†“์นœ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ง์”€ํ•ด์ฃผ์‹ ๋Œ€๋กœ ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Comment on lines 43 to 45
} catch (NumberFormatException e) {
throw new RuntimeException();
}
Copy link

Choose a reason for hiding this comment

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

๋ณ„๋„ try/catch ๋ฌธ์„ ํ•  ํ•„์š” ์—†์„๊ฒƒ ๊ฐ™์•„์š”!

NumberFormatException ์€ unchecked exception ์ด๊ธฐ๋„ ํ•˜๊ตฌ์š”!

java.lang.Object
  โ””โ”€โ”€ java.lang.Throwable
        โ””โ”€โ”€ java.lang.Exception
              โ””โ”€โ”€ java.lang.RuntimeException
                    โ””โ”€โ”€ java.lang.IllegalArgumentException
                          โ””โ”€โ”€ java.lang.NumberFormatException

Copy link

Choose a reason for hiding this comment

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

์•„! @hyoojuu ๋‹˜

๋ฌธ์ž์—ด ๊ณ„์‚ฐ๊ธฐ์— ์ˆซ์ž ์ด์™ธ์˜ ๊ฐ’ ๋˜๋Š” ์Œ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒฝ์šฐ RuntimeException ์˜ˆ์™ธ๋ฅผ throwํ•œ๋‹ค.
์ด ์š”๊ตฌ์‚ฌํ•ญ์„ ์ง€ํ‚ค๊ธฐ ์œ„ํ•ด catch ํ•˜๊ณ  ๋‹ค์‹œ ๋ถ€๋ชจ ์˜ˆ์™ธ๋กœ ์ „ํŒŒํ•˜์‹ ๊ฑธ๊นŒ์š”? ๐Ÿ˜…

NumberFormatException ์€ Runtime ์„ ์ƒ์†ํ•˜๊ณ  ์žˆ๋Š” ์˜ˆ์™ธ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์‹œ ์˜ˆ์™ธ๋ฅผ ์ „ํŒŒํ•  ํ•„์š”๊ฐ€ ์—†์„๊ฒƒ ๊ฐ™์•„๋ณด์—ฌ์„œ ํ”ผ๋“œ๋ฐฑ ๋‚จ๊ฒผ์Šต๋‹ˆ๋‹น ๐Ÿ˜„
์ด๋ฏธ ์•Œ๊ณ  ๊ณ„์…จ๋˜ ๋‚ด์šฉ์ด๋ผ๋ฉด ์Šค์œฝ~ ์ง€๋‚˜๊ฐ€์‹œ๋ฉด ๋ ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ™ƒ

Copy link
Author

Choose a reason for hiding this comment

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

์•— ๋„ต,, ์ƒ์†ํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์€ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ
Unchecked Exception์€ ๋ช…์‹œ์ ์œผ๋กœ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ์ ์— ๋Œ€ํ•œ ์ดํ•ด๊ฐ€ ๋ถ€์กฑํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

int size = this.numbers.size();

assertThat(size).isEqualTo(3);
assertThat(this.numbers).hasSize(3);
Copy link

Choose a reason for hiding this comment

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

๐Ÿ‘

}

@ParameterizedTest
@ValueSource(ints = {1, 2, 3})
void ์ˆซ์ž_ํฌํ•จ์—ฌ๋ถ€_ํ™•์ธ(int value) {
assertThat(this.numbers.contains(value)).isTrue();
assertThat(this.numbers).contains(value);
Copy link

Choose a reason for hiding this comment

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

๐Ÿ‘

Comment on lines 19 to 28
private static String[] split(String text) {
Matcher matcher = PATTERN.matcher(text);
if (!matcher.find()) {
return text.split(DELIMITER);
}

String customDelimiter = matcher.group(1);
String delimitedText = matcher.group(2);
return delimitedText.split(customDelimiter);
}
Copy link

Choose a reason for hiding this comment

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

์ด๋ฒˆ ๋ฏธ์…˜์—์„œ ์ค‘์š”ํ•œ ๊ธฐ๋Šฅ์„ ๋‹ด๋‹นํ•˜๋Š” split ๋ฉ”์„œ๋“œ์—์„œ ๋‘๊ฐ€์ง€์˜ ํ–‰์œ„๋ฅผ ํ•˜๊ณ  ์žˆ๋Š”๊ฒƒ ๊ฐ™์•„์š”!

  1. ๊ตฌ๋ถ„์ž๋ฅผ ์ฐพ๊ธฐ
  2. ๊ตฌ๋ถ„์ž๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌ

split ์ด๋ผ๋Š” ๋ฉ”์„œ๋“œ๋Š” 2๋ฒˆ์— ํ•ด๋‹นํ•˜๋Š” ํ–‰์œ„๋งŒ ์กด์žฌํ•˜๊ฒŒ ๋ฆฌํŒฉํ† ๋ง ํ•˜๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”? ๐Ÿค”

    private static String[] split(String text, String delimiter) {
        return text.split(delimiter);
    }

์œ„ ์ฒ˜๋Ÿผ ๋ฆฌํŒฉํ† ๋ง์ด ๋˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฉ”์„œ๋“œ๋กœ ๋‚˜๋ˆ„๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์„๊ฒƒ ๊ฐ™์•„์š” :)

  1. ๊ตฌ๋ถ„์ž๋ฅผ ์ฐพ๊ธฐ
  2. ๊ตฌ๋ถ„์ž๋กœ ๋ถ„ํ• ํ•  text ์ถ”์ถœ
String delimiter = findDelimiter(text);
String textToSplit = findTextToSplit(text);
sum(toInt(split(textToSplit, delimiter);

Copy link
Author

Choose a reason for hiding this comment

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

๋„ต ๋ง์”€ํ•ด์ฃผ์‹ ๋Œ€๋กœ 1, 2 ๊ฐ๊ฐ์˜ ํ–‰์œ„๋งŒ ํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋กœ ๋ถ„๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link

@mskangg mskangg left a comment

Choose a reason for hiding this comment

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

ํ”ผ๋“œ๋ฐฑ๋ฐ˜์˜ ์ž˜ํ•ด์ฃผ์…จ๋„ค์š”! ๐Ÿ‘
๋‹ค์Œ ๋‹จ๊ณ„ ์ง„ํ–‰์‹œ์—๋Š” ์š”๊ตฌ์‚ฌํ•ญ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์ฒดํฌ๋ฆฌ์ŠคํŠธ๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•œ ๋’ค ์ง„ํ–‰ํ•ด๋ณด์‹œ๋Š”๊ฒƒ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค!
๊ทธ๋Ÿผ ๋‹ค์Œ ๋‹จ๊ณ„ ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š” ๐Ÿ”ฅ

Comment on lines +17 to +19
String delimiter = findDelimiter(text);
String textToSplit = findTextToSplit(text);
return sum(toInts(split(textToSplit, delimiter)));
Copy link

Choose a reason for hiding this comment

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

๐Ÿ’ฏ

return parsedValue;
}

private static void validate(int value) {
Copy link

Choose a reason for hiding this comment

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

๐Ÿ‘

@mskangg mskangg merged commit 218846d into next-step:hyoojuu Mar 14, 2025
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.

2 participants