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

신재한 1주차 과제 1차 수정본 #45

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/Calculator/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
Expand All @@ -10,7 +10,7 @@ build/
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/Calculator/**/out/
!**/src/test/**/out/

### Eclipse ###
Expand All @@ -22,7 +22,7 @@ out/
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/Calculator/**/bin/
!**/src/test/**/bin/

### NetBeans ###
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ repositories {
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation( 'org.assertj:assertj-core:3.20.2')
}

test {
useJUnitPlatform()
}

Binary file added lib/assertj-core-3.27.3-sources.jar
Binary file not shown.
Binary file added lib/assertj-core-3.27.3.jar
Binary file not shown.
Binary file added lib/byte-buddy-1.15.11-sources.jar
Binary file not shown.
Binary file added lib/byte-buddy-1.15.11.jar
Binary file not shown.
17 changes: 17 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Calculator {

Choose a reason for hiding this comment

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

1단계 - 초간단 계산기 구현이 빠진 거 같아요 !
확인 부탁드릴께요 ~

Choose a reason for hiding this comment

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

관련해서 2단계 - 초간단 문자열 테스트도 진행해주세요 ~

Choose a reason for hiding this comment

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

커밋을 확인해보니, 구현하시고 다른 미션 적용을 위해 지운 거 같아요 !

1단계 - 초간단 계산기 구현3단계 - 문자열 계산기 구현은 별도의 기능이기 때문에 남겨주시면 좋을 거 같아요 ~

public int add(int a, int b) {

Choose a reason for hiding this comment

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

a, b 보다 더 의미 있는 변수 명에 대해서 생각해보면 좋을 거 같아요.

간단한 부분이지만, 습관을 가지는 것이 좋다고 생각합니다 !

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) {

Choose a reason for hiding this comment

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

0으로 나누면 어떻게 될까요 ?

return a / b;
}
}
68 changes: 68 additions & 0 deletions src/main/java/String_Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.util.Arrays;

public class String_Calculator {

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

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

Arrays.copyOfRange를 사용하신 이유가 있을까요 ??
해당 메소드를 사용했을 때, 어떤 복사가 일어나는 지 확인하고 사용하면 좋을 거같아요.

간단한 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()];

Choose a reason for hiding this comment

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

초기 값 설정을 위해서 다음과 같이 선언하셨다면, 아래 내용에 대해서 조사해보면 좋을 거 같아요.

  1. String은 자료형인가? 클래스인가?
  2. 자바의 자료형에는 어떤 게 있을까?
  3. 자료형과 클래스는 무슨 차이가 있을까?


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

Choose a reason for hiding this comment

The 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;
}
}
38 changes: 38 additions & 0 deletions src/test/java/Cal_Test.java
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));
}

}
}
61 changes: 61 additions & 0 deletions src/test/java/StringCal_AssertJTest.java
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 {

Choose a reason for hiding this comment

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

약어에 대해서 한 번 생각해보면 좋을 거 같아요.
다른 사람이 봤을 때, StringCal가 무슨 뜻일까 라는 생각이 들 수 있을 거 같아요. 내가 보기 편한 코드보다는, 누가 봐도 읽기 좋은 코드를 작성해보려고 노력하는 모습도 좋답니다 !

@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"));
}

}
}
61 changes: 61 additions & 0 deletions src/test/java/String_calTest.java
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"));
}

}
}
29 changes: 29 additions & 0 deletions untitled/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###

Choose a reason for hiding this comment

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

.gitinore에 대해서 한 번 조사하고, 이를 잘 적용해보면 좋을 거 같아요.

지금은 해당 파일이 두 개나 존재하고 있어요 ! 깃 공부도 병행하면 좋습니다 👍

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