source("test_helpers.R")
mc <- new("MultipleChoice",
content = list(),
choices = c("Hydrogen","Helium","Carbon","Oxygen","Nitrogen",
"Chlorine"),
choice_identifiers = c("H","He","C","O","N","Cl"),
points = c(1,0,0,1,0,-1),
title = "title_mc",
prompt = paste0("Which of the following elements ",
"are used to form water?"))
test_that("Test createItemBody for MultipleChoice class", {
example <- '
Which of the following elements are used to form water?
Hydrogen
Helium
Carbon
Oxygen
Nitrogen
Chlorine
'
sut <- xml2::read_xml(toString(createItemBody(mc)))
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})
test_that("Test createResponseDeclaration for MultipleChoice class",{
mc <- new("MultipleChoice",
content = list(""),
choices = c("Hydrogen","Helium","Carbon","Oxygen","Nitrogen",
"Chlorine"),
choice_identifiers = c("H","He","C","O","N","Cl"),
points = c(1,0,0,1,0,-1),
title = "filename_sc",
prompt = paste0("Which of the following elements ",
"are used to form water?"))
example <- '
H
O
'
qtiXML <- toString(createResponseDeclaration(mc))
sut <- xml2::read_xml(qtiXML)
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})
test_that("Test getPoints for MultipleChoice class", {
sut <- getPoints(mc)
expect_equal(sut, 2)
})
test_that("Test createOutcomeDeclaration() for Multiple Choice",{
example <- '
0
2
0
'
responseDe <- as.character(htmltools::tag(
"additionalTag", list(createOutcomeDeclaration(mc))))
sut <- xml2::read_xml(responseDe)
expected <- xml2::read_xml(example)
equal_xml(sut, expected)
})