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๋‹จ๊ณ„ - ๋ฌธ์ž์—ด ๋ง์…ˆ ๊ณ„์‚ฐ๊ธฐ #5916

Merged
merged 7 commits into from
Mar 14, 2025

Conversation

nno0obb
Copy link

@nno0obb nno0obb commented Mar 12, 2025

No description provided.

Copy link

@pci2676 pci2676 left a comment

Choose a reason for hiding this comment

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

์กฐ๊ธˆ ๋” ๊ฐœ์„ ํ•ด๋ณด๋ฉด ์ข‹์„ ๋ถ€๋ถ„์— ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ฒจ๋‘์—ˆ์œผ๋‹ˆ ํ™•์ธํ•ด์ฃผ์„ธ์š”~!

๋ฐ˜๋“œ์‹œ ๋ชจ๋“  ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•  ํ•„์š”๋Š” ์—†์ง€๋งŒ ํ•œ๋ฒˆ์ฏค ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

public class StringAddCalculatorTest {

@Test
public void splitAndSum_null() {
Copy link

Choose a reason for hiding this comment

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

๋ชจ๋“  ํ…Œ์ŠคํŠธ์— ์ด๋ฆ„์„ ๋ถ€์—ฌํ•ด์ฃผ์…จ๊ตฐ์š” ๐Ÿ‘

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋Š” ํ•˜๋‚˜์˜ ๋ฌธ์„œ๋กœ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ์š”~!

์กฐ๊ธˆ ๋” ํ…Œ์ŠคํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚ด๊ณ ์ž ํ•˜๋Š” ๋ฐ”๋ฅผ ๋“œ๋Ÿฌ๋‚ผ ์ˆ˜ ์žˆ๋„๋ก ์ด๋ฆ„์„ ์ž‘์„ฑํ•ด๋ณด๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”?

๊ฐ€๋ น ํ…Œ์ŠคํŠธ์—์„œ ํ•˜๋Š” ํ–‰์œ„์™€ ๊ทธ ํ–‰์œ„๋กœ ์ธํ•ด ์–ด๋– ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋Š” ์‹์œผ๋กœ ์ด๋ฆ„์„ ์ง€์–ด๋ณผ ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

"how to write test case name"๋ผ๊ณ  ๊ฒ€์ƒ‰์„ ํ•ด๋ณด์‹œ๋ฉด ์ด์— ๋Œ€ํ•ด ๋‹ค๋ฃจ๋Š” ๊ธ€์ด ๋งŽ์œผ๋‹ˆ ํ•œ๋ฒˆ ๊ฒ€์ƒ‰ํ•ด๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)

๋˜ํ•œ @DisplayName์„ ์ด์šฉํ•˜์—ฌ ํ•œ๊ธ€๋กœ ๋œ ํ…Œ์ŠคํŠธ ์ด๋ฆ„์„ ์ž‘์„ฑํ•˜๊ธฐ๋„ ํ•˜๋‹ˆ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”~

Copy link
Author

@nno0obb nno0obb Mar 14, 2025

Choose a reason for hiding this comment

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

  • Baeldung :: Best Practices for Unit Testing in Java ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!
  • @DisplayName ๋„ ํ™œ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment on lines 52 to 68
@Test
public void splitAndSum_negative() {
assertThatThrownBy(() -> StringAddCalculator.splitAndSum("-1,2,3"))
.isInstanceOf(RuntimeException.class);
}

@Test
public void splitAndSum_delimCustomAndNegative() {
assertThatThrownBy(() -> StringAddCalculator.splitAndSum("//-\n-1-2-3"))
.isInstanceOf(RuntimeException.class);
}

@Test
public void splitAndSum_blank() {
assertThatThrownBy(() -> StringAddCalculator.splitAndSum(" "))
.isInstanceOf(RuntimeException.class);
}
Copy link

Choose a reason for hiding this comment

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

๋ชจ๋‘ RuntimeException์— ๋Œ€ํ•ด์„œ๋งŒ ๊ฒ€์‚ฌ๋ฅผ ํ•˜๊ณ  ์žˆ๋„ค์š”!

๊ทธ๋ ‡๋‹ค๋ฉด ๋ชจ๋‘ ์˜ˆ์ƒํ•˜์‹  ๋ถ€๋ถ„์—์„œ exception์ด throw ๋˜์—ˆ๋‹ค๊ณ  ํ™•์‹ ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?

์กฐ๊ธˆ ๋” ์‹ ๋ขฐ์„ฑ ์žˆ๋Š” ๊ฒ€์‚ฌ๋ฅผ ํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

์•„๋ž˜ ๊ธ€์„ ์ฐธ๊ณ ํ•ด๋ณด์…”๋„ ์ข‹์Šต๋‹ˆ๋‹ค~

https://bottom-to-top.tistory.com/97

Copy link
Author

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;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class StringAddCalculatorTest {
Copy link

Choose a reason for hiding this comment

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

์ „์ฒด์ ์œผ๋กœ ํ…Œ์ŠคํŠธ๋ฅผ ์ผ€์ด์Šค๋ณ„๋กœ ๊ผผ๊ผผํ•˜๊ฒŒ ์ž‘์„ฑํ•ด์ฃผ์‹ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ‘

๊ทธ๋Ÿฐ๋ฐ ์กฐ๊ธˆ ๋” ๊ฐœ์„ ํ•ด๋ณผ๋งŒํ•œ ๋ถ€๋ถ„์ด ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

splitAndSum์ด๋ผ๋Š” ์ด๋ฆ„์—์„œ ์•Œ ์ˆ˜ ์žˆ๋“ฏ

split๊ณผ sum ๊ธฐ๋Šฅ์ด ํ•œ๊ณณ์— ๊ตฌํ˜„์ด ๋˜์–ด์žˆ๋‹ค๋ณด๋‹ˆ

๊ตฌ๋ถ„์ž๊ฐ€ ๋™์ž‘ํ•˜๋Š”๊ฒƒ๋„ sum์„ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ๋„ ํ•˜๋‚˜์˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์ผ๋ จ์˜ ๊ฒฐ๊ณผ๋กœ ํ™•์ธ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

SRP๋ฅผ ์ค€์ˆ˜ํ•˜๋ ค๋ฉด "๊ตฌ๋ถ„์ž๋ฅผ ํ†ตํ•œ ๋ฌธ์ž์—ด ๋ถ„๋ฆฌ"์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ๊ณผ "๋ถ„๋ฆฌ๋œ ๋ฌธ์ž์—ด๋“ค์˜ ํ•ฉ"์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ์€ ์„œ๋กœ ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์•„์•ผ ํ•˜์ง€ ์•Š์„๊นŒ์š”?

๋ฌธ์ž์—ด์„ ๊ตฌ๋ถ„ํ•˜๋Š” ๋Šฅ๋ ฅ์„ ๊ฐ€์ง„ ํด๋ž˜์Šค์™€ ๋ฌธ์ž์—ด๋“ค์˜ ์ง‘ํ•ฉ์„ ์ด์šฉํ•ด ๊ณ„์‚ฐ์„ ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ์„ค๊ณ„ํ•œ๋’ค ๋‘ ํด๋ž˜์Šค๊ฐ€ ์„œ๋กœ ๋ฉ”์„ธ์ง€๋ฅผ ์ฃผ๊ณ  ๋ฐ›์œผ๋ฉฐ ํ˜‘๋ ฅํ•˜๋Š” ๊ทธ๋ฆผ์ด ๊ทธ๋ ค์ง€๋„๋ก ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. :)

๊ทธ๋ ‡๊ฒŒ ํ•œ๋‹ค๋ฉด ๊ฐœ๋ณ„์ ์ธ ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•ด์งˆ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~

Copy link
Author

Choose a reason for hiding this comment

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

  • SPR(Single Responsibility Principle) ์ž„์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.
  • splitAndSum --> split + sum ์œผ๋กœ ๋ถ„๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

if (!isValid(input)) {
return 0;
}
int[] tokens = tokenize(input);
Copy link

Choose a reason for hiding this comment

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

์—ฌ๋Ÿฌ๊ฐœ์˜ token์„ ๋‹ค๋ฃจ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ๋ฐฐ์—ด์„ ์„ ํƒํ•˜์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋‹ค๋ฅธ collection(ex. List)๋“ค๋„ ์ด๋ฃจ๊ณ ์ž ํ•˜๋Š” ๋ฐ”๋ฅผ ๋‹ฌ์„ฑํ•˜๊ธฐ์— ์ข‹์€ ์„ ํƒ์ง€๊ฐ€ ๋  ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์€๋ฐ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹ค๊นŒ์š”? ๋ฐฐ์—ด์„ ์„ ํƒํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•˜๋„ค์š” :)

Copy link
Author

Choose a reason for hiding this comment

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

  • ์ œ๊ฐ€ ์ž๋ฐ”๋ฅผ ์ž˜ ๋ชฐ๋ผ์„œ... (Python3 ๊ฐ€ ์ฃผ๋ ฅ์ด๊ณ  ์ •๋ง Java ๋ฅผ ์ž˜ ๋ชจ๋ฆ…๋‹ˆ๋‹ค)
  • ๋„ต๋„ต, Collection ์œผ๋กœ ์ „ํ™˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link

Choose a reason for hiding this comment

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

๊ผญ ์ „ํ™˜์„ ๋ฐ”๋ž€ ๋ฆฌ๋ทฐ๋Š” ์•„๋‹ˆ์—ˆ์Šต๋‹ˆ๋‹ค :)

์ €์™€ ๋‚˜๋ˆ„๋Š” ๋ชจ๋“  ๋ฆฌ๋ทฐ๋Š” ์ƒ๊ฐ์„ ๋‚˜๋ˆ„๋Š” ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ•˜๊ณ  ๋ชจ๋“  ๋ถ€๋ถ„์„ ๊ผญ ๊ณ ์ณ์•ผํ•˜๋Š” ์‚ฌํ•ญ์œผ๋กœ ๋ฐ›์•„๋“ค์ด๊ธฐ ๋ณด๋‹ค

์–ด๋– ํ•œ ์˜์‹์˜ ํ๋ฆ„์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด์•˜๋Š”์ง€, ์˜๊ฒฌ์„ ๊ต๋ฅ˜ํ•˜๋Š” ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ•ด์ฃผ์„ธ์š”~!


public class StringAddCalculator {
public static int splitAndSum(String input) {
if (!isValid(input)) {
Copy link

Choose a reason for hiding this comment

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

!๋ฅผ ์ด์šฉํ•ด ๋ถ€์ • ํ‘œํ˜„์„ ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์ง€๋งŒ ์ธ์ง€๋ถ€ํ•˜๋ฅผ ๋Š˜๋ฆฌ๋Š” ์š”์†Œ๋กœ ์ž‘์šฉํ•  ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๊ฐ€๋Šฅํ•˜๋ฉด ๋ฉ”์„œ๋“œ์˜ ์ด๋ฆ„์—์„œ ๋ถ€์ •ํ‘œํ˜„์ด ๋“œ๋Ÿฌ๋‚˜๋„๋ก ํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

ex. isNotValid, isInvalid

Copy link
Author

Choose a reason for hiding this comment

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

  • ๋„ต, ๋ช…์‹œ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋‚˜๋„๋ก ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

if (Pattern.matches("(//\\D\\n)*(\\d+\\D)*\\d+", input)) {
return true;
}
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.

exception์„ ๋ฐœ์ƒ์‹œํ‚ฌ๋•Œ๋Š” ๊ทธ ์ด์œ ์— ๋Œ€ํ•ด ํ•จ๊ป˜ ๋ฉ”์„ธ์ง€๋กœ ์ „๋‹ฌํ•ด์ฃผ๋ฉด ๋” ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. :)

Copy link
Author

Choose a reason for hiding this comment

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

  • ๋„ต, ๋ฉ”์‹œ์ง€๊นŒ์ง€ ๋„ฃ์–ด์„œ ์ข€ ๋” ํŠน์ •ํ•  ์ˆ˜ ์žˆ๋Š” Exception ์„ ๋ฐœ์ƒ์‹œํ‚ค๋„๋ก ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment on lines 27 to 32
String[] delimiters = new String[]{",", ":"};
Matcher m = Pattern.compile("//(\\D)\n(.*)").matcher(input);
if (m.find()) {
delimiters = new String[]{delimiters[0], delimiters[1], m.group(1)};
input = m.group(2);
}
Copy link

Choose a reason for hiding this comment

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

์—ฌ๊ธฐ์„œ ๋˜ ๋‹ค๋ฅธ ํŒจํ„ด์˜ ๊ตฌ๋ถ„์ž๋ฅผ ์ง€์›ํ•˜๋Š” ๋ฐฉ์‹์ด ์ƒ๊ธด๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ๋Œ€์ฒ˜ํ•ด์•ผํ• ๊นŒ์š”?

๊ณ„์†ํ•ด์„œ if์ ˆ์ด ์ถ”๊ฐ€๋˜๊ณ  ๊ทธ์—๋”ฐ๋ฅธ delimiters๋ฅผ ํ• ๋‹นํ•ด์ฃผ์–ด์•ผํ• ๊ฒƒ ๊ฐ™์€๋ฐ์š”.

์ „๋žตํŒจํ„ด์„ ์ด์šฉํ•ด์„œ ํ™•์žฅ์— ์šฉ์ดํ•œ ๊ตฌ์กฐ๋ฅผ ์ทจํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

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 30 to 31
delimiters = new String[]{delimiters[0], delimiters[1], m.group(1)};
input = m.group(2);
Copy link

Choose a reason for hiding this comment

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

๊ธฐ์กด์— ์‚ฌ์šฉ์ค‘์ด๋˜ ๊ฐ’์„ ๊ณ„์†ํ•ด์„œ ํ• ๋‹นํ•˜๋ฉฐ ๋‹ค๋ฅธ ์šฉ๋„๋กœ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์ด๋Š” ์ฝ”๋“œ๋ฅผ ์ฝ๋Š”๋ฐ ๋ฐฉํ•ด๊ฐ€ ๋˜๋Š” ์š”์†Œ๋กœ ์ž‘์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ณ„์†ํ•ด์„œ ๋ณ€๊ฒฝ๋˜๋Š” ์˜๋ฏธ๋ฅผ ํŒŒ์•…ํ•ด์•ผํ•˜๋‹ˆ๊นŒ์š”~

๊ฐ€๋Šฅํ•œ ๋ถˆ๋ณ€ํ•œ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋„๋ก ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Copy link
Author

Choose a reason for hiding this comment

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

  • ๋„ต, ๋ถˆ๋ณ€ํ•œ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋„๋ก ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

@pci2676
Copy link

pci2676 commented Mar 13, 2025

์ถ”๊ฐ€๋กœ PR ๋ณธ๋ฌธ์— ๋ฆฌ๋ทฐ๋ฅผ ์š”์ฒญ์ฃผ์‹ค๋•Œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์š”๊ตฌ์‚ฌํ•ญ์„ ์ ์–ด์ฃผ์‹œ๋ฉด ์ œ๊ฐ€ ๋ฆฌ๋ทฐํ•˜๋Š”๋ฐ ํฐ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์•„๋ž˜ ๊ธ€์„ ์ฐธ๊ณ ํ•ด๋ณด์…”๋„ ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”~

https://bottom-to-top.tistory.com/96

@nno0obb
Copy link
Author

nno0obb commented Mar 14, 2025

  • Blog :: ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์š”์ฒญ์— ์ •์„ฑ์„ ๋‹ด์•„๋ณด์ž ์ข‹์€ ๊ธ€์„ ๊ณต์œ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
  • ์Œ... ์ธํ”„๋ผ ์ง๊ตฐ์— ๊ทผ๋ฌดํ•˜๋ฉด์„œ ์ด๋Ÿฐ ์ฝ”๋”ฉ ๊ฐ•์˜๋ฅผ ๋“ฃ๋Š”๊ฒŒ ์ฒ˜์Œ์ด๋ผ ๊ฐ์„ ์žก๊ธฐ ์–ด๋ ต๋„ค์š”...
  • ๋ถ€์กฑํ•œ ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ๊ฐ€๊ฐ์—†์ด ํ”ผ๋“œ๋ฐฑ ๋ถ€ํƒ๋“œ๋ฆฌ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.
  • (์ •์„ฑ์ด ์—†๋Š” ์ฝ”๋“œ๋ฆฌ๋ทฐ์—๋„) ์นœ์ ˆํ•˜๊ณ  ๊ผผ๊ผผํžˆ ๋‹ต๋ณ€ํ•ด์ฃผ์…”์„œ ์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :D

Copy link

@pci2676 pci2676 left a comment

Choose a reason for hiding this comment

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

๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ•˜๋ฉฐ ์ด๋ฒˆ ๋‹จ๊ณ„์— ๋‚จ๊ฒจ๋“œ๋ฆฐ ๋ฆฌ๋ทฐ๋ฅผ ํ•œ๋ฒˆ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. :)

mergeํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿš€

Comment on lines +12 to +39
public class StringAddCalculatorToken {

private final int value;

public StringAddCalculatorToken(String value) {
if (value.isEmpty()) {
this.value = 0;
return;
}
this.value = Integer.parseInt(value);
validate();
}

public StringAddCalculatorToken(int number) {
this.value = number;
validate();
}

private void validate() {
if (this.value < 0) {
throw new StringAddCalculatorTokenException("Don't allow negative number");
}
}

public int toInteger() {
return this.value;
}
}
Copy link

Choose a reason for hiding this comment

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

๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘

๊ทธ๋Ÿฐ๋ฐ Exception๊ณผ ๊ฐ™์€ ํŒŒ์ผ์— ์„ ์–ธํ•ด๋‘๋ฉด ํด๋ž˜์Šค๋ฅผ ์ฐพ๊ธฐ ์–ด๋ ค์šฐ๋‹ˆ ๋…๋ฆฝ์ ์œผ๋กœ ์„ ์–ธํ•ด์ฃผ์‹œ๋ฉด ๋” ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. :)

Comment on lines +3 to +12
public class StringAddCalculatorTokenCalculator {

public static int sum(StringAddCalculatorToken[] tokens) {
int result = 0;
for (StringAddCalculatorToken stringAddCalculatorToken : tokens) {
result += stringAddCalculatorToken.toInteger();
}
return result;
}
}
Copy link

Choose a reason for hiding this comment

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

์˜ค sum์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ณ„๋„์˜ ์—ญํ• ์„ ํ‘œํ˜„ํ•ด์ฃผ์…จ๋„ค์š”~!

์ด์™€ ๊ด€๋ จํ•˜์—ฌ ์ผ๊ธ‰์ปฌ๋ ‰์…˜์ด๋ผ๋Š” ๊ฐœ๋…์„ ํ•œ๋ฒˆ ์ฐพ์•„๋ณด์‹œ๊ณ  ๋‹ค์Œ ๋ฏธ์…˜๋ถ€ํ„ฐ ์ฐธ๊ณ ํ•˜์—ฌ ๋ฐ˜์˜ํ•ด๋ณด์‹œ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)

Comment on lines +20 to +27
for (String customDelimiterRegex : defaultCustomDelimiterRegexes) {
Matcher matcher = Pattern.compile(customDelimiterRegex).matcher(input);
if (matcher.find()) {
String customDelimiter = matcher.group(1);
delimiters.add(customDelimiter);
input = matcher.group(2);
}
}
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 +23 to +25
String customDelimiter = matcher.group(1);
delimiters.add(customDelimiter);
input = matcher.group(2);
Copy link

Choose a reason for hiding this comment

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

1๊ณผ 2๋Š” ์–ด๋– ํ•œ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๋Š” ์ˆซ์ž์ผ๊นŒ์š”? ๐Ÿค”

๋‹ค๋ฅธ์‚ฌ๋žŒ์ด ๋‹จ๋ฒˆ์— ์•Œ์•„์ฐจ๋ฆด ์ˆ˜ ์žˆ๋„๋ก ์ด๋ฆ„์„ ๋ถ€์—ฌํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

https://bottom-to-top.tistory.com/100

public class StringAddCalculatorTest {

@Test
@DisplayName("input: null --> output: 0")
Copy link

Choose a reason for hiding this comment

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

์ €๋Š” ๋ณดํ†ต ํ…Œ์ŠคํŠธ ์ด๋ฆ„์€ ์„œ์ˆ ์ ์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š” ํŽธ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~

"์ž…๋ ฅ์ด null์ด๋ฉด ๊ธฐ๋ณธ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค." ์™€ ๊ฐ™์ด ์ง€์„ ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™๋„ค์š” :)

@pci2676 pci2676 merged commit 323b65b into next-step:nno0obb 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.

3 participants