22
33import org .junit .jupiter .api .Assertions ;
44import org .junit .jupiter .api .DisplayName ;
5- import org .junit .jupiter .api .Test ;
65import org .junit .jupiter .params .ParameterizedTest ;
76import org .junit .jupiter .params .provider .ValueSource ;
87
98import static org .assertj .core .api .Assertions .assertThat ;
9+ import static org .assertj .core .api .Assertions .offset ;
1010
1111class 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}
0 commit comments