-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathCellFinderTest.kt
More file actions
67 lines (62 loc) · 2.51 KB
/
Copy pathCellFinderTest.kt
File metadata and controls
67 lines (62 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package minesweeper.domain
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.data.forAll
import io.kotest.data.row
import io.kotest.matchers.shouldBe
class CellFinderTest : BehaviorSpec({
Given("지뢰 위치들이 주어질 때") {
val minePosition = Position(1, 1)
val minePositions = listOf(minePosition)
When("CellFinder의 convert 함수를 호출하면") {
val cellFinder = CellFinder.init(Size(10), Size(10))
cellFinder.convert(minePositions)
Then("주어진 지뢰 위치는 지뢰로 변해있다.") {
cellFinder.find(minePosition)?.isMine shouldBe true
}
}
}
Given("위치가 주어질 때") {
val position = Position(2, 2)
val cellFinder = CellFinder.init(Size(10), Size(10))
val minePositions = listOf(Position(1, 2), Position(1, 3))
cellFinder.convert(minePositions)
When("CellFinder의 getAroundMinesCount 함수를 호출하면") {
val result = cellFinder.getAroundMinesCount(position)
Then("자신을 제외한 주변 8개 사각형에 포함된 지뢰의 개수를 반환한다.") {
result shouldBe 2
}
}
}
Given("지뢰가 있는지 알고 싶은 위치가 주어질 때") {
val cellFinder = CellFinder.init(Size(10), Size(10))
val minePositions = listOf(Position(1, 2), Position(1, 3))
cellFinder.convert(minePositions)
When("isMine 함수를 호출하면") {
Then("지뢰가 있는지 여부를 반환한다.") {
forAll(
row(Position(1, 2), true),
row(Position(1, 3), true),
row(Position(2, 2), false),
) { position, expected ->
cellFinder.isMine(position) shouldBe expected
}
}
}
}
Given("찾고 싶은 위치가 주어질 때") {
val cellFinder = CellFinder.init(Size(10), Size(10))
val minePositions = listOf(Position(1, 2), Position(1, 3))
cellFinder.convert(minePositions)
When("find 함수를 호출하면") {
Then("해당 위치의 Cell을 반환한다.") {
forAll(
row(Position(1, 2)),
row(Position(1, 3)),
row(Position(2, 2)),
) { position ->
cellFinder.find(position)?.position shouldBe position
}
}
}
}
})