Skip to content

Commit

Permalink
Refactor FillBlanksItemMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderZhu committed Oct 18, 2023
1 parent 65ea64b commit df8c5a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.hyperskill.app.step_quiz_fill_blanks.presentation
import org.hyperskill.app.core.utils.DotMatchesAllRegexOption
import org.hyperskill.app.step_quiz.domain.model.attempts.Attempt
import org.hyperskill.app.step_quiz.domain.model.attempts.Component
import org.hyperskill.app.step_quiz.domain.model.attempts.Dataset
import org.hyperskill.app.step_quiz.domain.model.submissions.Reply
import org.hyperskill.app.step_quiz.domain.model.submissions.Submission
import org.hyperskill.app.step_quiz_fill_blanks.model.FillBlanksConfig
import org.hyperskill.app.step_quiz_fill_blanks.model.FillBlanksData
Expand All @@ -19,13 +21,21 @@ object FillBlanksItemMapper {

fun map(attempt: Attempt, submission: Submission): FillBlanksData? =
attempt.dataset?.components?.let {
mapInternal(
map(
componentsDataset = it,
replyBlanks = submission.reply?.blanks
)
}

internal fun mapInternal(
fun map(dataset: Dataset, reply: Reply?): FillBlanksData? =
dataset.components?.let {
map(
componentsDataset = it,
replyBlanks = reply?.blanks
)
}

private fun map(
componentsDataset: List<Component>,
replyBlanks: List<String>?
): FillBlanksData? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FillBlanksMapperTest {

@Test
fun `FillBlanksMapper should correctly split text`() {
val result = FillBlanksItemMapper.mapInternal(
val result = FillBlanksItemMapper.map(
componentsDataset = listOf(
Component(
type = Component.Type.TEXT,
Expand All @@ -59,7 +59,7 @@ class FillBlanksMapperTest {
fun `FillBlanksMapper should use reply for inputs`() {
val firstReply = "1"
val secondReply = "2"
val result = FillBlanksItemMapper.mapInternal(
val result = FillBlanksItemMapper.map(
componentsDataset = listOf(
Component(
type = Component.Type.TEXT,
Expand All @@ -82,7 +82,7 @@ class FillBlanksMapperTest {

@Test
fun `FillBlanksMapper should extract language name from the CODE tag`() {
val result = FillBlanksItemMapper.mapInternal(
val result = FillBlanksItemMapper.map(
componentsDataset = listOf(
Component(
type = Component.Type.TEXT,
Expand Down

This file was deleted.

0 comments on commit df8c5a1

Please sign in to comment.