Skip to content

ALTAPPS-1293: Shared table problem with multiple options requires answer for each row #1102

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ internal class StepQuizReplyValidator(private val resourceProvider: ResourceProv
}
BlockName.TABLE -> {
val choices = reply.choices?.safeCast<List<ChoiceAnswer.Table>>()

if (choices.isNullOrEmpty() || choices.any { it -> it.tableChoice.columns.none { it.answer } }) {
return ReplyValidationResult.Error(getErrorMessage(stepBlockName))
when {
choices.isNullOrEmpty() ->
return ReplyValidationResult.Error(getErrorMessage(stepBlockName))
dataset?.isCheckbox == true ->
return ReplyValidationResult.Success
choices.any { it -> it.tableChoice.columns.none { it.answer } } ->
return ReplyValidationResult.Error(getErrorMessage(stepBlockName))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import org.hyperskill.app.step.domain.model.BlockName
import org.hyperskill.app.step_quiz.domain.model.attempts.Dataset
import org.hyperskill.app.step_quiz.domain.validation.ReplyValidationResult
import org.hyperskill.app.step_quiz.domain.validation.StepQuizReplyValidator
import org.hyperskill.app.submissions.domain.model.Cell
import org.hyperskill.app.submissions.domain.model.ChoiceAnswer
import org.hyperskill.app.submissions.domain.model.Reply
import org.hyperskill.app.submissions.domain.model.TableChoiceAnswer
import org.hyperskill.app.step_quiz.domain.model.attempts.Pair as DatasetPair

class StepQuizReplyValidatorTest {
Expand Down Expand Up @@ -47,4 +50,94 @@ class StepQuizReplyValidatorTest {

assertTrue(result is ReplyValidationResult.Success)
}

@Test
fun `Table reply validation should return success for multiple choice table problem without all answers`() {
val dataset = Dataset(isCheckbox = true)
val reply = Reply.table(
listOf(
ChoiceAnswer.Table(
tableChoice = TableChoiceAnswer(
nameRow = "Row 1",
columns = listOf(
Cell(id = "Col 1", answer = false),
Cell(id = "Col 2", answer = false)
)
)
)
)
)

val result = validator.validate(dataset, reply, BlockName.TABLE)
assertTrue(result is ReplyValidationResult.Success)
}

@Test
fun `Table reply validation should return success for single choice table problem with all answers`() {
val dataset = Dataset(isCheckbox = false)
val reply = Reply.table(
listOf(
ChoiceAnswer.Table(
tableChoice = TableChoiceAnswer(
nameRow = "Row 1",
columns = listOf(
Cell(id = "Col 1", answer = true),
Cell(id = "Col 2", answer = false)
)
)
),
ChoiceAnswer.Table(
tableChoice = TableChoiceAnswer(
nameRow = "Row 2",
columns = listOf(
Cell(id = "Col 1", answer = false),
Cell(id = "Col 2", answer = true)
)
)
)
)
)

val result = validator.validate(dataset, reply, BlockName.TABLE)
assertTrue(result is ReplyValidationResult.Success)
}

@Test
fun `Table reply validation should return error for single choice table problem with missing answers`() {
val dataset = Dataset(isCheckbox = false)
val reply = Reply.table(
listOf(
ChoiceAnswer.Table(
tableChoice = TableChoiceAnswer(
nameRow = "Row 1",
columns = listOf(
Cell(id = "Col 1", answer = false),
Cell(id = "Col 2", answer = false)
)
)
),
ChoiceAnswer.Table(
tableChoice = TableChoiceAnswer(
nameRow = "Row 2",
columns = listOf(
Cell(id = "Col 1", answer = false),
Cell(id = "Col 2", answer = true)
)
)
)
)
)

val result = validator.validate(dataset, reply, BlockName.TABLE)
assertTrue(result is ReplyValidationResult.Error)
}

@Test
fun `Table reply validation should return error for single choice table problem with empty reply`() {
val dataset = Dataset(isCheckbox = false)
val reply = Reply(choices = emptyList())

val result = validator.validate(dataset, reply, BlockName.TABLE)
assertTrue(result is ReplyValidationResult.Error)
}
}
Loading