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단계 - 문자열 계산기 #5657

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
afb3952
1단계 - 학습테스트 실습 (#5569)
kdfasdf Sep 24, 2024
7f59c4d
feat: implement requirement 1
kdfasdf Sep 26, 2024
a7c96bb
feat: implement requirement 2
kdfasdf Sep 27, 2024
e808659
feat: implement requirement 3
kdfasdf Sep 27, 2024
2724f87
implement requirement 4
kdfasdf Sep 27, 2024
7255cec
feat: implement requirement 5
kdfasdf Sep 27, 2024
d751a21
chore : rename file
kdfasdf Sep 27, 2024
81050ba
feat : implement requirement 6
kdfasdf Sep 27, 2024
a6163b7
chore : 미사용 파일 삭제 및 주석 추가
kdfasdf Sep 27, 2024
823b6cb
chore : 구현 내용 초기화
kdfasdf Sep 27, 2024
bedc9d1
feat : 요구사항1 구현
kdfasdf Sep 27, 2024
00b6c48
feat : 요구사항2 구현
kdfasdf Sep 27, 2024
4f9474d
feat : 요구사항 3 구현
kdfasdf Sep 27, 2024
7da8790
feat : 요구사항 4 구현
kdfasdf Sep 27, 2024
e557d7a
feat : 요구사항 5 구현
kdfasdf Sep 27, 2024
7415048
feat : 요구사항 6 구현
kdfasdf Sep 27, 2024
3fad8a6
chore : 상수추출 및 불필요한 메서드(validnegative) 제거
kdfasdf Sep 27, 2024
c8ea667
refactor : 숫자 합을 구하는 공통 로직, calculateSum 메서드로 추출
kdfasdf Sep 27, 2024
15b2371
chore : 불필요한 지역변수 제거
kdfasdf Sep 27, 2024
2249f09
refactor : if문 validNegativeNumberString메서드로 분리
kdfasdf Sep 27, 2024
188ea61
refactor : 정수 형변환 toInt()메서드로 책임 분리
kdfasdf Sep 27, 2024
8604a7e
chore : 코드 자동 정렬
kdfasdf Sep 27, 2024
3f0e234
refactor : 요구사항 1, 2 재구현 및 private() 생성자
kdfasdf Sep 28, 2024
639fcfc
refactor : 요구사항 3 재구현
kdfasdf Sep 28, 2024
4a4aa08
refactor : 요구사항 4 재구현
kdfasdf Sep 28, 2024
13c2117
refactor : 피드백 반영 및 요구사항 5 재구현
kdfasdf Sep 28, 2024
f9458c1
refactor : 요구사항 6 재구현 및 피드백 반영
kdfasdf Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor : 요구사항 1, 2 재구현 및 private() 생성자
- 아래 메서드들을 splitAndSum에 재구현
- emptyOrNull
- processOneNumberString
  • Loading branch information
kdfasdf committed Sep 28, 2024
commit 3f0e23421d8600d62e272c73d8de878bc81e6f52
14 changes: 7 additions & 7 deletions src/main/java/StringAddCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ public class StringAddCalculator {
public static final String COMMA = ",";
public static final String DELIMETER = ",|:";
public static final String CUSTOMDELIMETER = "//(.)\n(.*)";
public static final int DEFAULTVALUE_OF_NULL_AND_EMPTYSTRING = 0;

public static int emptyOrNull(String input) {
if (input == null || input.isEmpty()) {
return 0;
}
return 1;
private StringAddCalculator() {
throw new RuntimeException();
}

public static int processOneNumberString(String input) {
public static int splitAndSum(String input) {
if (input == null || input.isEmpty()) {
return DEFAULTVALUE_OF_NULL_AND_EMPTYSTRING;
}
return Integer.parseInt(input);
}

Expand Down Expand Up @@ -66,5 +67,4 @@ private static int[] toInt(String[] splited) {
}
return numbers;
}

}
4 changes: 2 additions & 2 deletions src/test/java/StringAddCalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class StringAddCalculatorTest {
@NullSource
@DisplayName("빈 문자열 또는 null이면 0을 반환")
void whenGivenNullOrEmpty(String input) {
int result = StringAddCalculator.emptyOrNull(input);
int result = StringAddCalculator.splitAndSum(input);

assertThat(result).isEqualTo(0);
}

@Test
@DisplayName("숫자 하나를 입력할 경우 해당 숫자를 반환한다")
void inputOneNumberStringReturnToInteger() {
int result = StringAddCalculator.processOneNumberString("1");
int result = StringAddCalculator.splitAndSum("1");

assertThat(result).isEqualTo(1);
}
Expand Down