-
Notifications
You must be signed in to change notification settings - Fork 67
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
신재한 1주차 과제 1차 수정본 #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Calculator { | ||
public int add(int a, int b) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
간단한 부분이지만, 습관을 가지는 것이 좋다고 생각합니다 ! |
||
return a + b; | ||
} | ||
|
||
public int sub(int a, int b) { | ||
return a - b; | ||
} | ||
|
||
public int mul(int a, int b) { | ||
return a * b; | ||
} | ||
|
||
public int div(int a, int b) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return a / b; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import java.util.Arrays; | ||
|
||
public class String_Calculator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public int add(String String_nums) { | ||
int[] nums = check(String_nums); | ||
|
||
int sum = nums[0]; | ||
for (int token : Arrays.copyOfRange(nums, 1, nums.length)) { | ||
sum += token; | ||
} | ||
return sum; | ||
} | ||
|
||
|
||
public static int sub(String String_nums) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static 메소드로 선언한 이유가 궁금합니다..! 이전 리뷰 확인 부탁드릴께요 |
||
int[] nums = check(String_nums); | ||
|
||
int sum = nums[0]; | ||
for (int token : Arrays.copyOfRange(nums, 1, nums.length)) { | ||
sum -= token; | ||
} | ||
return sum; | ||
Comment on lines
+19
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
간단한 for문으로 nums 배열을 순회할 수 있을 거 같아요 ! |
||
} | ||
|
||
public static int mul(String String_nums) { | ||
int[] nums = check(String_nums); | ||
|
||
int sum = nums[0]; | ||
for (int token : Arrays.copyOfRange(nums, 1, nums.length)) { | ||
sum *= token; | ||
} | ||
return sum; | ||
} | ||
|
||
public static int div(String String_nums) { | ||
int[] nums = check(String_nums); | ||
|
||
int sum = nums[0]; | ||
for (int token : Arrays.copyOfRange(nums, 1, nums.length)) { | ||
sum /= token; | ||
} | ||
return sum; | ||
} | ||
|
||
public static int[] check(String String_nums) { | ||
String[] tokens = new String[String_nums.length()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 초기 값 설정을 위해서 다음과 같이 선언하셨다면, 아래 내용에 대해서 조사해보면 좋을 거 같아요.
|
||
|
||
if (String_nums.contains(",") || String_nums.contains(";")) tokens = String_nums.split("[,|;]"); | ||
if (String_nums.contains("//")) { | ||
String_nums = String_nums.substring(String_nums.indexOf("\n") + 1); | ||
tokens = String_nums.split("[,|;]"); | ||
} | ||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 커스텀 문자열 적용을 하고 있지 않는 거 같아요. |
||
|
||
for (int i = 0; i < tokens.length; i++) { | ||
if (!tokens[i].matches("-?\\d+")) { | ||
throw new RuntimeException("양수가 아닌 값이 입력되었습니다."); | ||
} | ||
} | ||
|
||
int[] nums = new int[tokens.length]; | ||
|
||
for (int i = 0; i < tokens.length; i++) { | ||
nums[i] = Integer.parseInt(tokens[i]); | ||
} | ||
|
||
return nums; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Cal_Test { | ||
|
||
@Nested | ||
@DisplayName("계산기 사칙연산 테스트") | ||
class CalTest { | ||
|
||
@Test | ||
void AddTest() { | ||
Calculator calc = new Calculator(); | ||
assertEquals(3, calc.add(1,2)); | ||
} | ||
|
||
@Test | ||
void SubTest() { | ||
Calculator calc = new Calculator(); | ||
assertEquals(2, calc.sub(8,6)); | ||
} | ||
|
||
@Test | ||
void MulTest() { | ||
Calculator calc = new Calculator(); | ||
assertEquals(2, calc.mul(1,2)); | ||
} | ||
|
||
@Test | ||
void DivTest() { | ||
Calculator calc = new Calculator(); | ||
assertEquals(6, calc.div(12,2)); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class StringCal_AssertJTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 약어에 대해서 한 번 생각해보면 좋을 거 같아요. |
||
@Nested | ||
@DisplayName("문자열 계산기 사칙연산 테스트") | ||
class AssertJ_CalTest { | ||
|
||
@Test | ||
void AddTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(7).isEqualTo(calc.add("3,4")); | ||
} | ||
@Test | ||
void AddTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(6).isNotEqualTo(calc.add("//;\n1;2;4")); | ||
} | ||
|
||
@Test | ||
void SubTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(6).isEqualTo(calc.add("1;2;3")); | ||
} | ||
|
||
@Test | ||
void SubTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(6).isNotEqualTo(calc.sub("//;\n8,6;1")); | ||
} | ||
|
||
@Test | ||
void MulTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(6).isEqualTo(calc.mul("2;3;1")); | ||
} | ||
|
||
@Test | ||
void MulTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(6).isNotEqualTo(calc.mul("//;\n8;6;1")); | ||
} | ||
|
||
@Test | ||
void DivTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(1).isEqualTo(calc.div("10;2;5")); | ||
} | ||
|
||
@Test | ||
void DivTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertThat(6).isNotEqualTo(calc.div("//;\n10;2;5")); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class String_calTest { | ||
|
||
@Nested | ||
@DisplayName("문자열 계산기 사칙연산 테스트") | ||
class CalTest { | ||
|
||
@Test | ||
void AddTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(6, calc.add("1,2;3")); | ||
} | ||
@Test | ||
void AddTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(6, calc.add("//;\n1;2;3")); | ||
} | ||
|
||
@Test | ||
void SubTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(1, calc.sub("8,6;1")); | ||
} | ||
|
||
@Test | ||
void SubTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(1, calc.sub("//;\n8,6;1")); | ||
} | ||
|
||
@Test | ||
void MulTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(6, calc.mul("1,2;3")); | ||
} | ||
|
||
@Test | ||
void MulTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(6, calc.mul("//;\n1,2;3")); | ||
} | ||
|
||
@Test | ||
void DivTest() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(2, calc.div("12,2;3")); | ||
} | ||
|
||
@Test | ||
void DivTest2() { | ||
String_Calculator calc = new String_Calculator(); | ||
assertEquals(2, calc.div("//;\n12,2;3")); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### IntelliJ IDEA ### | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
지금은 해당 파일이 두 개나 존재하고 있어요 ! 깃 공부도 병행하면 좋습니다 👍 |
||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1단계 - 초간단 계산기 구현
이 빠진 거 같아요 !확인 부탁드릴께요 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
관련해서
2단계 - 초간단 문자열 테스트
도 진행해주세요 ~There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커밋을 확인해보니, 구현하시고 다른 미션 적용을 위해 지운 거 같아요 !
1단계 - 초간단 계산기 구현
과3단계 - 문자열 계산기 구현
은 별도의 기능이기 때문에 남겨주시면 좋을 거 같아요 ~