Skip to content

Commit

Permalink
Add test for mdca to cover count input data and complete/long output
Browse files Browse the repository at this point in the history
  • Loading branch information
gederajeg committed Sep 27, 2018
1 parent 8764431 commit aa7b753
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/testthat/test-mdca.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,29 @@ test_that("`assocstr` when `n` is greater than `exp` is greater than 0 or positi
expect_gt(attracted[i], 0)
}
})

df_count <- dplyr::count(happyr::phd_data_metaphor, synonyms, metaphors, sort = TRUE)
mdca_res_count <- mdca(df_count, already_count_table = TRUE)
mdca_res_raw <- mdca(df = phd_data_metaphor, already_count_table = FALSE)
testthat::test_that("`mdca()` returns the same output of rows/cases when the input is raw or already co-occurrence table, and equal results", {

testthat::expect_equal(nrow(mdca_res_count), nrow(mdca_res_raw))
testthat::expect_equal(subset(mdca_res_raw, synonyms=="kebahagiaan" & assocstr >= 2)[["assocstr"]][1], subset(mdca_res_count, synonyms=="kebahagiaan" & assocstr >= 2)[["assocstr"]][1])
testthat::expect_equal(subset(mdca_res_raw, synonyms=="kegembiraan" & assocstr >= 2)[["p_binomial"]][1], subset(mdca_res_count, synonyms=="kegembiraan" & assocstr >= 2)[["p_binomial"]][1])

})

mdca_res_long <- mdca(df = phd_data_metaphor, concise_output = FALSE)
mdca_res_short <- mdca(df = phd_data_metaphor, concise_output = TRUE)
testthat::test_that("`mdca()` produces more column when concise = FALSE than when concise = TRUE", {
testthat::expect_true(ncol(mdca_res_long) > ncol(mdca_res_short))
})


colnames_long <- colnames(mdca_res_long)
colnames_long_rgx <- paste("(", paste(colnames(mdca_res_long), collapse = "|"), ")", sep = "")
testthat::test_that("the output columns when concise = FALSE are correctly printed/matched", {

testthat::expect_true(all(stringr::str_detect(colnames_long, colnames_long_rgx)))

})

0 comments on commit aa7b753

Please sign in to comment.