test_that("Testing SingleChoice where answer is $nummer", { path <- test_path("file/md/sc_example3.md") sut <- create_question_object(path) content <- "

This is a mock question
The speed of the light in kilometers per second is:

" expected <- new("SingleChoice", content = list(content), identifier = "eco", qti_version = "v2p1", title = "Physic", choices = c("\\(299\\)", "\\(300\\)", "\\(199\\)", "\\(99\\)"), shuffle = TRUE, prompt = "", choice_identifiers = c("ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"), orientation = "vertical", solution = 2 ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for SingleChoice class", { path <- test_path("file/md/sc_example1.md") sut <- create_question_object(path) expected <- new("SingleChoice", content = list(paste0("

This is a mock question.
", "In economics it is generally ", "believed that the main ", "objective of a Public Sector ", "Financial Company ", "like Bank is to:

")), identifier = "eco", qti_version = "v2p1", title = "Economics and Physic", choices = c("Employ more and more people", "Maximize total production", "Maximize total profits", "Sell the goods at subsidized cost"), shuffle = TRUE, prompt = "", choice_identifiers = c("ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"), orientation = "vertical") expect_equal(sut, expected) }) test_that("Testing create_question_object() for SingleChoice class: solution", { path <- test_path("file/md/sc_example2.md") sut <- create_question_object(path) expected <- new("SingleChoice", content = list(paste0("

Which term is used to ", "describe the study ", "of how people make decisions", " in a world where ", "resources are limited?

")), points = 2, identifier = "sample_2", qti_version = "v2p1", title = "Economics 2", choices = c("scarcity", "decision-making modeling", "economics", "cost-benefit analysis"), shuffle = TRUE, prompt = "", choice_identifiers = c("ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"), orientation = "vertical", solution = 2 ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for MultipleChoice class: solution 1 and 2", { path <- test_path("file/md/mc_example.md") sut <- create_question_object(path) expected <- new("MultipleChoice", content = list(paste0("

When deciding between ", "renovating a water treatment plant ", "or building a new community pool, ", "what is the government most likely ", "to consider?

")), points = c(1, 2, 0, 0), identifier = "test2", qti_version = "v2p1", title = "Economics", choices = c("scarcity vs resources", "wages vs prices", "wants vs needs", "consumers vs producers"), shuffle = TRUE, prompt = "", choice_identifiers = c("ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"), orientation = "vertical" ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for MultipleChoice class: solution 1 and 3", { path <- test_path("file/md/mc_example2.md") sut <- create_question_object(path) expected <- new("MultipleChoice", content = list(paste0("

Economic systems are ways ", "that countries answer the 5 ", "fundamental questions:", "

When deciding ", "between renovating a water ", "treatment plant or building a new ", "community pool, what is the ", "government most likely to ", "consider?

")), points = c(2.5, 0, 2.5, 0), identifier = "test_2", qti_version = "v2p1", title = "Economics", choices = c("scarcity vs resources", "wants vs needs", "wages vs prices", "consumers vs producers"), shuffle = TRUE, prompt = "", choice_identifiers = c("ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"), orientation = "vertical" ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for Essay class", { path <- test_path("file/md/essay_example.md") sut <- suppressWarnings(create_question_object(path)) expected <- suppressWarnings(new("Essay", content = list( "

Defining Good Students Means More Than Just Grades.

"), points = 10, identifier = "test_2", qti_version = "v2p1", title = "Definition Essay", data_allow_paste = FALSE )) expect_equal(sut, expected) }) test_that("Testing create_question_object() for Entry class", { path <- test_path("file/md/entry_example1.md") sut <- suppressMessages(create_question_object(path)) expected <- suppressMessages(new("Entry", content = list("

Hast du ", new("TextGap", response_identifier = "response_1", solution = "ein"), " Handy?

"), points = 5, identifier = "test_2", qti_version = "v2p1", title = "Germany" )) expect_equal(sut, expected) }) test_that("Testing create_question_object() for Entry with YAML", { path <- test_path("file/md/entry_example2.md") sut <- suppressMessages(create_question_object(path)) expected <- suppressMessages(new("Entry", content = list("

Hast du ", new("TextGap", expected_length = 10, response_identifier = "response_1", solution = "Ein"), " Handy?
Wie viele Äpfel liegen auf dem Tisch? ", new("NumericGap", solution = 2, response_identifier = "response_2"), "

"), points = 5, identifier = "test_2", qti_version = "v2p1", title = "Germany" )) expect_equal(sut, expected) }) test_that("Testing create_outcome_declaration() for Entry class", { expected <- suppressMessages(new("Entry", content = list("

Hast du", new("TextGap", response_identifier = "response_1", solution = "ein"), " Handy?

"), points = 1, identifier = "test_2", title = "Germany" )) example <- " 0 1 0 0 1 0 " expected <- toString(htmltools::tag( "additionalTag", list(create_outcome_declaration_entry(expected)))) xml1 <- xml2::read_xml(expected) xml2 <- xml2::read_xml(example) expect_equal(xml1, xml2) }) test_that("Testing create_question_object() for Order task", { path <- test_path("file/md/order_example.md") sut <- create_question_object(path) expected <- new("Order", content = list(paste0("

Arrange German cities ", "in ascending order of ", "population

")), identifier = "order_example", choices = c("Berlin", "Hamburg", "Munich", "Cologne", "Düsseldorf", "Leipzig") ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for Direct Pair task", { path <- test_path("file/md/directedPair_example.md") sut <- create_question_object(path) expected <- new("DirectedPair", content = list("

Associate the cities with lands.

"), identifier = "test_direct_pair_example", rows = c("Munchen", "Chemnitz", "Dusseldorf", "Karlsruhe", "Erfurt"), rows_identifiers = c("row_1", "row_2", "row_3", "row_4","row_5"), cols = c("Bayern", "Sachsen", "NRW", "Baden-Württemberg", "Thüringen"), cols_identifiers = c("col_1", "col_2", "col_3", "col_4","col_5"), answers_identifiers = c("row_1 col_1", "row_2 col_2", "row_3 col_3", "row_4 col_4", "row_5 col_5"), answers_scores = c(1, 1, 1, 1, 0.5) ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for OnInColTable task, where as_table=T", { path <- test_path("file/md/OneInColTable_example.md") sut <- create_question_object(path) expected <- new("OneInColTable", content = list(paste0("

Choose the correct order in ", "the multiplication table

")), identifier = "test_OnInColTable_example", title = "test_OnInColTable_example", rows = c("2*3 =", "4*7 =", "12*3 =","3*9 =", "5*5 ="), rows_identifiers = c("row_1", "row_2", "row_3", "row_4", "row_5"), cols = c("6", "36", "27", "72/2", "25"), cols_identifiers = c("col_1", "col_2", "col_3", "col_4", "col_5"), answers_identifiers =c("row_1 col_1", "row_3 col_2", "row_3 col_4", "row_4 col_3", "row_5 col_5"), answers_scores = c(0.5, 1, 1, 1, 1) ) expect_equal(sut, expected) }) test_that("Testing create_question_object() with conditions: OnInColTable and as_table=F", { path <- test_path("file/rmd/DirectedPair_with_table.Rmd") sut <- suppressMessages(create_question_object(path)) expected <- new("DirectedPair", content = list("

Choose the right classes:

"), identifier = "test_DirectedPair_from_table", title = "test_DirectedPair_from_table", rows = c("Sparrow", "Bear", "Pine tree", "Airplane", "Earth"), rows_identifiers = c("row_1", "row_2", "row_3", "row_4", "row_5"), cols = c("Animal", "Plant", "Bird"), cols_identifiers = c("col_1", "col_2", "col_3"), answers_identifiers =c("row_1 col_3", "row_2 col_1", "row_3 col_2"), answers_scores = c(0.5, 1, 1) ) expect_equal(sut, expected) }) test_that("Testing create_question_object() for OneInRowTable task", { path1 <- test_path("file/md/OneInRowTable_example.md") sut1 <- create_question_object(path1) path2 <- test_path("file/rmd/OneInRowTable_example.Rmd") sut2 <- create_question_object(path2) expected <- new("OneInRowTable", content = list(paste0("

Choose the correct order in ", "the multiplication table

")), identifier = "test_OneInRowTable_example", title = "OneInRowTable", rows = c("4*9 =", "3*9 =", "5*5 =", "2*3 =", "12*3 ="), rows_identifiers = c("row_1", "row_2", "row_3", "row_4", "row_5"), cols = c("27", "36", "25", "6"), cols_identifiers = c("col_1", "col_2", "col_3", "col_4"), answers_identifiers = c("row_1 col_2", "row_2 col_1", "row_3 col_3", "row_4 col_4", "row_5 col_2"), answers_scores = c(0.5, 1, 1, 1, 1)) expect_equal(sut1, expected) expect_equal(sut2, expected) }) test_that("Testing create_question_object() for MultipleChoiceTable task", { path <- test_path("file/md/MultipleChoiceTable_example.md") sut <- create_question_object(path) expected <- new("MultipleChoiceTable", content = list(paste0("

Choose the correct order in ", "the multiplication table

")), identifier = "test_MultipleChoiceTable_example", rows = c("4*7-1 =", "3*9 =", "5*5 =", "2*3 =", "12*3 ="), rows_identifiers = c("row_1", "row_2", "row_3","row_4", "row_5"), cols = c("27", "36", "25", "6", "72/2"), cols_identifiers = c("col_1", "col_2", "col_3", "col_4", "col_5"), answers_identifiers =c("row_1 col_1", "row_2 col_1", "row_3 col_3", "row_4 col_4", "row_5 col_2", "row_5 col_5"), answers_scores = c(1, 1, 1, 1, 1, 1)) expect_equal(sut, expected) }) test_that("Testing create_question_object() for TextGap (yaml and primitive) tasks", { path <- test_path("file/rmd/Gap_primitive.Rmd") sut <- suppressMessages(create_question_object(path)) content <- paste0("

Diese Aufgabe dient zum Testen ", "verschiedener Möglichkeiten zum Erstellen von ", "Lücken

Hast du ") expected <- suppressMessages(new("Entry", identifier = "test_entry_example", title = "test_entry_example", content = list(content, new("TextGap", response_identifier = "response_1", solution = c("ein","EIN", "Ein"), expected_length = 2, case_sensitive = FALSE), ' Handy? Dieses Telefonmodell ist Nokia ', new("NumericGap", response_identifier = "response_2", expected_length = 3, solution = 3310), '. Hast du ', new("TextGap", response_identifier = "response_3", expected_length = 2, solution = "ein"), paste0(" Computer? Der beliebteste Prozessor ", "im ersten Quartal 2023 ist der Core i"), new("NumericGap", response_identifier = "response_4", expected_length = 1, solution = 5), paste0(".

neue numerische Lücke, die mit ", "der Funktion gebaut würde "), new("NumericGap", response_identifier = "response_5", solution = 8, placeholder = "die richtige Antwort ist 8", tolerance_type = "relative", expected_length = 1, tolerance = 10, include_lower_bound = FALSE), paste0("

eine texte Lücke, die mit der ", "Funktion gebaut würde "), new("TextGap", response_identifier = "response_6", solution = c("answer0", "answer1", "answer2"), points = 3, placeholder = "put answer here", expected_length = 6, case_sensitive = FALSE), paste0("

eine texte Lücke für ", "opal, die mit der Funktion ", "gebaut würde "), new("TextGapOpal", response_identifier = "response_7", solution = c("answer000", "answer111", "answer222"), points = 3, expected_length = 8, placeholder = "opal allows some tolerance rate", case_sensitive = FALSE, tolerance = 2),'

'), feedback = list(new("ModalFeedback", content = list("

general feedback

"))))) expect_equal(sut, expected) }) # Rmd file without type of attribute for InlineChoice test_that("Testing create_question_object() for InlineChoice (yaml and primitive) tasks", { path <- test_path("file/rmd/Gap_InlineChoice.Rmd") sut <- suppressMessages(create_question_object(path)) expected <- suppressMessages(new("Entry", identifier = "test_entry_example", title = "test_entry_example", content = list('

Das beliebteste Telefon der Welt ist ', new("InlineChoice", choices = c("Realme 9 Pro", "Realme GT Master Edition", "Samsung Galaxy A52"), response_identifier = "response_1"), paste0(". Das meistverkaufte ", "Telefonmodell in Deutschland ist "), new("InlineChoice", choices = c("Apple iPhone 13 Pro", "Apple iPhone 13 Pro Max", "Apple iPhone 13"), response_identifier = "response_2", solution_index = 3), paste0(".

In welchem Jahr ", "begann das iPhone auf dem ", "europäischen Markt zu ", "verkaufen?"), new("InlineChoice", response_identifier = "response_3", choices = c(2007, 2008)), '

'), feedback = list(new("WrongFeedback", content = list("

wrong feedback

")), new("CorrectFeedback", content = list("

correct feedback

")) ) )) expect_equal(sut, expected) }) test_that("Testing of incorrect Rmd file (without parameter: type) for MultipleChoice class that calls the error.", { error <- tryCatch({ sut <- create_question_object(path) }, error = function(e) e) expect_true(inherits(error, "error")) }) test_that("Testing create_question_object() for MultipleChoice class without points", { path <- test_path("file/rmd/mc_no_point.Rmd") sut <- create_question_object(path) expected <- new("MultipleChoice", content = list(paste0("

When deciding between ", "renovating a water treatment plant ", "or building a new community pool, ", "what is the government most likely ", "to consider?

")), identifier = "test_2", points = c(0.5, 0.5, 0, 0), qti_version = "v2p1", title = "Economics", choices = c("scarcity vs. resources", "wages vs. prices", "wants vs. needs", "consumers vs. producers"), shuffle = TRUE, prompt = "", choice_identifiers = c("ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"), orientation = "vertical" ) expect_equal(sut@points, expected@points) }) test_that("Testing the Order task, points are awarded for each correct answer.", { path <- test_path("file/rmd/order.Rmd") suppressMessages(rmd2xml(path, path = test_path())) xml_file_sut <- xml2::read_xml(test_path("ord.xml")) xml_file_expected <- xml2::read_xml(test_path("file/xml/Order.xml")) # Strip namespaces from the XML files xml_file_sut <- xml_ns_strip(xml_file_sut) xml_file_expected <- xml_ns_strip(xml_file_expected) # Find the 'match' and 'baseValue' tags match_sut <- xml_find_all(xml_file_sut, ".//match") bv_sut <- xml_find_all(xml_file_sut, ".//baseValue") list_bv_sut <- sum(as.numeric(xml2::xml_text(bv_sut))) match_expected <- xml_find_all(xml_file_expected, ".//match") bv_expected <- xml_find_all(xml_file_sut, ".//baseValue") list_bv_expected <- sum(as.numeric(xml2::xml_text(bv_expected))) # Copy the contents to the 'sut' and 'expected' variables sut <- as.character(match_sut) expected <- as.character(match_expected) expect_equal(sut, expected) expect_equal(list_bv_sut, list_bv_expected ) unlink(test_path("ord.xml")) }) test_that("Testing stop message for create_question_object() function in case the type of the task is not specified properly )", { error_message <- NULL path <- test_path("file/rmd/wrong_file.Rmd") tryCatch( { create_question_object(path) }, error = function(e) { error_message <<- conditionMessage(e) } ) expected_error <- ("The type of the task is not specified properly") expect_equal(error_message, expected_error) }) test_that("Testing stop message for create_question_object() function in case more than 1 option marked as the correct answer in SingleChoice object)", { error_message <- NULL path <- test_path("file/rmd/SC_wrong_marked.Rmd") tryCatch( { create_question_object(path) }, error = function(e) { error_message <<- conditionMessage(e) } ) expected_error <- ("More than 1 option marked as the correct answer") expect_equal(error_message, expected_error) }) test_that("Testing read_table() function: delete the name of cols and rows for MultipleChoiceTable", { path <- test_path("file/rmd/MultipleChoiceTable_rowid_colid_example.Rmd") sut <- create_question_object(path) expected <- new("MultipleChoiceTable", content = list("

Choose the correct order in the multiplication table

"), identifier = "test_MultipleChoice_example", title = "MultipleChoice", rows = c("row1", "row2", "row3"), rows_identifiers = c("id1", "id2", "id3"), cols = c("alfa", "beta", "gamma"), cols_identifiers = c("alf", "bet", "gmm"), answers_identifiers =c("id1 alf", "id1 gmm", "id2 bet", "id3 bet"), points = 4) expect_equal(sut, expected) }) test_that("Testing read_table() function: delete the name of cols and rows for OneInRowTable", { path <- test_path("file/rmd/OneInRowTable_rowid_colid_example.Rmd") sut <- create_question_object(path) expected <- new("OneInRowTable", content = list("

Choose the correct order in the multiplication table

"), identifier = "test_OneInRowTable_example", title = "OneInRowTable", rows = c("row1", "row2", "row3"), rows_identifiers = c("id1", "id2", "id3"), cols = c("alfa", "beta", "gamma"), cols_identifiers = c("alf", "bet", "gmm"), answers_identifiers =c("id1 alf", "id2 alf", "id3 gmm"), points = 3) expect_equal(sut, expected) }) test_that("Testing read_table() function: delete the name of cols and rows for OneInColTable", { path <- test_path("file/rmd/OneInColTable_rowid_colid_example.Rmd") sut <- create_question_object(path) expected <- new("OneInColTable", content = list("

Choose the correct order in the multiplication table

"), identifier = "test_OneInColTable_example", title = "OneInColTable", rows = c("row1", "row2", "row3"), rows_identifiers = c("id1", "id2", "id3"), cols = c("alfa", "beta", "gamma"), cols_identifiers = c("alf", "bet", "gmm"), answers_identifiers =c("id1 alf", "id1 bet", "id3 gmm"), points = 3) expect_equal(sut, expected) }) test_that("Checking rmd_checker() behavior when 'library(rqti)' is not called in the Rmd file", { path <- test_path("file/rmd/checker.Rmd") error_message <- tryCatch( rmd_checker(path), error = function(e) { conditionMessage(e) } ) expect_equal("Helper functions are found. Call 'library(rqti)' inside Rmd file.", error_message) })