-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from swm-standard/seyeon/swm-177
Fix: ํธ๋์ญ์ ์ค์ ๋ฐ fixtureMonkey ํ ์คํธ ์ฝ๋ ์ ์ฒด ์ ์ฉ
- Loading branch information
Showing
9 changed files
with
212 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,53 @@ | ||
package com.swm_standard.phote.entity | ||
|
||
import org.assertj.core.api.Assertions | ||
import com.navercorp.fixturemonkey.FixtureMonkey | ||
import com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector | ||
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin | ||
import com.navercorp.fixturemonkey.kotlin.giveMeBuilder | ||
import com.navercorp.fixturemonkey.kotlin.giveMeOne | ||
import com.navercorp.fixturemonkey.kotlin.setExp | ||
import net.jqwik.api.Arbitraries | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import java.util.UUID | ||
|
||
class AnswerTest { | ||
private val fixtureMonkey = | ||
FixtureMonkey | ||
.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE) | ||
.build() | ||
|
||
@Test | ||
fun `๋ฌธ์ ๊ฐ ๊ฐ๊ด์์ด๋ฉด ์ ์ค๋ต ์ฒดํฌํ๋ค`() { | ||
val submittedAnswer = Arbitraries.strings().numeric().sample() | ||
val category = Category.MULTIPLE | ||
val submittedAnswer = "1" | ||
val correctAnswer = "5" | ||
val answer = createAnswer(category, submittedAnswer, correctAnswer) | ||
val correctAnswer = Arbitraries.strings().numeric().sample() | ||
val answer = | ||
fixtureMonkey | ||
.giveMeBuilder<Answer>() | ||
.setExp(Answer::submittedAnswer, submittedAnswer) | ||
.setExp( | ||
Answer::question, | ||
fixtureMonkey.giveMeBuilder<Question>().setExp(Question::answer, correctAnswer).sample(), | ||
).sample() | ||
|
||
answer.checkMultipleAnswer() | ||
|
||
Assertions.assertThat(submittedAnswer == correctAnswer).isEqualTo(answer.isCorrect) | ||
Assertions.assertThat(answer.isCorrect).isFalse() | ||
assertThat(submittedAnswer == correctAnswer).isEqualTo(answer.isCorrect) | ||
assertThat(answer.isCorrect).isFalse() | ||
} | ||
|
||
@Test | ||
fun `์ ์ถํ ๋ต์์ ์์ฑํ๋ค`() { | ||
val exam = createExam() | ||
val submittedAnswer = "1" | ||
val question = createQuestion(answer = submittedAnswer) | ||
val sequence = 2 | ||
val exam: Exam = fixtureMonkey.giveMeOne() | ||
val submittedAnswer = Arbitraries.strings().numeric().sample() | ||
val question = | ||
fixtureMonkey | ||
.giveMeBuilder<Question>() | ||
.setExp(Question::answer, submittedAnswer) | ||
.sample() | ||
val sequence = Arbitraries.integers().sample() | ||
|
||
val createAnswer = | ||
Answer.createAnswer( | ||
|
@@ -33,80 +57,8 @@ class AnswerTest { | |
sequence = sequence, | ||
) | ||
|
||
Assertions.assertThat(createAnswer.submittedAnswer).isEqualTo(submittedAnswer) | ||
Assertions.assertThat(createAnswer.exam).isEqualTo(exam) | ||
Assertions.assertThat(createAnswer.sequence).isEqualTo(sequence) | ||
assertThat(createAnswer.submittedAnswer).isEqualTo(submittedAnswer) | ||
assertThat(createAnswer.exam).isEqualTo(exam) | ||
assertThat(createAnswer.sequence).isEqualTo(sequence) | ||
} | ||
|
||
fun createWorkbook(): Workbook = | ||
Workbook( | ||
title = "hinc", | ||
description = null, | ||
member = createMember(), | ||
emoji = "๐", | ||
) | ||
|
||
fun createExam() = | ||
Exam( | ||
member = createMember(), | ||
workbook = createWorkbook(), | ||
sequence = 4282, | ||
time = 40, | ||
) | ||
|
||
fun createAnswer( | ||
category: Category, | ||
submittedAnswer: String?, | ||
correctAnswer: String, | ||
) = Answer( | ||
question = | ||
Question( | ||
id = UUID.randomUUID(), | ||
member = | ||
Member( | ||
name = "Erik Ashley", | ||
email = "[email protected]", | ||
image = "per", | ||
provider = Provider.APPLE, | ||
), | ||
statement = "Kentucky", | ||
options = null, | ||
image = null, | ||
answer = correctAnswer, | ||
category = category, | ||
questionSet = listOf(), | ||
memo = null, | ||
), | ||
exam = createExam(), | ||
submittedAnswer = submittedAnswer, | ||
sequence = 2017, | ||
) | ||
|
||
private fun createQuestion(answer: String) = | ||
Question( | ||
id = UUID.randomUUID(), | ||
member = | ||
Member( | ||
name = "Charmaine Joseph", | ||
email = "[email protected]", | ||
image = "maiorum", | ||
provider = Provider.APPLE, | ||
), | ||
statement = "Missouri", | ||
options = null, | ||
image = null, | ||
answer = answer, | ||
category = Category.MULTIPLE, | ||
questionSet = listOf(), | ||
tags = mutableListOf(), | ||
memo = null, | ||
) | ||
|
||
private fun createMember() = | ||
Member( | ||
name = "Wilbur Noel", | ||
email = "[email protected]", | ||
image = "ocurreret", | ||
provider = Provider.APPLE, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,32 @@ | ||
package com.swm_standard.phote.entity | ||
|
||
import org.assertj.core.api.Assertions | ||
import com.navercorp.fixturemonkey.FixtureMonkey | ||
import com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector | ||
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin | ||
import com.navercorp.fixturemonkey.kotlin.giveMeBuilder | ||
import com.navercorp.fixturemonkey.kotlin.giveMeOne | ||
import com.navercorp.fixturemonkey.kotlin.setExp | ||
import com.navercorp.fixturemonkey.kotlin.sizeExp | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class ExamTest { | ||
private fun createExam(): Exam { | ||
val member = Member("phote", "[email protected]", "imageUrl", Provider.KAKAO) | ||
val workbook = Workbook.createWorkbook(title = "testTitle", description = "", member = member) | ||
|
||
val exam = | ||
Exam( | ||
member = member, | ||
workbook = workbook, | ||
sequence = 1, | ||
time = 30, | ||
) | ||
|
||
val answer = | ||
Answer( | ||
question = | ||
Question( | ||
member = member, | ||
statement = "๋ชจ๋ ๊ฐ์ด ๋์ผํ ์ผ๊ฐํ์?", | ||
image = "http://example.com/image.jpg", | ||
answer = "์ ์ผ๊ฐํ", | ||
category = Category.ESSAY, | ||
memo = "์ผ๊ฐํ ๋ด๊ฐ์ ํฉ์ 180๋์ด๋ค.", | ||
), | ||
exam = exam, | ||
submittedAnswer = "์ ์ผ๊ฐํ", | ||
sequence = 1, | ||
) | ||
|
||
answer.isCorrect = true | ||
|
||
exam.answers.add(answer) | ||
exam.answers.add(answer) | ||
|
||
return exam | ||
} | ||
private val fixtureMonkey = | ||
FixtureMonkey | ||
.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE) | ||
.build() | ||
|
||
@Test | ||
fun `๋ฌธ์ ํ์ดํ ์ด ๋ฌธ์ ์๋ฅผ ๊ตฌํ๋ค`() { | ||
// given | ||
val exam = createExam() | ||
val exam: Exam = | ||
fixtureMonkey | ||
.giveMeBuilder<Exam>() | ||
.sizeExp(Exam::answers, 2) | ||
.sample() | ||
|
||
// when | ||
val totalQuantity = exam.calculateTotalQuantity() | ||
|
@@ -55,42 +37,30 @@ class ExamTest { | |
|
||
@Test | ||
fun `์ํ ์์ฑ์ ์ฑ๊ณตํ๋ค`() { | ||
val workbook = createWorkbook() | ||
val member = createMember() | ||
val workbook: Workbook = fixtureMonkey.giveMeOne() | ||
val member: Member = fixtureMonkey.giveMeOne() | ||
val sequence: Int = 2 | ||
val time = 20 | ||
|
||
val exam = Exam.createExam(member, workbook, sequence, time) | ||
|
||
Assertions.assertThat(exam.workbook).isEqualTo(workbook) | ||
Assertions.assertThat(exam.member.name).isEqualTo(member.name) | ||
Assertions.assertThat(exam.sequence).isEqualTo(sequence) | ||
assertThat(exam.workbook).isEqualTo(workbook) | ||
assertThat(exam.member.name).isEqualTo(member.name) | ||
assertThat(exam.sequence).isEqualTo(sequence) | ||
} | ||
|
||
@Test | ||
fun `totalCorrect๊ฐ ์ฆ๊ฐํ๋ค`() { | ||
val exam = createExam() | ||
val count = 3 | ||
val totalCorrect = exam.totalCorrect | ||
val totalCorrect = 2 | ||
val exam = | ||
fixtureMonkey | ||
.giveMeBuilder<Exam>() | ||
.setExp(Exam::totalCorrect, totalCorrect) | ||
.sample() | ||
|
||
exam.increaseTotalCorrect(count) | ||
|
||
Assertions.assertThat(exam.totalCorrect).isEqualTo(totalCorrect + count) | ||
assertThat(exam.totalCorrect).isEqualTo(totalCorrect + count) | ||
} | ||
|
||
fun createWorkbook(): Workbook = | ||
Workbook( | ||
title = "hinc", | ||
description = null, | ||
member = createMember(), | ||
emoji = "๐", | ||
) | ||
|
||
fun createMember(): Member = | ||
Member( | ||
name = "Mayra Payne", | ||
email = "[email protected]", | ||
image = "dicant", | ||
provider = Provider.APPLE, | ||
) | ||
} |
Oops, something went wrong.