test_that("generate_gapselect generates correct XML structure with a single answer", {
# Inputs
answer <- "Correct Answer"
a_values <- character(0) # No additional options
correct_feedback <- "Well done!"
incorrect_feedback <- "Try again!"
partially_correct_feedback <- "Almost there!"
# Expected structure
expected_structure <- paste0(
"\n1",
"\n",
"\n Well done!",
"\n",
"\n",
"\n Almost there!",
"\n",
"\n",
"\n Try again!",
"\n",
"\n",
"\n",
"\n Correct Answer",
"\n 1",
"\n"
)
# Run the function
result <- generate_gapselect(
answer = answer,
a_values = a_values,
correct_feedback = correct_feedback,
incorrect_feedback = incorrect_feedback,
partially_correct_feedback = partially_correct_feedback
)
# Check if the result matches the expected structure
expect_equal(result, expected_structure)
})
test_that("generate_gapselect generates correct XML structure with multiple options", {
# Inputs
answer <- "Correct Answer"
a_values <- c("Option 1", "Option 2", "Option 3")
correct_feedback <- "Well done!"
incorrect_feedback <- "Try again!"
partially_correct_feedback <- "Almost there!"
# Expected structure
expected_structure <- paste0(
"\n1",
"\n",
"\n Well done!",
"\n",
"\n",
"\n Almost there!",
"\n",
"\n",
"\n Try again!",
"\n",
"\n",
"\n",
"\n Correct Answer",
"\n 1",
"\n",
"\n",
"\n Option 1",
"\n 1",
"\n",
"\n",
"\n Option 2",
"\n 1",
"\n",
"\n",
"\n Option 3",
"\n 1",
"\n"
)
# Run the function
result <- generate_gapselect(
answer = answer,
a_values = a_values,
correct_feedback = correct_feedback,
incorrect_feedback = incorrect_feedback,
partially_correct_feedback = partially_correct_feedback
)
# Check if the result matches the expected structure
expect_equal(result, expected_structure)
})
test_that("generate_gapselect handles empty inputs gracefully", {
# Inputs with minimal data
answer <- ""
a_values <- character(0)
correct_feedback <- ""
incorrect_feedback <- ""
partially_correct_feedback <- ""
# Expected structure
expected_structure <- paste0(
"\n1",
"\n",
"\n ",
"\n",
"\n",
"\n ",
"\n",
"\n",
"\n ",
"\n",
"\n",
"\n",
"\n ",
"\n 1",
"\n"
)
# Run the function
result <- generate_gapselect(
answer = answer,
a_values = a_values,
correct_feedback = correct_feedback,
incorrect_feedback = incorrect_feedback,
partially_correct_feedback = partially_correct_feedback
)
# Check if the result matches the expected structure
expect_equal(result, expected_structure)
})