test_that("Testing method createOutcomeDeclaration()
for AssessmentTest class", {
mc1 <- new("MultipleChoice",
identifier = "q1", prompt = "What does 3/4 + 1/4 = ?",
title = "MultipleChoice",
choices = c("1", "4/8", "8/4", "4/4"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1))
sc2 <- new("SingleChoice",
prompt = "What is the percentage of 3/20?",
title = "SingleChoice",
choices = c("15%", "20%", "30%"),
choice_identifiers = "1",
identifier = "q2")
mc3 <- new("MultipleChoice",
identifier = "q3",
prompt = "3 + 4b = 15. What is the value of b in this equation?",
title = "MultipleChoice",
choices = c("3", "2", "5", "6/2"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1)
)
order1 <- new("Ordering",
identifier = "q4",
title = "Order",
prompt = "Choose the correct order",
choices = c("Data collection", "Data cleansing",
"Data marking", "Verification and visualization"),
choices_identifiers = c("1", "2", "3", "4"),
points = 1
)
exam_section <- new("AssessmentSection",
identifier = "sec_id",
title = "section",
assessment_item = list(mc1, sc2, mc3, order1)
)
exam <- new("AssessmentTest",
identifier = "id_test",
# exclude "title"
section = list(exam_section)
)
example <- "
0
6
0
"
expected <- paste('', toString(createOutcomeDeclaration(exam)),'')
xml1 <- xml2::read_xml(expected)
xml2 <- xml2::read_xml(example)
expect_equal(xml1, xml2)
})
test_that("Testing method createOutcomeDeclaration() with
academic_grading = TRUE for AssessmentTest class", {
mc1 <- new("MultipleChoice",
identifier = "q1", prompt = "What does 3/4 + 1/4 = ?",
title = "MultipleChoice",
choices = c("1", "4/8", "8/4", "4/4"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1))
sc2 <- new("SingleChoice",
prompt = "What is the percentage of 3/20?",
title = "SingleChoice",
choices = c("15%", "20%", "30%"),
choice_identifiers = "1",
identifier = "q2")
mc3 <- new("MultipleChoice",
identifier = "q3",
prompt = "3 + 4b = 15. What is the value of b in this equation?",
title = "MultipleChoice",
choices = c("3", "2", "5", "6/2"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1)
)
order1 <- new("Ordering",
identifier = "q4",
title = "Order",
prompt = "Choose the correct order",
choices = c("Data collection", "Data cleansing",
"Data marking", "Verification and visualization"),
choices_identifiers = c("1", "2", "3", "4"),
points = 1
)
exam_section <- new("AssessmentSection",
identifier = "sec_id",
title = "section",
assessment_item = list(mc1, sc2, mc3, order1)
)
exam <- new("AssessmentTest",
identifier = "id_test",
academic_grading = TRUE,
section = list(exam_section)
)
example <- "
0
6
0
2.99
feedback_grade_50
3.00
3.29
feedback_grade_40
3.30
3.59
feedback_grade_37
3.60
3.89
feedback_grade_33
3.90
4.19
feedback_grade_30
4.20
4.49
feedback_grade_27
4.50
4.79
feedback_grade_23
4.80
5.09
feedback_grade_20
5.10
5.39
feedback_grade_17
5.40
5.69
feedback_grade_13
5.70
feedback_grade_10
0
feedback_grade_table
Grade 5.0
\n
Grade 4.0
\n \n \n Grade 3.7
Grade 3.3
Grade 3.0
Grade 2.7
Grade 2.3
Grade 2.0
Grade 1.7
Grade 1.3
Grade 1.0
Grade |
Min |
Max |
1.0 |
5.70 |
6.00 |
1.3 |
5.40 |
5.69 |
1.7 |
5.10 |
5.39 |
2.0 |
4.80 |
5.09 |
2.3 |
4.50 |
4.79 |
2.7 |
4.20 |
4.49 |
3.0 |
3.90 |
4.19 |
3.3 |
3.60 |
3.89 |
3.7 |
3.30 |
3.59 |
4.0 |
3.00 |
3.29 |
5.0 |
0.00 |
2.99 |
"
expected <- paste('', toString(create_assessment_test(exam, "to_delete")),'')
xml1 <- xml2::read_xml(expected)
xml2 <- xml2::read_xml(example)
expect_equal(xml1, xml2)
unlink("q1.xml", recursive = TRUE)
unlink("q2.xml", recursive = TRUE)
unlink("q3.xml", recursive = TRUE)
unlink("q4.xml", recursive = TRUE)
unlink("id_test.xml", recursive = TRUE)
unlink("id_test.zip", recursive = TRUE)
unlink("imsmanifest.xml", recursive = TRUE)
unlink("to_delete", recursive = TRUE)
})
test_that("Testing method createAssessmentTest for AssessmentTestOpal class", {
sc1 <- new("SingleChoice", prompt = "Test task", title = "SC",
identifier = "q1", choices = c("a", "b", "c"))
sc2 <- new("SingleChoice", prompt = "Test task", title = "SC",
identifier = "q2", choices = c("A", "B", "C"))
sc3 <- new("SingleChoice", prompt = "Test task", title = "SC",
identifier = "q3", choices = c("aa", "bb", "cc"))
e1 <- new("Essay", prompt = "Essay task", identifier = "e1")
e2 <- new("Essay", prompt = "Essay task", identifier = "e2")
e3 <- new("Essay", prompt = "Essay task", identifier = "e3")
exam_subsection <- new("AssessmentSection", identifier = "subsec_id",
title = "Subsection", assessment_item = list(e1, e2, e3),
shuffle = TRUE, selection = 2)
exam_section <- new("AssessmentSection", identifier = "sec_id",
title = "section",
assessment_item = list(sc1, sc2, sc3, exam_subsection),
max_attempts = 3, time_limit = 30, allow_comment = TRUE)
exam <- new("AssessmentTestOpal", identifier = "id_test",
title = "some title", section = list(exam_section),
files = c(test_path("file/test_fig1.jpg"),
test_path("file/test_fig2.jpg")),
max_attempts = 5, time_limit = 100, allow_comment = TRUE,
rebuild_variables = TRUE,
show_test_time = TRUE, calculator = "simple",
keep_responses = TRUE
)
suppressMessages(createQtiTest(exam, "test1a9b56cf96", "TRUE"))
sut <- sort(list.files("test1a9b56cf96"))
expected <- sort(c("downloads", "e1.xml", "e2.xml", "e3.xml", "q1.xml", "q2.xml", "q3.xml",
"id_test.xml", "id_test.zip", "imsmanifest.xml"))
expect_equal(sut, expected)
unlink("test1a9b56cf96", recursive = TRUE)
})
test_that("Testing method createAssessmentTest for AssessmentTest class", {
sc1 <- new("SingleChoice", prompt = "Test task", title = "SC",
identifier = "q1", choices = c("a", "b", "c"))
sc2 <- new("SingleChoice", prompt = "Test task", title = "SC",
identifier = "q2", choices = c("A", "B", "C"))
sc3 <- new("SingleChoice", prompt = "Test task", title = "SC",
identifier = "q3", choices = c("aa", "bb", "cc"))
e1 <- new("Essay", prompt = "Essay task", identifier = "e1")
e2 <- new("Essay", prompt = "Essay task", identifier = "e2")
e3 <- new("Essay", prompt = "Essay task", identifier = "e3")
exam_subsection <- new("AssessmentSection", identifier = "subsec_id",
title = "Subsection",
assessment_item = list(e1, e2, e3),
shuffle = TRUE, selection = 2)
exam_section <- new("AssessmentSection", identifier = "sec_id",
title = "section",
assessment_item = list(sc1, sc2, sc3, exam_subsection),
max_attempts = 3, time_limit = 30,
allow_comment = TRUE)
exam <- new("AssessmentTest", identifier = "id_test",
title = "some title", section = list(exam_section),
max_attempts = 5, time_limit = 100, allow_comment = TRUE,
rebuild_variables = TRUE
)
# Testing AssessmentTest
suppressMessages(createQtiTest(exam, "todelete", "TRUE"))
sut <- xml2::read_xml(suppressMessages(toString(createAssessmentTest(
object = exam, folder = getwd()))))
expected <- xml2::read_xml("todelete/id_test.xml")
expect_equal(sut, expected)
file.remove("e1.xml")
file.remove("e2.xml")
file.remove("e3.xml")
file.remove("q1.xml")
file.remove("q2.xml")
file.remove("q3.xml")
unlink("todelete", recursive = TRUE)
})
test_that("Testing of AssessmentSection class that contains
non-unique identifiers of AssessmentItem class", {
mc1 <- new("MultipleChoice",
identifier = "theSame", prompt = "What does 3/4 + 1/4 = ?",
title = "MultipleChoice",
choices = c("1", "4/8", "8/4", "4/4"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1))
sc2 <- new("SingleChoice",
prompt = "What is the percentage of 3/20?",
title = "SingleChoice",
choices = c("15%", "20%", "30%"),
choice_identifiers = "1",
identifier = "theSame")
expect_error({
new("AssessmentSection",
identifier = "sec_id",
title = "section",
assessment_item = list(mc1, sc2)
)
}, "Items of section id:sec_id contain non-unique values: theSame, theSame")
})
test_that("Testing of AssessmentTest class that contains non-unique identifiers
of AssessmentSection", {
mc1 <- new("MultipleChoice",
identifier = "theSame", prompt = "What does 3/4 + 1/4 = ?",
title = "MultipleChoice",
choices = c("1", "4/8", "8/4", "4/4"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1))
sc2 <- new("SingleChoice",
prompt = "What is the percentage of 3/20?",
title = "SingleChoice",
choices = c("15%", "20%", "30%"),
choice_identifiers = "1",
identifier = "theSame")
section1 <- new("AssessmentSection",
identifier = "sec_id",
title = "section",
assessment_item = list(mc1))
section2 <- new("AssessmentSection",
identifier = "sec_id",
title = "section",
assessment_item = list(sc2))
expect_warning({ exam <- new("AssessmentTest",
identifier = "id_test",
title = "some title",
section = list(section1, section2))
}, "Identifiers of test sections contain non-unique values: sec_id, theSame, sec_id, theSame")
})
test_that("Testing of time_limits in AssessmentTest class", {
mc1 <- new("MultipleChoice",
identifier = "theSame", prompt = "What does 3/4 + 1/4 = ?",
title = "MultipleChoice",
choices = c("1", "4/8", "8/4", "4/4"),
choice_identifiers = c("1", "2", "3", "4"),
points = c(1, 0, 0, 1))
section <- new("AssessmentSection",
identifier = "sec_id",
title = "section",
assessment_item = list(mc1))
expect_warning({
exam <- new("AssessmentTest",
identifier = "id_test",
title = "some title",
time_limit = 190,
section = list(section))
}, "Value of time_limits does not seem plausible.")
})
test_that("Testing getPoints() method in case the point of Task
in XML file is not defined", {
path <- test_path("file/xml/Essay_without_Maxscore_Minscore.xml")
sut_points <- getPoints(path)
expect_equal(sut_points, 1)
})
test_that("Testing getPoints() method in case of XML file does not exist", {
path <- test_path("file/test.xml")
expect_warning({
sut_points <- suppressMessages(getPoints(path))
}, "file file/test.xml does not exist")
})
test_that("Testing getIdentifier() method in case of XML file does not exist", {
path <- test_path("file/test.xml")
expect_warning({
sut_points <- getIdentifier(path)
}, "file file/test.xml does not exist")
})
test_that("Testing a specific attribute 'files' in yaml section of Rmd file",
{
tpath <- "file/test_rmd_files"
path <- test_path("file/test_rmd_files/test_DirectedPair_from_table.Rmd")
exam_section <- suppressMessages(section(path))
fls <- exam_section@assessment_item[[1]]@files
fls <- sapply(fls, function(x) test_path(tpath, x))
exam_section@assessment_item[[1]]@files <- fls
exam <- new("AssessmentTestOpal",
identifier = "id_test",
section = list(exam_section))
expected <- c(test_path(tpath, "test_fig2.jpg"),
test_path(tpath, "test_fig1.jpg"),
test_path(tpath, "statistics.csv"))
expect_equal(exam@files, expected)
})