From 4fc2e0047450598ec00ac8d20173a895a1925814 Mon Sep 17 00:00:00 2001 From: Heesoo Date: Sat, 1 Mar 2025 17:46:25 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=A2=8C=ED=91=9C=EA=B3=84=EC=82=B0?= =?UTF-8?q?=EA=B8=B0=20=EB=8B=A4=EC=8B=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-HS.md | 79 ++++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/Main.java | 12 +++ .../java/exception/CoordinateException.java | 8 ++ src/main/java/exception/ErrorMessages.java | 8 ++ src/main/java/io/InputView.java | 36 ++++++++ src/main/java/model/Figure.java | 46 +++++++++++ src/main/java/model/FigureFactory.java | 32 ++++++++ src/main/java/model/Line.java | 27 ++++++ src/main/java/model/Point.java | 59 +++++++++++++ src/main/java/model/Points.java | 31 +++++++ src/main/java/model/Rectangle.java | 45 ++++++++++ src/main/java/model/Triangle.java | 32 ++++++++ src/main/java/utils/CoordinateUtils.java | 29 +++++++ src/test/java/model/FigureFactoryTest.java | 54 ++++++++++++ src/test/java/model/LineTest.java | 53 ++++++++++++ src/test/java/model/PointTest.java | 81 ++++++++++++++++++ src/test/java/model/PointsTest.java | 66 +++++++++++++++ src/test/java/model/RectangleTest.java | 69 ++++++++++++++++ src/test/java/model/TriangleTest.java | 51 ++++++++++++ src/test/java/utils/CoordinateUtilsTest.java | 82 +++++++++++++++++++ 21 files changed, 901 insertions(+), 1 deletion(-) create mode 100644 README-HS.md create mode 100644 src/main/java/Main.java create mode 100644 src/main/java/exception/CoordinateException.java create mode 100644 src/main/java/exception/ErrorMessages.java create mode 100644 src/main/java/io/InputView.java create mode 100644 src/main/java/model/Figure.java create mode 100644 src/main/java/model/FigureFactory.java create mode 100644 src/main/java/model/Line.java create mode 100644 src/main/java/model/Point.java create mode 100644 src/main/java/model/Points.java create mode 100644 src/main/java/model/Rectangle.java create mode 100644 src/main/java/model/Triangle.java create mode 100644 src/main/java/utils/CoordinateUtils.java create mode 100644 src/test/java/model/FigureFactoryTest.java create mode 100644 src/test/java/model/LineTest.java create mode 100644 src/test/java/model/PointTest.java create mode 100644 src/test/java/model/PointsTest.java create mode 100644 src/test/java/model/RectangleTest.java create mode 100644 src/test/java/model/TriangleTest.java create mode 100644 src/test/java/utils/CoordinateUtilsTest.java diff --git a/README-HS.md b/README-HS.md new file mode 100644 index 0000000..a6ca8a7 --- /dev/null +++ b/README-HS.md @@ -0,0 +1,79 @@ +## 요구사항 +1. 좌표값을 두 개 입력한 경우 두 점을 잇는 직선으로 가정 +2. 좌표와 좌표값 사이 '-' 문자로 구분 +3. 좌표값을 네 개 입력한 경우 네 점을 연결하는 사각형으로 가정 + - 네 점이 뒤틀어진 사다리꼴이나 마름모는 제외하고 직사각형만 허용하도록 검사 + - 사각형인 경우 사각형 넓이를 계산해서 출력 +4. 좌표값을 세 개 입력한 경우, 세 점을 연결하는 삼각형으로 가정한다. +5. 삼각형인 경우 삼각형의 넓이를 계산해서 출력한다. + + +## 프로그래밍 요구사항 +1. depth 2를 넘지 않도록 구현 (1까지만 허용) +2. 3항 연산자 금지 +3. else 예약어 금지 +4. switch/case 금지 +5. 메소드 10줄 넘어가지 않도록 구현 +6. 일급 컬렉션 + + +## 실행 결과 +``` +좌표를 입력하세요. +(10,10)-(14,15)-(20,8) + + +24| + | +22| + | +20| + | +18| + | +16| + | ● +14| + | +12| + | +10| ● + | + 8| ● + | + 6| + | + 4| + | + 2| + | + +―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― + 0 2 4 6 8 10 12 14 16 18 20 22 24 + +삼각형의 넓이는 29.0 +``` + +## 힌트 +1. 사각형 면적은 width * height 방식으로 계산할 수 있다. +2. Point 라는 객체를 추가해 x, y 좌표를 관리하도록 한다. + +- 직사각형 좌표 + (10,10)-(22,10)-(22,18)-(10,18) + (2,3)-(2,10)-(7,3)-(7,10) + (4,6)-(4,15)-(12,6)-(12,15) + +- 직사각형이 아닌 좌표 + (3,5)-(7,14)-(15,18)-(21,3) + (2,8)-(9,17)-(18,6)-(23,11) + +- 마름모 + (12,6)-(18,18)-(6,18)-(0,6) + (6,12)-(12,18)-(18,12)-(12,6) + +- 선 + (10,10)-(14,15) + 두 점 사이 거리는 6.403124 + +(10,10)-(14,15) +(10,10)-(22,10)-(22,18) +(10,10)-(22,10)-(22,18)-(10,18) \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..d2880ba 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..875abd3 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,12 @@ +import io.InputView; +import model.Figure; + +public class Main { + public static void main(String[] args) { + InputView inputView = new InputView(); + Figure figure = inputView.input(); + + double result = figure.calculateResult(); + System.out.println(figure.print(result)); + } +} diff --git a/src/main/java/exception/CoordinateException.java b/src/main/java/exception/CoordinateException.java new file mode 100644 index 0000000..d8ed140 --- /dev/null +++ b/src/main/java/exception/CoordinateException.java @@ -0,0 +1,8 @@ +package exception; + +public class CoordinateException extends RuntimeException{ + public CoordinateException(String errorMessage){ + super(errorMessage); + } + +} diff --git a/src/main/java/exception/ErrorMessages.java b/src/main/java/exception/ErrorMessages.java new file mode 100644 index 0000000..a735a14 --- /dev/null +++ b/src/main/java/exception/ErrorMessages.java @@ -0,0 +1,8 @@ +package exception; + +public class ErrorMessages { + public static String INVALID_INPUT_NUMBER = "숫자가 아닌 값은 입력할 수 없습니다."; + public static String OVER_NUMBER = "숫자 범위를 초과하였습니다."; + public static String NOT_RECTANGLE = "직사각형이 아닙니다."; + public static String INVALID_COORDINATE = "유효하지 않은 도형입니다."; +} diff --git a/src/main/java/io/InputView.java b/src/main/java/io/InputView.java new file mode 100644 index 0000000..f6ad6ab --- /dev/null +++ b/src/main/java/io/InputView.java @@ -0,0 +1,36 @@ +package io; + +import exception.CoordinateException; +import model.Figure; +import model.FigureFactory; +import utils.CoordinateUtils; + +import java.util.List; +import java.util.Scanner; + +public class InputView { + + private final Scanner scanner; + + public InputView() { + this.scanner = new Scanner(System.in); + } + + public Figure input(){ + System.out.println("좌표를 입력하세요"); + return getFigure(); + } + + private Figure getFigure() { + try{ + String input = scanner.nextLine(); + List numbers = CoordinateUtils.splitNumbers(input); + return new FigureFactory().create(numbers); + } catch (CoordinateException ex){ + System.out.println(ex.getMessage()); + return input(); + } + } + + +} diff --git a/src/main/java/model/Figure.java b/src/main/java/model/Figure.java new file mode 100644 index 0000000..d169926 --- /dev/null +++ b/src/main/java/model/Figure.java @@ -0,0 +1,46 @@ +package model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public abstract class Figure { + private static final int SQUARE_EXPONENT = 2; + private static final double ROUNDING_FACTOR = 100.0; + + protected Points points; + protected List linesLength; + + public Figure(Points points){ + this.points = points; + this.linesLength = calculateAllDistance(); + } + + public abstract double calculateResult(); + public abstract String print(double result); + + public List calculateAllDistance(){ + List distances = new ArrayList<>(); + + for(int i=0; i> creator; + + static { + creator = new HashMap<>(); + creator.put(Line.LINE_POINT_SIZE, Line::from); + creator.put(Triangle.TRIANGLE_POINT_SIZE, Triangle::from); + creator.put(Rectangle.RECTANGLE_POINT_SIZE, Rectangle::from); + } + + public Figure create(List numbers) { + Points points = Points.from(numbers); + Function figure = creator.get(points.size()); + + if(figure == null){ + throw new CoordinateException(ErrorMessages.INVALID_COORDINATE); + } + + return figure.apply(points); + } +} diff --git a/src/main/java/model/Line.java b/src/main/java/model/Line.java new file mode 100644 index 0000000..cbb6988 --- /dev/null +++ b/src/main/java/model/Line.java @@ -0,0 +1,27 @@ +package model; + +public class Line extends Figure { + public static final int LINE_POINT_SIZE = 2; + + public Line(Points points){ + super(points); + } + + public static Line from(Points points) { + return new Line(points); + } + + @Override + public double calculateResult() { + double distance = linesLength.get(0); + return roundToSecondDecimal(distance); + } + + @Override + public String print(double result) { + return "두 점 사이 거리는 " + result; + } + + + +} diff --git a/src/main/java/model/Point.java b/src/main/java/model/Point.java new file mode 100644 index 0000000..b10a4a7 --- /dev/null +++ b/src/main/java/model/Point.java @@ -0,0 +1,59 @@ +package model; + +import exception.CoordinateException; +import exception.ErrorMessages; + +import java.util.Objects; + +public class Point { + private static final int MAX_COORDINATE = 24; + private static final int MIN_COORDINATE = 0; + private int x; + private int y; + + public Point(){} + + public Point(int x, int y){ + validateRange(x, y); + this.x = x; + this.y = y; + } + + public static Point of(int x, int y){ + return new Point(x, y); + } + + public void validateRange(int x, int y) { + if (!isCorrectRange(x) || !isCorrectRange(y)){ + throw new CoordinateException(ErrorMessages.OVER_NUMBER); + } + } + + public boolean isCorrectRange(int value) { + return value <= MAX_COORDINATE && value >= MIN_COORDINATE; + } + + public int minusX(Point other){ + return this.x - other.x; + } + + public int minusY(Point other){ + return this.y - other.y; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Point point = (Point) o; + return x == point.x && y == point.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + + +} diff --git a/src/main/java/model/Points.java b/src/main/java/model/Points.java new file mode 100644 index 0000000..a06d9c8 --- /dev/null +++ b/src/main/java/model/Points.java @@ -0,0 +1,31 @@ +package model; + +import java.util.ArrayList; +import java.util.List; + +public class Points { + private List points; + + public Points(List points){ + this.points = points; + } + + public static Points from(List numbers){ + List points = new ArrayList<>(); + + for(int i=0; i splitNumbers(String value) { + return Pattern.compile("\\d+") + .matcher(value) + .results() + .map(MatchResult::group) + .map(CoordinateUtils::convertStringToInteger) + .toList(); + } + + public static int convertStringToInteger(String value) { + try{ + return Integer.parseInt(value); + } catch (Exception e){ + throw new CoordinateException(ErrorMessages.INVALID_INPUT_NUMBER); + } + } +} diff --git a/src/test/java/model/FigureFactoryTest.java b/src/test/java/model/FigureFactoryTest.java new file mode 100644 index 0000000..a8db417 --- /dev/null +++ b/src/test/java/model/FigureFactoryTest.java @@ -0,0 +1,54 @@ +package model; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FigureFactoryTest { + + + @Test + @DisplayName("선 객체 생성") + void line(){ + // given + List numbers = List.of(10, 10, 14, 15); + + // when + Figure figure = new FigureFactory().create(numbers); + + // then + assertThat(figure).isInstanceOf(Line.class); + assertThat(figure.points.size()).isEqualTo(2); + } + + @Test + @DisplayName("삼각형 객체 생성") + void triangle(){ + // given + List numbers = List.of(10, 10, 22, 10, 22, 18); + + // when + Figure figure = new FigureFactory().create(numbers); + + // then + assertThat(figure).isInstanceOf(Triangle.class); + assertThat(figure.points.size()).isEqualTo(3); + } + + @Test + @DisplayName("사각형 객체 생성") + void rectangle(){ + // given + List numbers = List.of(10, 10, 22, 10, 22, 18, 10, 18); + + // when + Figure figure = new FigureFactory().create(numbers); + + // then + assertThat(figure).isInstanceOf(Rectangle.class); + assertThat(figure.points.size()).isEqualTo(4); + } +} diff --git a/src/test/java/model/LineTest.java b/src/test/java/model/LineTest.java new file mode 100644 index 0000000..ed77496 --- /dev/null +++ b/src/test/java/model/LineTest.java @@ -0,0 +1,53 @@ +package model; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class LineTest { + + @Test + @DisplayName("직선 객체 생성") + void from(){ + // given + Points points = Points.from(List.of(10, 0, 24, 15)); + + // when + // then + assertDoesNotThrow(() -> Line.from(points)); + } + + @Test + @DisplayName("두 점 사이 거리 계산") + void calculateResult(){ + // given + Points points = Points.from(List.of(10, 10, 14, 15)); + Figure line = Line.from(points); + + // when + double response = line.calculateResult(); + + // then + assertThat(response).isEqualTo(6.40); + } + + @Test + @DisplayName("두 점 사이 거리 출력") + void print(){ + // given + Points points = Points.from(List.of(10, 10, 14, 15)); + Figure line = Line.from(points); + + // when + String response = line.print(6.4); + + // then + assertThat(response).isEqualTo("두 점 사이 거리는 6.4"); + } + + +} diff --git a/src/test/java/model/PointTest.java b/src/test/java/model/PointTest.java new file mode 100644 index 0000000..3224b99 --- /dev/null +++ b/src/test/java/model/PointTest.java @@ -0,0 +1,81 @@ +package model; + +import exception.CoordinateException; +import exception.ErrorMessages; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.assertj.core.api.Assertions.*; + +public class PointTest { + + @Test + @DisplayName("point 객체 생성") + void of(){ + // given + // when + Point response = Point.of(3, 5); + + // then + assertThat(response).isEqualTo(new Point(3, 5)); + } + + @ParameterizedTest + @CsvSource({"0, 14", "24, 3"}) + @DisplayName("x, y 범위 검증 통과") + void validateRangeNumber(int x, int y){ + // given + Point point = new Point(); + + // when + // then + assertThatCode(() -> point.validateRange(x, y)) + .doesNotThrowAnyException(); + } + + @ParameterizedTest + @CsvSource({"-1, 14", "25, 3"}) + @DisplayName("x, y 범위 검증 통과 실패") + void validateRangeNumber_exception(int x, int y){ + // given + Point point = new Point(); + + // when + // then + assertThatThrownBy(() -> point.validateRange(x, y)) + .isInstanceOf(CoordinateException.class) + .hasMessage(ErrorMessages.OVER_NUMBER); + } + + @ParameterizedTest + @CsvSource(value = {"10", "14", "24", "0"}) + @DisplayName("숫자 범위 검증 true 반환") + void isCorrectRange_true(int request){ + // given + Point point = new Point(); + + // when + boolean response = point.isCorrectRange(request); + + // then + assertThat(response).isTrue(); + } + + @ParameterizedTest + @CsvSource(value = {"-1", "25", "300", "-1000"}) + @DisplayName("숫자 범위 검증 false 반환") + void isCorrectRange_false(int request){ + // given + Point point = new Point(); + + // when + boolean response = point.isCorrectRange(request); + + // then + assertThat(response).isFalse(); + } + + +} diff --git a/src/test/java/model/PointsTest.java b/src/test/java/model/PointsTest.java new file mode 100644 index 0000000..195ea07 --- /dev/null +++ b/src/test/java/model/PointsTest.java @@ -0,0 +1,66 @@ +package model; + +import exception.CoordinateException; +import exception.ErrorMessages; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class PointsTest { + + @Test + @DisplayName("points 객체 생성1") + void fromTwo(){ + // given + List numbers = List.of(10, 0, 24, 15); + + // when + Points points = Points.from(numbers); + + // then + assertThat(points.size()).isEqualTo(2); + } + + @Test + @DisplayName("points 객체 생성2") + void fromThree(){ + // given + List numbers = List.of(10, 10, 14, 0, 24, 15); + + // when + Points points = Points.from(numbers); + + // then + assertThat(points.size()).isEqualTo(3); + } + + @Test + @DisplayName("points 객체 생성3") + void fromFour(){ + // given + List numbers = List.of(10, 10, 14, 0, 24, 15, 22, 18); + + // when + Points points = Points.from(numbers); + + // then + assertThat(points.size()).isEqualTo(4); + } + + @Test + @DisplayName("points 객체 생성 시 제한 범위를 초과해 예외 발생") + void fromException(){ + // given + List numbers = List.of(10, 10, 14, 0, 25, 15, 22, 18); + + // when + CoordinateException fail = assertThrows(CoordinateException.class, () -> Points.from(numbers)); + + // then + assertThat(fail.getMessage()).isEqualTo(ErrorMessages.OVER_NUMBER); + } +} diff --git a/src/test/java/model/RectangleTest.java b/src/test/java/model/RectangleTest.java new file mode 100644 index 0000000..be405d7 --- /dev/null +++ b/src/test/java/model/RectangleTest.java @@ -0,0 +1,69 @@ +package model; + +import exception.CoordinateException; +import exception.ErrorMessages; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestReporter; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class RectangleTest { + + @Test + @DisplayName("직사각형 생성") + void from(){ + // given + Points points = Points.from(List.of(10, 10, 22, 10, 22, 18, 10, 18)); + + // when + // then + assertDoesNotThrow(() -> Rectangle.from(points)); + } + + @Test + @DisplayName("직사각형이 아니여서 예외 발생") + void from_notRectangle(){ + // given + Points points = Points.from(List.of(3, 5, 7, 14, 22, 18, 10, 18)); + + // when + CoordinateException fail = assertThrows(CoordinateException.class, () -> Rectangle.from(points)); + + // then + assertThat(fail.getMessage()).isEqualTo(ErrorMessages.NOT_RECTANGLE); + } + + @Test + @DisplayName("사각형 넓이 계산") + void calculateResult(){ + // given + Points points = Points.from(List.of(10, 10, 22, 10, 22, 18, 10, 18)); + Figure rectangle = Rectangle.from(points); + + // when + double response = rectangle.calculateResult(); + + // then + assertThat(response).isEqualTo(96.0); + } + + @Test + @DisplayName("사각형 넓이 출력") + void print(){ + // given + Points points = Points.from(List.of(10, 10, 22, 10, 22, 18, 10, 18)); + Figure rectangle = Rectangle.from(points); + + // when + String response = rectangle.print(96.0); + + // then + assertThat(response).isEqualTo("사각형의 넓이는 96.0"); + } + +} diff --git a/src/test/java/model/TriangleTest.java b/src/test/java/model/TriangleTest.java new file mode 100644 index 0000000..36be354 --- /dev/null +++ b/src/test/java/model/TriangleTest.java @@ -0,0 +1,51 @@ +package model; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class TriangleTest { + + @Test + @DisplayName("삼각형 생성") + void from(){ + // given + Points points = Points.from(List.of(10, 0, 24, 15)); + + // when + // then + assertDoesNotThrow(() -> Triangle.from(points)); + } + + @Test + @DisplayName("삼각형 넓이 계산") + void calculateResult(){ + // given + Points points = Points.from(List.of(10, 10, 14, 15, 20, 8)); + Figure triangle = Triangle.from(points); + + // when + double response = triangle.calculateResult(); + + // then + assertThat(response).isEqualTo(29.0); + } + + @Test + @DisplayName("삼각형 넓이 출력") + void print(){ + // given + Points points = Points.from(List.of(10, 10, 14, 15, 20, 8)); + Figure triangle = Triangle.from(points); + + // when + String response = triangle.print(29.0); + + // then + assertThat(response).isEqualTo("삼각형의 넓이는 29.0"); + } +} diff --git a/src/test/java/utils/CoordinateUtilsTest.java b/src/test/java/utils/CoordinateUtilsTest.java new file mode 100644 index 0000000..f96ad42 --- /dev/null +++ b/src/test/java/utils/CoordinateUtilsTest.java @@ -0,0 +1,82 @@ +package utils; + +import exception.CoordinateException; +import exception.ErrorMessages; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class CoordinateUtilsTest { + + @Test + @DisplayName("문자열 숫자 분리") + void splitNumbers1(){ + // given + String request = "(10,10)-(14,15)"; + + // when + List response = CoordinateUtils.splitNumbers(request); + + // then + assertThat(response.size()).isEqualTo(4); + assertThat(response.get(0)).isEqualTo(10); + assertThat(response.get(2)).isEqualTo(14); + } + + @Test + @DisplayName("문자열 숫자 분리") + void splitNumbers2(){ + // given + String request = "(10,10)-(22,10)-(22,18)"; + + // when + List response = CoordinateUtils.splitNumbers(request); + + // then + assertThat(response.size()).isEqualTo(6); + assertThat(response.get(0)).isEqualTo(10); + assertThat(response.get(2)).isEqualTo(22); + } + + @Test + @DisplayName("문자열 숫자 분리") + void splitNumbers3(){ + // given + String request = "(10,10)-(22,10)-(22,18)-(10,18)"; + + // when + List response = CoordinateUtils.splitNumbers(request); + + // then + assertThat(response.size()).isEqualTo(8); + assertThat(response.get(0)).isEqualTo(10); + assertThat(response.get(2)).isEqualTo(22); + } + + @Test + @DisplayName("문자열 숫자를 정수로 변경") + void convertStringToInteger(){ + // given + // when + int response = CoordinateUtils.convertStringToInteger("3"); + + // then + assertThat(response).isEqualTo(3); + } + + @Test + @DisplayName("문자열 숫자를 정수로 변경 시 예외 발생") + void convertStringToInteger_exception(){ + // given + // when + // then + assertThatThrownBy(() -> CoordinateUtils.convertStringToInteger("3^")) + .isInstanceOf(CoordinateException.class) + .hasMessage(ErrorMessages.INVALID_INPUT_NUMBER); + + } +}