Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FL 워들제출합니다. #5

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
190ac26
docs : 요구사항 정리
Apr 11, 2022
337557e
feat(Tile.kt): Tile에는 문자가 들어간다.
Apr 11, 2022
9e6149d
feat(Tile.kt): 알파벳만 입력이 가능하다.
Apr 11, 2022
f697439
docs : Tile의 구현 방식 변경으로 인한 요구사항 정의 변경
Apr 11, 2022
f5d8d6d
feat(Tile.kt) : Tile과 Tile은 비교할 수 있다.
Apr 11, 2022
8771abc
feat(Tiles.kt) : 5개의 Tile을 구성할 수 있는 Tiles 구현
Apr 12, 2022
862eb7e
feat(Tiles.kt) : Tiles는 5글자를 받는다.
Apr 12, 2022
b84dc75
docs : Answer에 대한 정의
Apr 12, 2022
ac876f8
feat(Answer.kt) : Answer는 5개의 Tile로 구성이 되어있다.
Apr 12, 2022
8c1daf1
feat(Answer.kt) : Answer는 5글자를 받는다.
Apr 12, 2022
6a25262
feat(Answer.kt, Tiles.kt): 정답과 비교하여 같은 위치에 있으면 GREEN이다
Apr 12, 2022
ee13936
feat(Answer.kt, Tiles.kt): 정답에는 있지만 위치가 다르면 노란색
Apr 12, 2022
18d8b9f
feat(Answer.kt, Tiles.kt): 아예 없으면 회색
Apr 12, 2022
8ca253b
feat(Answer.kt): 정답에 있는 타일은 n개이지만, 입력한 타일은 n + 1개 이상인 경우 초록 -> 노란색 ->…
Apr 12, 2022
7f95066
refact : 매직넘버 제거
Apr 12, 2022
44a0e0d
refact : MatchResult 도메인 명칭으로 변경
Apr 12, 2022
56b4cd9
feat(MatchResults.kt) : MatchResult 일급컬렉션 구현
Apr 12, 2022
d8b6671
feat(Game.kt) : 기회는 총 6번이 있다.
Apr 13, 2022
d0ffc16
feat(Game.kt) : 정답을 적으면 게임이 끝난다.
Apr 13, 2022
f4d6b61
feat(Game.kt) : 결과를 전달할 수 있다.
Apr 13, 2022
08ee075
feat(Game.kt) : 존재하지 않는 단어이면 재입력을 한다.
Apr 13, 2022
f775ac7
feat(Game.kt) : 정답과 답안은 words.txt 에 있고, 날짜가 바뀔 때 마다 답이 바뀐다.
Apr 14, 2022
8271db1
feat(DefaultOutput.kt) : 기본 아웃풋 추가
Apr 14, 2022
5f72da9
refact(ALL) : 전체적인 린트 적용 및 리팩터링
Apr 14, 2022
d9cefda
chore() : lint 검사
Flamme1004K Apr 16, 2022
9b74d70
refactor : Game 클래스의 input, ouput 침투 로직 리팩토링
Flamme1004K Apr 16, 2022
dde9105
refactor(DefaultInput.kt) : readln으로 변경
Flamme1004K Apr 16, 2022
24ff1f6
chore : lint 검사
Flamme1004K Apr 16, 2022
3da26d3
refactor(WordsPool.kt) : WordsPool 리팩토링
Flamme1004K Apr 16, 2022
e0d8ff7
refactor(Input.kt, Output.kt) : fun interface로 변경
Flamme1004K Apr 16, 2022
8ba25c6
refactor(words.kt) : wordsRepository -> words 변경 및 file 로직 수정
Flamme1004K Apr 16, 2022
41ef174
refactor(WordleController.kt, Game.kt, MatchResults) : TryCount Excep…
Flamme1004K Apr 16, 2022
0d77637
test(AnswerTest.kt) : AnswerTest를 JunitTest에서 KoTest로 변경
Flamme1004K Apr 16, 2022
b844aea
test(GameTest.kt) : GameTest를 JunitTest에서 KoTest로 변경
Flamme1004K Apr 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(AnswerTest.kt) : AnswerTest를 JunitTest에서 KoTest로 변경
Flamme1004K committed Apr 16, 2022
commit 0d7763787ad8635d2a5fb2386eba6ab5479f042a
187 changes: 74 additions & 113 deletions src/test/kotlin/domain/AnswerTest.kt
Original file line number Diff line number Diff line change
@@ -3,119 +3,80 @@ package domain
import domain.MatchResult.CORRECT
import domain.MatchResult.INCORRECT
import domain.MatchResult.MISSING
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

internal class AnswerTest {
@Test
fun `Answer는 5개의 Tile로 구성이 되어있다`() {
// given
val elements = Tiles.of("hello")

// when
val answer = Answer(elements)

// then
assertThat(answer.tiles).containsExactlyElementsOf(elements)
}

@Test
fun `Answer는 문자열 5글자로 구성 할 수 있다`() {
// given
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.data.forAll
import io.kotest.data.headers
import io.kotest.data.row
import io.kotest.data.table
import io.kotest.matchers.collections.shouldContain
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe

internal class AnswerTest : ShouldSpec({
context("Answer는") {
val answer = Answer.of("hello")

// then
assertThat(answer.tiles)
.containsExactly(Tile('h'), Tile('e'), Tile('l'), Tile('l'), Tile('o'))
}

@ParameterizedTest
@ValueSource(strings = ["", "h", "hell", "hellow"])
fun `Answer는 문자열 5글자로 구성이 안되면 실패한다`(words: String) {
// then
Assertions.assertThatIllegalArgumentException()
.isThrownBy { Answer.of(words) }
.withMessage(Answer.ERROR_TILE_SIZE_MSG)
}

@Test
fun `정답과 비교하여 같은 위치에 있으면 CORRECT이다`() {
// given
val answer = Answer.of("hello")
val tiles = Tiles.of("hello")

// when
val matches = answer.match(tiles)

// then
assertThat(matches.results).containsOnly(CORRECT)
}

@Test
fun `정답은 아니지만 Tile이 있으면 MISSING이다`() {
// given
val answer = Answer.of("hello")
val tiles = Tiles.of("olehl")

// when
val matches = answer.match(tiles)

// then
assertThat(matches.results).containsOnly(MISSING)
}

@Test
fun `정답에 Tile이 없으면 INCORRECT이다`() {
// given
val answer = Answer.of("hello")
val tiles = Tiles.of("zzzzz")

// when
val matches = answer.match(tiles)

// then
assertThat(matches.results).containsOnly(INCORRECT)
}

@Test
fun `정답을 머저 CORRECT으로 변경하고 나머지 존재하는 부분을 MISSING으로 변경한다`() {
// given
val answer = Answer.of("hello")
val tiles = Tiles.of("olleh")

// when
val matches = answer.match(tiles)

// then
assertThat(matches.results).containsExactly(MISSING, MISSING, CORRECT, MISSING, MISSING)
}

@Test
fun `정답이 뒤에 있으면 정답부터 CORRECT으로 변경된다`() {
// given
val answer = Answer.of("hello")
val tiles = Tiles.of("lllll")

// when
val matches = answer.match(tiles)

// then
assertThat(matches.results).containsExactly(INCORRECT, INCORRECT, CORRECT, CORRECT, INCORRECT)
}

@Test
fun `답에 있는 타일 개수보다 많으면 INCORRECT으로 변경된다`() {
// given
val answer = Answer.of("hello")
val tiles = Tiles.of("llool")

// when
val matches = answer.match(tiles)

// then
assertThat(matches.results).containsExactly(MISSING, MISSING, MISSING, INCORRECT, INCORRECT)
context("5개 Tile 로") {
val tiles = Tiles.of("hello")
should("구성되어 있다") {
answer.tiles shouldBe tiles
}
}

context("5개가 아닌 Tile 은") {
should("실패한다") {
forAll(
table(
headers("word"),
row(""),
row("h"),
row("hell"),
row("hellow"),
)
) { word ->
shouldThrow<IllegalArgumentException> { Answer.of(word) }
}
}
}

context("답안과 비교하여") {
Copy link

@etff etff Apr 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 컨텍스트가 답안 컨텍스트와 동일한 레벨로 구성되어있는데요.

정상적인 답안 Answer 컨텍스트 내부 -> 입력 받은 타일 비교로 구성하면
테스트 가독성이 더 좋아질 것같습니다.


should("같은 위치에 있으면 CORRECT이다") {
val tiles = Tiles.of("hello")
val matches = answer.match(tiles)
matches.results shouldContainExactly listOf(CORRECT, CORRECT, CORRECT, CORRECT, CORRECT)
}

should("다른 위치에 있으면 MISSING이다") {
val tiles = Tiles.of("olehl")
val matches = answer.match(tiles)
matches.results shouldContain MISSING
}

should("없을 경우 INCORRECT이다") {
val tiles = Tiles.of("zzzzz")
val matches = answer.match(tiles)
matches.results shouldContain INCORRECT
}

should("맞는 부분을 CORRECT로 변경하고 나머지 존재하는 부분을 MISSING으로 변경된다 ") {
val tiles = Tiles.of("olleh")
val matches = answer.match(tiles)
matches.results shouldContainExactly listOf(MISSING, MISSING, CORRECT, MISSING, MISSING)
}

should("정답이 뒤에 있으면 정답부터 CORRECT으로 변경된다") {
val tiles = Tiles.of("lllll")
val matches = answer.match(tiles)
matches.results shouldContainExactly listOf(INCORRECT, INCORRECT, CORRECT, CORRECT, INCORRECT)
}

should("답안에 있는 타일이 정답 개수보다 많으면 겹치는 부분을 제외한 부분이 INCORRECT으로 변경된다") {
val tiles = Tiles.of("llool")
val matches = answer.match(tiles)
matches.results shouldContainExactly listOf(MISSING, MISSING, MISSING, INCORRECT, INCORRECT)
}
}
}
}
})