2
2
3
3
import org .junit .jupiter .api .Assertions ;
4
4
import org .junit .jupiter .api .DisplayName ;
5
- import org .junit .jupiter .api .Test ;
6
5
import org .junit .jupiter .params .ParameterizedTest ;
7
6
import org .junit .jupiter .params .provider .ValueSource ;
8
7
9
8
import static org .assertj .core .api .Assertions .assertThat ;
9
+ import static org .assertj .core .api .Assertions .offset ;
10
10
11
11
class CoordinatesCalculatorTest {
12
12
13
13
@ 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)" })
15
15
@ DisplayName ("입력을 받습니다." )
16
16
void test1 (String 식 ) {
17
17
Assertions .assertDoesNotThrow (
@@ -20,7 +20,7 @@ void test1(String 식) {
20
20
}
21
21
22
22
@ 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)" })
24
24
@ DisplayName ("입력이 선 인지 직사각형인지 판단합니다." )
25
25
void test2 (String 식 ) {
26
26
CoordinatesCalculator calculator = new CoordinatesCalculator (식 );
@@ -32,10 +32,14 @@ void test2(String 식) {
32
32
if (식 .equals ("(10,10)-(22,10)-(22,18)-(10,18)" )) {
33
33
assertThat (calculator .getShapes ()).isInstanceOf (Rectangle .class );
34
34
}
35
+
36
+ if (식 .equals ("(10,10)-(14,15)-(20,8)" )) {
37
+ assertThat (calculator .getShapes ()).isInstanceOf (Triangle .class );
38
+ }
35
39
}
36
40
37
41
@ 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)" })
39
43
@ DisplayName ("답을 출력합니다." )
40
44
void test3 (String 식 ) {
41
45
CoordinatesCalculator calculator = new CoordinatesCalculator (식 );
@@ -47,10 +51,14 @@ void test3(String 식) {
47
51
if (식 .equals ("(10,10)-(22,10)-(22,18)-(10,18)" )) {
48
52
assertThat (calculator .getResult ()).isEqualTo (96.0 );
49
53
}
54
+
55
+ if (식 .equals ("(10,10)-(14,15)-(20,8)" )) {
56
+ assertThat (calculator .getResult ()).isEqualTo (29.0 , offset (0.0009 ));
57
+ }
50
58
}
51
59
52
60
@ 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)" })
54
62
@ DisplayName ("좌표를 출력합니다." )
55
63
void test4 (String 식 ) {
56
64
CoordinatesCalculator calculator = new CoordinatesCalculator (식 );
@@ -62,5 +70,9 @@ void test4(String 식) {
62
70
if (식 .equals ("(10,10)-(22,10)-(22,18)-(10,18)" )) {
63
71
assertThat (calculator .findCoordinates ()).hasSize (4 );
64
72
}
73
+
74
+ if (식 .equals ("(10,10)-(14,15)-(20,8)" )) {
75
+ assertThat (calculator .findCoordinates ()).hasSize (3 );
76
+ }
65
77
}
66
78
}
0 commit comments