Skip to content

Commit 5e2b9b3

Browse files
committed
Feat : 삼각형 기능 구현 및 테스트 진행
1 parent c727b99 commit 5e2b9b3

File tree

4 files changed

+78
-6
lines changed

4 files changed

+78
-6
lines changed

src/main/java/coordinate/domain/CoordinatesCalculator.java

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public CoordinatesCalculator(String expression) {
1212
return;
1313
}
1414

15+
if (expression.split(REGEX).length == 3) {
16+
shapes = new Triangle(expression);
17+
return;
18+
}
19+
1520
if (expression.split(REGEX).length == 4) {
1621
shapes = new Rectangle(expression);
1722
return;

src/main/java/coordinate/domain/Rectangle.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.List;
6-
import java.util.stream.Collectors;
76

87
import static java.lang.Math.abs;
98

src/test/java/coordinate/domain/CoordinatesCalculatorTest.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import org.junit.jupiter.api.Assertions;
44
import org.junit.jupiter.api.DisplayName;
5-
import org.junit.jupiter.api.Test;
65
import org.junit.jupiter.params.ParameterizedTest;
76
import org.junit.jupiter.params.provider.ValueSource;
87

98
import static org.assertj.core.api.Assertions.assertThat;
9+
import static org.assertj.core.api.Assertions.offset;
1010

1111
class CoordinatesCalculatorTest {
1212

1313
@ParameterizedTest
14-
@ValueSource(strings = {"(10,10)-(14,15)", "(10,10)-(22,10)-(22,18)-(10,18)"})
14+
@ValueSource(strings = {"(10,10)-(14,15)", "(10,10)-(22,10)-(22,18)-(10,18)", "(10,10)-(14,15)-(20,8)"})
1515
@DisplayName("입력을 받습니다.")
1616
void test1(String ) {
1717
Assertions.assertDoesNotThrow(
@@ -20,7 +20,7 @@ void test1(String 식) {
2020
}
2121

2222
@ParameterizedTest
23-
@ValueSource(strings = {"(10,10)-(14,15)", "(10,10)-(22,10)-(22,18)-(10,18)"})
23+
@ValueSource(strings = {"(10,10)-(14,15)", "(10,10)-(22,10)-(22,18)-(10,18)", "(10,10)-(14,15)-(20,8)"})
2424
@DisplayName("입력이 선 인지 직사각형인지 판단합니다.")
2525
void test2(String ) {
2626
CoordinatesCalculator calculator = new CoordinatesCalculator();
@@ -32,10 +32,14 @@ void test2(String 식) {
3232
if (.equals("(10,10)-(22,10)-(22,18)-(10,18)")) {
3333
assertThat(calculator.getShapes()).isInstanceOf(Rectangle.class);
3434
}
35+
36+
if (.equals("(10,10)-(14,15)-(20,8)")) {
37+
assertThat(calculator.getShapes()).isInstanceOf(Triangle.class);
38+
}
3539
}
3640

3741
@ParameterizedTest
38-
@ValueSource(strings = {"(10,10)-(10,15)", "(10,10)-(22,10)-(22,18)-(10,18)"})
42+
@ValueSource(strings = {"(10,10)-(10,15)", "(10,10)-(22,10)-(22,18)-(10,18)", "(10,10)-(14,15)-(20,8)"})
3943
@DisplayName("답을 출력합니다.")
4044
void test3(String ) {
4145
CoordinatesCalculator calculator = new CoordinatesCalculator();
@@ -47,10 +51,14 @@ void test3(String 식) {
4751
if (.equals("(10,10)-(22,10)-(22,18)-(10,18)")) {
4852
assertThat(calculator.getResult()).isEqualTo(96.0);
4953
}
54+
55+
if (.equals("(10,10)-(14,15)-(20,8)")) {
56+
assertThat(calculator.getResult()).isEqualTo(29.0, offset(0.0009));
57+
}
5058
}
5159

5260
@ParameterizedTest
53-
@ValueSource(strings = {"(10,10)-(10,15)", "(10,10)-(22,10)-(22,18)-(10,18)"})
61+
@ValueSource(strings = {"(10,10)-(10,15)", "(10,10)-(22,10)-(22,18)-(10,18)", "(10,10)-(14,15)-(20,8)"})
5462
@DisplayName("좌표를 출력합니다.")
5563
void test4(String ) {
5664
CoordinatesCalculator calculator = new CoordinatesCalculator();
@@ -62,5 +70,9 @@ void test4(String 식) {
6270
if (.equals("(10,10)-(22,10)-(22,18)-(10,18)")) {
6371
assertThat(calculator.findCoordinates()).hasSize(4);
6472
}
73+
74+
if (.equals("(10,10)-(14,15)-(20,8)")) {
75+
assertThat(calculator.findCoordinates()).hasSize(3);
76+
}
6577
}
6678
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package coordinate.domain;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.ValueSource;
7+
8+
import static org.assertj.core.api.Assertions.*;
9+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
10+
11+
class TriangleTest {
12+
13+
@Test
14+
@DisplayName("삼각형을 그릴 수 있습니다.")
15+
void test() {
16+
String = "(10,10)-(14,15)-(20,8)";
17+
assertDoesNotThrow(
18+
() -> new Triangle()
19+
);
20+
}
21+
22+
@Test
23+
@DisplayName("식이 틀리면 예외가 발생합니다.")
24+
void test1() {
25+
String = "(10,10)(14,15)-(20,8)";
26+
assertThatThrownBy(
27+
() -> new Triangle()
28+
).isInstanceOf(IllegalArgumentException.class);
29+
}
30+
31+
32+
@ParameterizedTest
33+
@ValueSource(strings = {"(14,15)-(20,8)", "(14,15)-(20,8)-(20,15)-(14,8)"})
34+
@DisplayName("좌표가 세개 이외의 값이 들어오면 예외가 발생합니다.")
35+
void test2(String ) {
36+
assertThatThrownBy(
37+
() -> new Triangle()
38+
).isInstanceOf(IllegalArgumentException.class);
39+
}
40+
41+
@Test
42+
@DisplayName("답인 삼각형의 넓이를 출력합니다.")
43+
void test3() {
44+
String = "(10,10)-(14,15)-(20,8)";
45+
Triangle 삼각형 = new Triangle();
46+
assertThat(삼각형.getResult()).isEqualTo(29.0, offset(0.00099));
47+
}
48+
49+
@Test
50+
@DisplayName("좌표를 그리기 위해 좌표들을 출력합니다.")
51+
void test4() {
52+
String = "(10,10)-(14,15)-(20,8)";
53+
Triangle 삼각형 = new Triangle();
54+
assertThat(삼각형.findCoordinates()).hasSize(3);
55+
}
56+
}

0 commit comments

Comments
 (0)