source("test_helpers.R")
sc <- new("SingleChoice",
content = list(paste0("
Look at the text in the picture.
",
"
")),
choices = c("You must stay with your luggage at all times.",
"Do not let someone else look after your luggage.",
"Remember your luggage when you leave."),
title = "filename_sc",
prompt = "What does it say?",
shuffle = FALSE,
choice_identifiers = c("ID_1", "ID_2", "ID_3"),
feedback = list(new("ModalFeedback", title = "common",
content = list("general feedback"))))
test_that("Test createItemBody() for SingleChoice class", {
example <- paste0("",
"Look at the text in the picture.
",
"",
"",
"What does it say?",
"",
"You must stay with your luggage at all times.",
"",
"",
"Do not let someone else look after your luggage.",
"",
"",
"Remember your luggage when you leave.",
"",
"",
"")
sut <- xml2::read_xml(toString(createItemBody(sc)))
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})
test_that("Test createResponseDeclaration()
for SingleChoice class:solution = 2", {
sc@solution <- 2
example <- paste0("",
"",
"ID_2",
"",
"")
sut <- xml2::read_xml(toString(createResponseDeclaration(sc)))
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})
test_that("Test outcomeDeclaration() for SingleChoice class", {
example <- paste0(" ",
"",
"0",
"",
"")
nodes <- createOutcomeDeclaration(sc)
sut <- xml2::read_xml(toString(nodes[[1]]))
expected <- xml2::read_xml(example)
expect_equal(sut, expected)
})
test_that("Test createItemBody() for SingleChoice class:
orientation = horizontal", {
sc@orientation <- "horizontal"
example <- paste0("",
"Look at the text in the picture.
",
"",
"",
"What does it say?",
"",
"You must stay with your luggage at all times.",
"",
"",
"Do not let someone else look after ",
"your luggage.",
"",
"",
"Remember your luggage when you leave.",
"",
"",
"")
sut <- xml2::read_xml(toString(createItemBody(sc)))
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})
test_that("Test createResponseProcessing() for SingleChoice class", {
example <- '
empty
incorrect
correct
0
modal_feedback
'
sut <- xml2::read_xml(toString(createResponseProcessing(sc)))
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})
test_that("Testing the constructor for SingleChoice class", {
sut <- singleChoice(content = list("Some content"),
choices = c("Answer_1","Answer_2","Answer_3"))
xml_sut <- create_assessment_item(sut)
expect_no_error(xml2::read_xml(as.character(xml_sut)))
expect_s4_class(sut, "SingleChoice")
})