From 9f63f5b666696bb736af73741cc6318f05969b2c Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 17:01:11 +0900 Subject: [PATCH 01/10] =?UTF-8?q?docs:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c354962f..e6fa3e6b7 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ -# kotlin-minesweeper \ No newline at end of file +# kotlin-minesweeper + +- [ ] 지뢰 찾기에 필요한 정보(높이, 너비, 지뢰 개수)를 입력 받는다 +- [ ] 높이 * 너비 만큼의 좌표 정보를 생성한다 +- [ ] 지뢰 개수만큼 랜덤한 지뢰의 위치를 구해 해당 좌표에 지뢰를 설치한다 +- [ ] 지뢰 찾기 게임을 출력한다 \ No newline at end of file From a30cf298873b609f67f21fa109ec323d578ef807 Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 17:02:16 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=EC=A7=80=EB=A2=B0=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=EC=97=90=20=ED=95=84=EC=9A=94=ED=95=9C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/.gitkeep | 0 src/main/kotlin/minesweeper/Main.kt | 9 ++++ src/main/kotlin/minesweeper/view/InputView.kt | 41 +++++++++++++++++++ src/test/kotlin/.gitkeep | 0 5 files changed, 51 insertions(+), 1 deletion(-) delete mode 100644 src/main/kotlin/.gitkeep create mode 100644 src/main/kotlin/minesweeper/Main.kt create mode 100644 src/main/kotlin/minesweeper/view/InputView.kt delete mode 100644 src/test/kotlin/.gitkeep diff --git a/README.md b/README.md index e6fa3e6b7..bc6b12653 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # kotlin-minesweeper -- [ ] 지뢰 찾기에 필요한 정보(높이, 너비, 지뢰 개수)를 입력 받는다 +- [x] 지뢰 찾기에 필요한 정보(높이, 너비, 지뢰 개수)를 입력 받는다 - [ ] 높이 * 너비 만큼의 좌표 정보를 생성한다 - [ ] 지뢰 개수만큼 랜덤한 지뢰의 위치를 구해 해당 좌표에 지뢰를 설치한다 - [ ] 지뢰 찾기 게임을 출력한다 \ No newline at end of file diff --git a/src/main/kotlin/.gitkeep b/src/main/kotlin/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/kotlin/minesweeper/Main.kt b/src/main/kotlin/minesweeper/Main.kt new file mode 100644 index 000000000..c96717f7b --- /dev/null +++ b/src/main/kotlin/minesweeper/Main.kt @@ -0,0 +1,9 @@ +package minesweeper + +import minesweeper.view.InputView + +fun main() { + val height = InputView.receiveHeight() + val width = InputView.receiveWidth() + val mineCount = InputView.receiveMineCount() +} diff --git a/src/main/kotlin/minesweeper/view/InputView.kt b/src/main/kotlin/minesweeper/view/InputView.kt new file mode 100644 index 000000000..44098dec4 --- /dev/null +++ b/src/main/kotlin/minesweeper/view/InputView.kt @@ -0,0 +1,41 @@ +package minesweeper.view + +object InputView { + fun receiveHeight(): Int { + println("높이를 입력하세요.") + + return receiveInt() + } + + fun receiveWidth(): Int { + println("너비를 입력하세요.") + + return receiveInt() + } + + fun receiveMineCount(): Int { + println("지뢰는 몇 개인가요?") + + return receiveInt() + } + + private fun receiveString(): String { + var input: String? = null + + do { + input = readlnOrNull() + } while (input.isNullOrBlank()) + + return input + } + + private fun receiveInt(): Int { + var int: Int? = receiveString().toIntOrNull() + + while (int == null) { + int = receiveString().toIntOrNull() + } + + return int + } +} \ No newline at end of file diff --git a/src/test/kotlin/.gitkeep b/src/test/kotlin/.gitkeep deleted file mode 100644 index e69de29bb..000000000 From 88f25ef51b7f800b615494927bad6d0154e86dbb Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 17:38:11 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=A0=95=EB=B3=B4=EB=A1=9C=20=EC=A7=80=EB=8F=84=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/minesweeper/Main.kt | 12 +++++++++--- src/main/kotlin/minesweeper/domain/Height.kt | 11 +++++++++++ .../kotlin/minesweeper/domain/MineCount.kt | 11 +++++++++++ src/main/kotlin/minesweeper/domain/MineMap.kt | 19 +++++++++++++++++++ src/main/kotlin/minesweeper/domain/Point.kt | 8 ++++++++ src/main/kotlin/minesweeper/domain/Width.kt | 11 +++++++++++ src/test/kotlin/minesweeper/HeightTest.kt | 12 ++++++++++++ src/test/kotlin/minesweeper/MineCountTest.kt | 12 ++++++++++++ src/test/kotlin/minesweeper/MineMapTest.kt | 19 +++++++++++++++++++ src/test/kotlin/minesweeper/PointTest.kt | 13 +++++++++++++ src/test/kotlin/minesweeper/WidthTest.kt | 12 ++++++++++++ 12 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/minesweeper/domain/Height.kt create mode 100644 src/main/kotlin/minesweeper/domain/MineCount.kt create mode 100644 src/main/kotlin/minesweeper/domain/MineMap.kt create mode 100644 src/main/kotlin/minesweeper/domain/Point.kt create mode 100644 src/main/kotlin/minesweeper/domain/Width.kt create mode 100644 src/test/kotlin/minesweeper/HeightTest.kt create mode 100644 src/test/kotlin/minesweeper/MineCountTest.kt create mode 100644 src/test/kotlin/minesweeper/MineMapTest.kt create mode 100644 src/test/kotlin/minesweeper/PointTest.kt create mode 100644 src/test/kotlin/minesweeper/WidthTest.kt diff --git a/README.md b/README.md index bc6b12653..2697c0361 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # kotlin-minesweeper - [x] 지뢰 찾기에 필요한 정보(높이, 너비, 지뢰 개수)를 입력 받는다 -- [ ] 높이 * 너비 만큼의 좌표 정보를 생성한다 +- [x] 높이 * 너비 만큼의 좌표 정보를 생성한다 - [ ] 지뢰 개수만큼 랜덤한 지뢰의 위치를 구해 해당 좌표에 지뢰를 설치한다 - [ ] 지뢰 찾기 게임을 출력한다 \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/Main.kt b/src/main/kotlin/minesweeper/Main.kt index c96717f7b..0fa283848 100644 --- a/src/main/kotlin/minesweeper/Main.kt +++ b/src/main/kotlin/minesweeper/Main.kt @@ -1,9 +1,15 @@ package minesweeper +import minesweeper.domain.Height +import minesweeper.domain.MineCount +import minesweeper.domain.MineMap +import minesweeper.domain.Width import minesweeper.view.InputView fun main() { - val height = InputView.receiveHeight() - val width = InputView.receiveWidth() - val mineCount = InputView.receiveMineCount() + val height = Height(InputView.receiveHeight()) + val width = Width(InputView.receiveWidth()) + val mineCount = MineCount(InputView.receiveMineCount()) + + val mineMap = MineMap(height, width, mineCount) } diff --git a/src/main/kotlin/minesweeper/domain/Height.kt b/src/main/kotlin/minesweeper/domain/Height.kt new file mode 100644 index 000000000..ada4a5bcb --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/Height.kt @@ -0,0 +1,11 @@ +package minesweeper.domain + +class Height(val value: Int) { + init { + require(value >= MIN_HEIGHT_VALUE) { "height는 $MIN_HEIGHT_VALUE 이상만 허용됩니다." } + } + + companion object { + const val MIN_HEIGHT_VALUE = 1 + } +} \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/domain/MineCount.kt b/src/main/kotlin/minesweeper/domain/MineCount.kt new file mode 100644 index 000000000..0fed5c7be --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/MineCount.kt @@ -0,0 +1,11 @@ +package minesweeper.domain + +class MineCount(val value: Int) { + init { + require(value >= MIN_MINE_COUNT_VALUE) { "지뢰 개수는 $MIN_MINE_COUNT_VALUE 이상만 허용됩니다." } + } + + companion object { + private const val MIN_MINE_COUNT_VALUE = 0 + } +} \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt new file mode 100644 index 000000000..519d4f70d --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -0,0 +1,19 @@ +package minesweeper.domain + +class MineMap(height: Height, width: Width, mineCount: MineCount) { + private val size: Int = height.value * width.value + val map: List + + init { + require(size >= mineCount.value) { "지도 크기는 지뢰 개수이상이어야 합니다." } + + val mutableList = mutableListOf() + (1..height.value).forEach { y -> + (1..width.value).forEach { x -> + mutableList.add(Point(x, y)) + } + } + + map = mutableList.toList() + } +} \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/domain/Point.kt b/src/main/kotlin/minesweeper/domain/Point.kt new file mode 100644 index 000000000..e83976f38 --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/Point.kt @@ -0,0 +1,8 @@ +package minesweeper.domain + +class Point(x: Int, y: Int) { + init { + require(x >= Width.MIN_WIDTH_VALUE) { "x 좌표 값은 width의 최소 값 이상이어야합니다." } + require(y >= Height.MIN_HEIGHT_VALUE) { "y 좌표 값은 height의 최소 값 이상이어야합니다." } + } +} \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/domain/Width.kt b/src/main/kotlin/minesweeper/domain/Width.kt new file mode 100644 index 000000000..2a9d43a3b --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/Width.kt @@ -0,0 +1,11 @@ +package minesweeper.domain + +class Width(val value: Int) { + init { + require(value >= MIN_WIDTH_VALUE) { "width는 $MIN_WIDTH_VALUE 이상만 허용됩니다."} + } + + companion object { + const val MIN_WIDTH_VALUE = 1 + } +} \ No newline at end of file diff --git a/src/test/kotlin/minesweeper/HeightTest.kt b/src/test/kotlin/minesweeper/HeightTest.kt new file mode 100644 index 000000000..86f360539 --- /dev/null +++ b/src/test/kotlin/minesweeper/HeightTest.kt @@ -0,0 +1,12 @@ +package minesweeper + +import io.kotest.assertions.throwables.shouldThrow +import minesweeper.domain.Height +import org.junit.jupiter.api.Test + +class HeightTest { + @Test + fun `height는 음수 값으로 생성 시 예외가 발생한다`() { + shouldThrow { Height(0) } + } +} diff --git a/src/test/kotlin/minesweeper/MineCountTest.kt b/src/test/kotlin/minesweeper/MineCountTest.kt new file mode 100644 index 000000000..18e4f6b04 --- /dev/null +++ b/src/test/kotlin/minesweeper/MineCountTest.kt @@ -0,0 +1,12 @@ +package minesweeper + +import io.kotest.assertions.throwables.shouldThrow +import minesweeper.domain.MineCount +import org.junit.jupiter.api.Test + +class MineCountTest { + @Test + fun `mineCount는 지도 크기를 초과하면 예외가 발생한다`() { + shouldThrow { MineCount(-1) } + } +} diff --git a/src/test/kotlin/minesweeper/MineMapTest.kt b/src/test/kotlin/minesweeper/MineMapTest.kt new file mode 100644 index 000000000..2ca472ba9 --- /dev/null +++ b/src/test/kotlin/minesweeper/MineMapTest.kt @@ -0,0 +1,19 @@ +package minesweeper + +import io.kotest.assertions.throwables.shouldThrow +import minesweeper.domain.Height +import minesweeper.domain.MineCount +import minesweeper.domain.MineMap +import minesweeper.domain.Width +import org.junit.jupiter.api.Test + +class MineMapTest { + @Test + fun `지뢰 개수가 지도 크기를 초과하면 예외가 발생한다`() { + val height = Height(1) + val width = Width(1) + val mineCount = MineCount(2) + + shouldThrow { MineMap(height, width, mineCount) } + } +} \ No newline at end of file diff --git a/src/test/kotlin/minesweeper/PointTest.kt b/src/test/kotlin/minesweeper/PointTest.kt new file mode 100644 index 000000000..c96cd3574 --- /dev/null +++ b/src/test/kotlin/minesweeper/PointTest.kt @@ -0,0 +1,13 @@ +package minesweeper + +import io.kotest.assertions.throwables.shouldThrow +import minesweeper.domain.Point +import org.junit.jupiter.api.Test + +class PointTest { + @Test + fun `좌표정보는 height와 width 의 최소 값 조건을 따른다`() { + shouldThrow { Point(0, 1) } + shouldThrow { Point(1, 0) } + } +} \ No newline at end of file diff --git a/src/test/kotlin/minesweeper/WidthTest.kt b/src/test/kotlin/minesweeper/WidthTest.kt new file mode 100644 index 000000000..f5dbe59b1 --- /dev/null +++ b/src/test/kotlin/minesweeper/WidthTest.kt @@ -0,0 +1,12 @@ +package minesweeper + +import io.kotest.assertions.throwables.shouldThrow +import minesweeper.domain.Width +import org.junit.jupiter.api.Test + +class WidthTest { + @Test + fun `width는 음수 값으로 생성 시 예외가 발생한다`() { + shouldThrow { Width(0) } + } +} From c73e7073c732bb481b2dc23ee4ff039380c949d3 Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 17:39:24 +0900 Subject: [PATCH 04/10] =?UTF-8?q?chore:=20lint=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/minesweeper/domain/Height.kt | 2 +- src/main/kotlin/minesweeper/domain/MineCount.kt | 2 +- src/main/kotlin/minesweeper/domain/MineMap.kt | 4 ++-- src/main/kotlin/minesweeper/domain/Point.kt | 2 +- src/main/kotlin/minesweeper/domain/Width.kt | 4 ++-- src/main/kotlin/minesweeper/view/InputView.kt | 2 +- src/test/kotlin/minesweeper/MineMapTest.kt | 2 +- src/test/kotlin/minesweeper/PointTest.kt | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/minesweeper/domain/Height.kt b/src/main/kotlin/minesweeper/domain/Height.kt index ada4a5bcb..a6599282c 100644 --- a/src/main/kotlin/minesweeper/domain/Height.kt +++ b/src/main/kotlin/minesweeper/domain/Height.kt @@ -8,4 +8,4 @@ class Height(val value: Int) { companion object { const val MIN_HEIGHT_VALUE = 1 } -} \ No newline at end of file +} diff --git a/src/main/kotlin/minesweeper/domain/MineCount.kt b/src/main/kotlin/minesweeper/domain/MineCount.kt index 0fed5c7be..e2bdf3c3c 100644 --- a/src/main/kotlin/minesweeper/domain/MineCount.kt +++ b/src/main/kotlin/minesweeper/domain/MineCount.kt @@ -8,4 +8,4 @@ class MineCount(val value: Int) { companion object { private const val MIN_MINE_COUNT_VALUE = 0 } -} \ No newline at end of file +} diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt index 519d4f70d..49485410f 100644 --- a/src/main/kotlin/minesweeper/domain/MineMap.kt +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -9,11 +9,11 @@ class MineMap(height: Height, width: Width, mineCount: MineCount) { val mutableList = mutableListOf() (1..height.value).forEach { y -> - (1..width.value).forEach { x -> + (1..width.value).forEach { x -> mutableList.add(Point(x, y)) } } map = mutableList.toList() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/minesweeper/domain/Point.kt b/src/main/kotlin/minesweeper/domain/Point.kt index e83976f38..a3d13c2a7 100644 --- a/src/main/kotlin/minesweeper/domain/Point.kt +++ b/src/main/kotlin/minesweeper/domain/Point.kt @@ -5,4 +5,4 @@ class Point(x: Int, y: Int) { require(x >= Width.MIN_WIDTH_VALUE) { "x 좌표 값은 width의 최소 값 이상이어야합니다." } require(y >= Height.MIN_HEIGHT_VALUE) { "y 좌표 값은 height의 최소 값 이상이어야합니다." } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/minesweeper/domain/Width.kt b/src/main/kotlin/minesweeper/domain/Width.kt index 2a9d43a3b..6a2009716 100644 --- a/src/main/kotlin/minesweeper/domain/Width.kt +++ b/src/main/kotlin/minesweeper/domain/Width.kt @@ -2,10 +2,10 @@ package minesweeper.domain class Width(val value: Int) { init { - require(value >= MIN_WIDTH_VALUE) { "width는 $MIN_WIDTH_VALUE 이상만 허용됩니다."} + require(value >= MIN_WIDTH_VALUE) { "width는 $MIN_WIDTH_VALUE 이상만 허용됩니다." } } companion object { const val MIN_WIDTH_VALUE = 1 } -} \ No newline at end of file +} diff --git a/src/main/kotlin/minesweeper/view/InputView.kt b/src/main/kotlin/minesweeper/view/InputView.kt index 44098dec4..b7d576680 100644 --- a/src/main/kotlin/minesweeper/view/InputView.kt +++ b/src/main/kotlin/minesweeper/view/InputView.kt @@ -38,4 +38,4 @@ object InputView { return int } -} \ No newline at end of file +} diff --git a/src/test/kotlin/minesweeper/MineMapTest.kt b/src/test/kotlin/minesweeper/MineMapTest.kt index 2ca472ba9..22fabd9ef 100644 --- a/src/test/kotlin/minesweeper/MineMapTest.kt +++ b/src/test/kotlin/minesweeper/MineMapTest.kt @@ -16,4 +16,4 @@ class MineMapTest { shouldThrow { MineMap(height, width, mineCount) } } -} \ No newline at end of file +} diff --git a/src/test/kotlin/minesweeper/PointTest.kt b/src/test/kotlin/minesweeper/PointTest.kt index c96cd3574..e7b742a97 100644 --- a/src/test/kotlin/minesweeper/PointTest.kt +++ b/src/test/kotlin/minesweeper/PointTest.kt @@ -10,4 +10,4 @@ class PointTest { shouldThrow { Point(0, 1) } shouldThrow { Point(1, 0) } } -} \ No newline at end of file +} From 4ba37f98ea7e0ce398ed0040f099ff0846f5c9c6 Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 17:54:47 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20=EC=A7=80=EB=A2=B0=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=EB=A7=8C=ED=81=BC=20=EC=A7=80=EB=8F=84=EC=97=90=20?= =?UTF-8?q?=EC=A7=80=EB=A2=B0=EB=A5=BC=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/minesweeper/domain/MineMap.kt | 10 ++++++++-- src/main/kotlin/minesweeper/domain/MinePoint.kt | 9 +++++++++ src/main/kotlin/minesweeper/domain/Point.kt | 12 +++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/minesweeper/domain/MinePoint.kt diff --git a/README.md b/README.md index 2697c0361..95fa9b5d0 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,5 @@ - [x] 지뢰 찾기에 필요한 정보(높이, 너비, 지뢰 개수)를 입력 받는다 - [x] 높이 * 너비 만큼의 좌표 정보를 생성한다 -- [ ] 지뢰 개수만큼 랜덤한 지뢰의 위치를 구해 해당 좌표에 지뢰를 설치한다 +- [x] 지뢰 개수만큼 랜덤한 지뢰의 위치를 구해 해당 좌표에 지뢰를 설치한다 - [ ] 지뢰 찾기 게임을 출력한다 \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt index 49485410f..107ea6453 100644 --- a/src/main/kotlin/minesweeper/domain/MineMap.kt +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -2,15 +2,21 @@ package minesweeper.domain class MineMap(height: Height, width: Width, mineCount: MineCount) { private val size: Int = height.value * width.value - val map: List + private val map: List init { require(size >= mineCount.value) { "지도 크기는 지뢰 개수이상이어야 합니다." } + val mineIndexes = (0..size).shuffled().take(mineCount.value) + val mutableList = mutableListOf() (1..height.value).forEach { y -> (1..width.value).forEach { x -> - mutableList.add(Point(x, y)) + val index = (y - 1) * width.value + (x - 1) + + val point = if (mineIndexes.contains(index)) MinePoint(x, y) else Point(x, y) + + mutableList.add(point) } } diff --git a/src/main/kotlin/minesweeper/domain/MinePoint.kt b/src/main/kotlin/minesweeper/domain/MinePoint.kt new file mode 100644 index 000000000..c6cf4470d --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/MinePoint.kt @@ -0,0 +1,9 @@ +package minesweeper.domain + +class MinePoint(x: Int, y: Int) : Point(x, y) { + override val symbol = MINE_SYMBOL + + companion object { + private const val MINE_SYMBOL = "*" + } +} diff --git a/src/main/kotlin/minesweeper/domain/Point.kt b/src/main/kotlin/minesweeper/domain/Point.kt index a3d13c2a7..7d1d5b6c7 100644 --- a/src/main/kotlin/minesweeper/domain/Point.kt +++ b/src/main/kotlin/minesweeper/domain/Point.kt @@ -1,8 +1,18 @@ package minesweeper.domain -class Point(x: Int, y: Int) { +open class Point(x: Int, y: Int) { + open val symbol: String = POINT_SYMBOL + init { require(x >= Width.MIN_WIDTH_VALUE) { "x 좌표 값은 width의 최소 값 이상이어야합니다." } require(y >= Height.MIN_HEIGHT_VALUE) { "y 좌표 값은 height의 최소 값 이상이어야합니다." } } + + fun symbol(): String { + return symbol + } + + companion object { + private const val POINT_SYMBOL = "C" + } } From 7dcf4031bf635c1765c240ad123aba3513bb22f9 Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 18:00:58 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=EC=A7=80=EB=A2=B0=20=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EA=B2=8C=EC=9E=84=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/minesweeper/Main.kt | 3 +++ src/main/kotlin/minesweeper/domain/MineMap.kt | 4 ++-- src/main/kotlin/minesweeper/view/InputView.kt | 2 ++ src/main/kotlin/minesweeper/view/ResultView.kt | 16 ++++++++++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/minesweeper/view/ResultView.kt diff --git a/README.md b/README.md index 95fa9b5d0..5ba91d978 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ - [x] 지뢰 찾기에 필요한 정보(높이, 너비, 지뢰 개수)를 입력 받는다 - [x] 높이 * 너비 만큼의 좌표 정보를 생성한다 - [x] 지뢰 개수만큼 랜덤한 지뢰의 위치를 구해 해당 좌표에 지뢰를 설치한다 -- [ ] 지뢰 찾기 게임을 출력한다 \ No newline at end of file +- [x] 지뢰 찾기 게임을 출력한다 \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/Main.kt b/src/main/kotlin/minesweeper/Main.kt index 0fa283848..beac66485 100644 --- a/src/main/kotlin/minesweeper/Main.kt +++ b/src/main/kotlin/minesweeper/Main.kt @@ -5,6 +5,7 @@ import minesweeper.domain.MineCount import minesweeper.domain.MineMap import minesweeper.domain.Width import minesweeper.view.InputView +import minesweeper.view.ResultView fun main() { val height = Height(InputView.receiveHeight()) @@ -12,4 +13,6 @@ fun main() { val mineCount = MineCount(InputView.receiveMineCount()) val mineMap = MineMap(height, width, mineCount) + + ResultView.printMineGame(mineMap) } diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt index 107ea6453..452ca4029 100644 --- a/src/main/kotlin/minesweeper/domain/MineMap.kt +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -1,8 +1,8 @@ package minesweeper.domain -class MineMap(height: Height, width: Width, mineCount: MineCount) { +class MineMap(height: Height, val width: Width, mineCount: MineCount) { private val size: Int = height.value * width.value - private val map: List + val map: List init { require(size >= mineCount.value) { "지도 크기는 지뢰 개수이상이어야 합니다." } diff --git a/src/main/kotlin/minesweeper/view/InputView.kt b/src/main/kotlin/minesweeper/view/InputView.kt index b7d576680..52865a7cd 100644 --- a/src/main/kotlin/minesweeper/view/InputView.kt +++ b/src/main/kotlin/minesweeper/view/InputView.kt @@ -8,12 +8,14 @@ object InputView { } fun receiveWidth(): Int { + println() println("너비를 입력하세요.") return receiveInt() } fun receiveMineCount(): Int { + println() println("지뢰는 몇 개인가요?") return receiveInt() diff --git a/src/main/kotlin/minesweeper/view/ResultView.kt b/src/main/kotlin/minesweeper/view/ResultView.kt new file mode 100644 index 000000000..1f4120f18 --- /dev/null +++ b/src/main/kotlin/minesweeper/view/ResultView.kt @@ -0,0 +1,16 @@ +package minesweeper.view + +import minesweeper.domain.MineMap + +object ResultView { + fun printMineGame(mineMap: MineMap) { + println() + println("지뢰찾기 게임 시작") + + mineMap.map + .chunked(mineMap.width.value) + .map { line -> + println(line.joinToString(" ") { it.symbol }) + } + } +} From 0d1adf305b693e8e3e02f0c1d7cc5ed315899305 Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 9 Jul 2023 18:21:48 +0900 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20=EA=B0=9D=EC=B2=B4=EC=A7=80?= =?UTF-8?q?=ED=96=A5=EC=9B=90=EC=B9=99=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/minesweeper/domain/MineMap.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt index 452ca4029..f2716e6ae 100644 --- a/src/main/kotlin/minesweeper/domain/MineMap.kt +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -7,19 +7,27 @@ class MineMap(height: Height, val width: Width, mineCount: MineCount) { init { require(size >= mineCount.value) { "지도 크기는 지뢰 개수이상이어야 합니다." } - val mineIndexes = (0..size).shuffled().take(mineCount.value) + val mineIndexes = (0..size) + .shuffled() + .take(mineCount.value) val mutableList = mutableListOf() (1..height.value).forEach { y -> (1..width.value).forEach { x -> val index = (y - 1) * width.value + (x - 1) - val point = if (mineIndexes.contains(index)) MinePoint(x, y) else Point(x, y) - - mutableList.add(point) + mutableList.add(point(mineIndexes.contains(index), x, y)) } } map = mutableList.toList() } + + private fun point(isMine: Boolean, x: Int, y: Int): Point { + if (isMine) { + return MinePoint(x, y) + } + + return Point(x, y) + } } From 1ace61c11422f943ea7c053a1f6d7775d3729f2b Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 16 Jul 2023 22:15:15 +0900 Subject: [PATCH 08/10] =?UTF-8?q?refactor:=20=EA=B0=9D=EC=B2=B4=EC=A7=80?= =?UTF-8?q?=ED=96=A5=EC=9B=90=EC=B9=99=20=EC=A0=81=EC=9A=A9=20=20-=203?= =?UTF-8?q?=EA=B0=9C=20=EC=9D=B4=EC=83=81=EC=9D=98=20=EC=9D=B8=EC=8A=A4?= =?UTF-8?q?=ED=84=B4=EC=8A=A4=20=EB=B3=80=EC=88=98=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EC=A7=80=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=20-=20=ED=95=9C=20=EB=8B=A8=EA=B3=84=EC=9D=98=20?= =?UTF-8?q?=EB=93=A4=EC=97=AC=EC=93=B0=EA=B8=B0=EB=A7=8C=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/minesweeper/Main.kt | 4 ++- src/main/kotlin/minesweeper/domain/MineMap.kt | 33 ++++++++++++++----- .../kotlin/minesweeper/domain/MineMapSize.kt | 19 +++++++++++ .../kotlin/minesweeper/view/ResultView.kt | 2 +- .../kotlin/minesweeper/MineMapSizeTest.kt | 18 ++++++++++ src/test/kotlin/minesweeper/MineMapTest.kt | 4 ++- 6 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/minesweeper/domain/MineMapSize.kt create mode 100644 src/test/kotlin/minesweeper/MineMapSizeTest.kt diff --git a/src/main/kotlin/minesweeper/Main.kt b/src/main/kotlin/minesweeper/Main.kt index beac66485..e64ca9d7d 100644 --- a/src/main/kotlin/minesweeper/Main.kt +++ b/src/main/kotlin/minesweeper/Main.kt @@ -3,6 +3,7 @@ package minesweeper import minesweeper.domain.Height import minesweeper.domain.MineCount import minesweeper.domain.MineMap +import minesweeper.domain.MineMapSize import minesweeper.domain.Width import minesweeper.view.InputView import minesweeper.view.ResultView @@ -10,9 +11,10 @@ import minesweeper.view.ResultView fun main() { val height = Height(InputView.receiveHeight()) val width = Width(InputView.receiveWidth()) + val mineMapSize = MineMapSize(width, height) val mineCount = MineCount(InputView.receiveMineCount()) - val mineMap = MineMap(height, width, mineCount) + val mineMap = MineMap(mineMapSize, mineCount) ResultView.printMineGame(mineMap) } diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt index f2716e6ae..f5bd14908 100644 --- a/src/main/kotlin/minesweeper/domain/MineMap.kt +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -1,7 +1,7 @@ package minesweeper.domain -class MineMap(height: Height, val width: Width, mineCount: MineCount) { - private val size: Int = height.value * width.value +class MineMap(private val mineMapSize: MineMapSize, mineCount: MineCount) { + private val size: Int = mineMapSize.size() val map: List init { @@ -10,17 +10,32 @@ class MineMap(height: Height, val width: Width, mineCount: MineCount) { val mineIndexes = (0..size) .shuffled() .take(mineCount.value) + val height = mineMapSize.height() + val width = mineMapSize.width() - val mutableList = mutableListOf() - (1..height.value).forEach { y -> - (1..width.value).forEach { x -> - val index = (y - 1) * width.value + (x - 1) + map = points(height, width, mineIndexes) + } - mutableList.add(point(mineIndexes.contains(index), x, y)) - } + private fun points( + height: Int, + width: Int, + mineIndexes: List + ): List { + return (1..height).flatMap { y -> + generateRow(width, mineIndexes, y) } + } + + private fun generateRow( + width: Int, + mineIndexes: List, + y: Int + ) = (1..width).map { x -> + point(mineIndexes.contains(mineMapSize.getIndex(y, x)), x, y) + } - map = mutableList.toList() + fun width(): Int { + return mineMapSize.width() } private fun point(isMine: Boolean, x: Int, y: Int): Point { diff --git a/src/main/kotlin/minesweeper/domain/MineMapSize.kt b/src/main/kotlin/minesweeper/domain/MineMapSize.kt new file mode 100644 index 000000000..6e9b2ec0a --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/MineMapSize.kt @@ -0,0 +1,19 @@ +package minesweeper.domain + +class MineMapSize(private val width: Width, private val height: Height) { + fun size(): Int { + return width.value * height.value + } + + fun width(): Int { + return width.value + } + + fun height(): Int { + return height.value + } + + fun getIndex(heightIndex: Int, widthIndex: Int): Int { + return (heightIndex - 1) * width() + (widthIndex - 1) + } +} \ No newline at end of file diff --git a/src/main/kotlin/minesweeper/view/ResultView.kt b/src/main/kotlin/minesweeper/view/ResultView.kt index 1f4120f18..d2afbbc66 100644 --- a/src/main/kotlin/minesweeper/view/ResultView.kt +++ b/src/main/kotlin/minesweeper/view/ResultView.kt @@ -8,7 +8,7 @@ object ResultView { println("지뢰찾기 게임 시작") mineMap.map - .chunked(mineMap.width.value) + .chunked(mineMap.width()) .map { line -> println(line.joinToString(" ") { it.symbol }) } diff --git a/src/test/kotlin/minesweeper/MineMapSizeTest.kt b/src/test/kotlin/minesweeper/MineMapSizeTest.kt new file mode 100644 index 000000000..8fe444700 --- /dev/null +++ b/src/test/kotlin/minesweeper/MineMapSizeTest.kt @@ -0,0 +1,18 @@ +package minesweeper + +import io.kotest.matchers.shouldBe +import minesweeper.domain.Height +import minesweeper.domain.MineMapSize +import minesweeper.domain.Width +import org.junit.jupiter.api.Test + +class MineMapSizeTest { + @Test + fun `size는 width와 height의 value의 곱이다`() { + val width = Width(5) + val height = Height(5) + val mineMapSize = MineMapSize(width, height) + + mineMapSize.size() shouldBe 25 + } +} \ No newline at end of file diff --git a/src/test/kotlin/minesweeper/MineMapTest.kt b/src/test/kotlin/minesweeper/MineMapTest.kt index 22fabd9ef..1743c1eb1 100644 --- a/src/test/kotlin/minesweeper/MineMapTest.kt +++ b/src/test/kotlin/minesweeper/MineMapTest.kt @@ -4,6 +4,7 @@ import io.kotest.assertions.throwables.shouldThrow import minesweeper.domain.Height import minesweeper.domain.MineCount import minesweeper.domain.MineMap +import minesweeper.domain.MineMapSize import minesweeper.domain.Width import org.junit.jupiter.api.Test @@ -12,8 +13,9 @@ class MineMapTest { fun `지뢰 개수가 지도 크기를 초과하면 예외가 발생한다`() { val height = Height(1) val width = Width(1) + val mineMapSize = MineMapSize(width, height) val mineCount = MineCount(2) - shouldThrow { MineMap(height, width, mineCount) } + shouldThrow { MineMap(mineMapSize, mineCount) } } } From 802cd55fcaf3b34079f5ea6dfc1e8ded4b8a472e Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 16 Jul 2023 22:28:22 +0900 Subject: [PATCH 09/10] =?UTF-8?q?refactor:=20=EB=84=A4=EC=9D=B4=EB=B0=8D?= =?UTF-8?q?=EC=9D=84=20=EC=9E=90=EC=97=B0=EC=8A=A4=EB=9F=BD=EA=B2=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/minesweeper/view/InputView.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/minesweeper/view/InputView.kt b/src/main/kotlin/minesweeper/view/InputView.kt index 52865a7cd..452147f90 100644 --- a/src/main/kotlin/minesweeper/view/InputView.kt +++ b/src/main/kotlin/minesweeper/view/InputView.kt @@ -4,21 +4,21 @@ object InputView { fun receiveHeight(): Int { println("높이를 입력하세요.") - return receiveInt() + return receiveNotNullNumber() } fun receiveWidth(): Int { println() println("너비를 입력하세요.") - return receiveInt() + return receiveNotNullNumber() } fun receiveMineCount(): Int { println() println("지뢰는 몇 개인가요?") - return receiveInt() + return receiveNotNullNumber() } private fun receiveString(): String { @@ -31,13 +31,13 @@ object InputView { return input } - private fun receiveInt(): Int { - var int: Int? = receiveString().toIntOrNull() + private fun receiveNotNullNumber(): Int { + var input: Int? = receiveString().toIntOrNull() - while (int == null) { - int = receiveString().toIntOrNull() + while (input == null) { + input = receiveString().toIntOrNull() } - return int + return input } } From af2ae0067a19164ba69eda518c2333f56045b1bc Mon Sep 17 00:00:00 2001 From: "turner.lee" Date: Sun, 16 Jul 2023 23:04:47 +0900 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20=EC=A7=80=EB=A2=B0=EC=9D=98?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EB=9E=9C=EB=8D=A4=EC=9C=BC=EB=A1=9C=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EC=A7=80=EC=95=8A=EA=B3=A0=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/minesweeper/Main.kt | 8 ++++--- .../kotlin/minesweeper/domain/MineCount.kt | 11 --------- .../kotlin/minesweeper/domain/MineIndexes.kt | 19 +++++++++++++++ src/main/kotlin/minesweeper/domain/MineMap.kt | 23 ++++++++++--------- .../kotlin/minesweeper/domain/MineMapSize.kt | 2 +- .../domain/RandomIndexesGenerator.kt | 9 ++++++++ src/test/kotlin/minesweeper/MineCountTest.kt | 12 ---------- .../kotlin/minesweeper/MineMapSizeTest.kt | 2 +- src/test/kotlin/minesweeper/MineMapTest.kt | 21 ++++++++++++++--- 9 files changed, 65 insertions(+), 42 deletions(-) delete mode 100644 src/main/kotlin/minesweeper/domain/MineCount.kt create mode 100644 src/main/kotlin/minesweeper/domain/MineIndexes.kt create mode 100644 src/main/kotlin/minesweeper/domain/RandomIndexesGenerator.kt delete mode 100644 src/test/kotlin/minesweeper/MineCountTest.kt diff --git a/src/main/kotlin/minesweeper/Main.kt b/src/main/kotlin/minesweeper/Main.kt index e64ca9d7d..b291dd673 100644 --- a/src/main/kotlin/minesweeper/Main.kt +++ b/src/main/kotlin/minesweeper/Main.kt @@ -1,9 +1,10 @@ package minesweeper import minesweeper.domain.Height -import minesweeper.domain.MineCount +import minesweeper.domain.MineIndexes import minesweeper.domain.MineMap import minesweeper.domain.MineMapSize +import minesweeper.domain.RandomIndexesGenerator import minesweeper.domain.Width import minesweeper.view.InputView import minesweeper.view.ResultView @@ -12,9 +13,10 @@ fun main() { val height = Height(InputView.receiveHeight()) val width = Width(InputView.receiveWidth()) val mineMapSize = MineMapSize(width, height) - val mineCount = MineCount(InputView.receiveMineCount()) + val mineCount = InputView.receiveMineCount() + val mineIndexes = MineIndexes(RandomIndexesGenerator.generate(mineCount, mineMapSize.size())) - val mineMap = MineMap(mineMapSize, mineCount) + val mineMap = MineMap(mineMapSize, mineIndexes) ResultView.printMineGame(mineMap) } diff --git a/src/main/kotlin/minesweeper/domain/MineCount.kt b/src/main/kotlin/minesweeper/domain/MineCount.kt deleted file mode 100644 index e2bdf3c3c..000000000 --- a/src/main/kotlin/minesweeper/domain/MineCount.kt +++ /dev/null @@ -1,11 +0,0 @@ -package minesweeper.domain - -class MineCount(val value: Int) { - init { - require(value >= MIN_MINE_COUNT_VALUE) { "지뢰 개수는 $MIN_MINE_COUNT_VALUE 이상만 허용됩니다." } - } - - companion object { - private const val MIN_MINE_COUNT_VALUE = 0 - } -} diff --git a/src/main/kotlin/minesweeper/domain/MineIndexes.kt b/src/main/kotlin/minesweeper/domain/MineIndexes.kt new file mode 100644 index 000000000..1ae73d205 --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/MineIndexes.kt @@ -0,0 +1,19 @@ +package minesweeper.domain + +class MineIndexes(private val indexes: List) { + init { + require(indexes.size >= MIN_MINE_COUNT_VALUE) { "지뢰 개수는 $MIN_MINE_COUNT_VALUE 이상만 허용됩니다." } + } + + fun contains(index: Int): Boolean { + return indexes.contains(index) + } + + fun size(): Int { + return indexes.size + } + + companion object { + private const val MIN_MINE_COUNT_VALUE = 0 + } +} diff --git a/src/main/kotlin/minesweeper/domain/MineMap.kt b/src/main/kotlin/minesweeper/domain/MineMap.kt index f5bd14908..aaebbf9fb 100644 --- a/src/main/kotlin/minesweeper/domain/MineMap.kt +++ b/src/main/kotlin/minesweeper/domain/MineMap.kt @@ -1,25 +1,30 @@ package minesweeper.domain -class MineMap(private val mineMapSize: MineMapSize, mineCount: MineCount) { +class MineMap(private val mineMapSize: MineMapSize, mineIndexes: MineIndexes) { private val size: Int = mineMapSize.size() val map: List init { - require(size >= mineCount.value) { "지도 크기는 지뢰 개수이상이어야 합니다." } + require(size >= mineIndexes.size()) { "지도 크기는 지뢰 개수이상이어야 합니다." } - val mineIndexes = (0..size) - .shuffled() - .take(mineCount.value) val height = mineMapSize.height() val width = mineMapSize.width() map = points(height, width, mineIndexes) } + fun width(): Int { + return mineMapSize.width() + } + + fun getPoint(index: Int): Point { + return map[index] + } + private fun points( height: Int, width: Int, - mineIndexes: List + mineIndexes: MineIndexes ): List { return (1..height).flatMap { y -> generateRow(width, mineIndexes, y) @@ -28,16 +33,12 @@ class MineMap(private val mineMapSize: MineMapSize, mineCount: MineCount) { private fun generateRow( width: Int, - mineIndexes: List, + mineIndexes: MineIndexes, y: Int ) = (1..width).map { x -> point(mineIndexes.contains(mineMapSize.getIndex(y, x)), x, y) } - fun width(): Int { - return mineMapSize.width() - } - private fun point(isMine: Boolean, x: Int, y: Int): Point { if (isMine) { return MinePoint(x, y) diff --git a/src/main/kotlin/minesweeper/domain/MineMapSize.kt b/src/main/kotlin/minesweeper/domain/MineMapSize.kt index 6e9b2ec0a..9e7bcdc60 100644 --- a/src/main/kotlin/minesweeper/domain/MineMapSize.kt +++ b/src/main/kotlin/minesweeper/domain/MineMapSize.kt @@ -16,4 +16,4 @@ class MineMapSize(private val width: Width, private val height: Height) { fun getIndex(heightIndex: Int, widthIndex: Int): Int { return (heightIndex - 1) * width() + (widthIndex - 1) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/minesweeper/domain/RandomIndexesGenerator.kt b/src/main/kotlin/minesweeper/domain/RandomIndexesGenerator.kt new file mode 100644 index 000000000..2f7ae32f8 --- /dev/null +++ b/src/main/kotlin/minesweeper/domain/RandomIndexesGenerator.kt @@ -0,0 +1,9 @@ +package minesweeper.domain + +object RandomIndexesGenerator { + fun generate(size: Int, maximum: Int): List { + return (0..maximum) + .shuffled() + .take(size) + } +} \ No newline at end of file diff --git a/src/test/kotlin/minesweeper/MineCountTest.kt b/src/test/kotlin/minesweeper/MineCountTest.kt deleted file mode 100644 index 18e4f6b04..000000000 --- a/src/test/kotlin/minesweeper/MineCountTest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package minesweeper - -import io.kotest.assertions.throwables.shouldThrow -import minesweeper.domain.MineCount -import org.junit.jupiter.api.Test - -class MineCountTest { - @Test - fun `mineCount는 지도 크기를 초과하면 예외가 발생한다`() { - shouldThrow { MineCount(-1) } - } -} diff --git a/src/test/kotlin/minesweeper/MineMapSizeTest.kt b/src/test/kotlin/minesweeper/MineMapSizeTest.kt index 8fe444700..fc291d427 100644 --- a/src/test/kotlin/minesweeper/MineMapSizeTest.kt +++ b/src/test/kotlin/minesweeper/MineMapSizeTest.kt @@ -15,4 +15,4 @@ class MineMapSizeTest { mineMapSize.size() shouldBe 25 } -} \ No newline at end of file +} diff --git a/src/test/kotlin/minesweeper/MineMapTest.kt b/src/test/kotlin/minesweeper/MineMapTest.kt index 1743c1eb1..6317dc735 100644 --- a/src/test/kotlin/minesweeper/MineMapTest.kt +++ b/src/test/kotlin/minesweeper/MineMapTest.kt @@ -1,10 +1,12 @@ package minesweeper import io.kotest.assertions.throwables.shouldThrow +import io.kotest.matchers.types.shouldBeTypeOf import minesweeper.domain.Height -import minesweeper.domain.MineCount +import minesweeper.domain.MineIndexes import minesweeper.domain.MineMap import minesweeper.domain.MineMapSize +import minesweeper.domain.MinePoint import minesweeper.domain.Width import org.junit.jupiter.api.Test @@ -14,8 +16,21 @@ class MineMapTest { val height = Height(1) val width = Width(1) val mineMapSize = MineMapSize(width, height) - val mineCount = MineCount(2) + val mineIndexes = MineIndexes(listOf(1, 2, 3)) - shouldThrow { MineMap(mineMapSize, mineCount) } + shouldThrow { MineMap(mineMapSize, mineIndexes) } + } + + @Test + fun `mineIndexes에 표시된 위치에 지뢰가 심어진다`() { + val height = Height(10) + val width = Width(10) + val mineMapSize = MineMapSize(width, height) + val mineIndexes = MineIndexes(listOf(1, 2, 3)) + val mineMap = MineMap(mineMapSize, mineIndexes) + + mineMap.getPoint(1).shouldBeTypeOf() + mineMap.getPoint(2).shouldBeTypeOf() + mineMap.getPoint(3).shouldBeTypeOf() } }