Skip to content

Commit

Permalink
all tests passing; closes #11, closes #13, closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
thegargiulian committed Aug 16, 2023
1 parent d7d049d commit 8bf2329
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
16 changes: 6 additions & 10 deletions R/utils_authentication.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ build_path <- function(replicates_dir, violation, replicate_nums) {

rep_lista <- tibble::tibble(full_path = path, matches) %>%
dplyr::mutate(rep_number = as.integer(rep_number)) %>%
dplyr::filter(violation == violation & rep_number %in% replicate_nums) %>%
purrr::pluck("full_path")
dplyr::filter(violation == violation & rep_number %in% replicate_nums)

} else {

Expand All @@ -237,20 +236,17 @@ build_path <- function(replicates_dir, violation, replicate_nums) {

rep_lista <- tibble::tibble(full_path = path, matches) %>%
dplyr::mutate(rep_number = as.integer(rep_number)) %>%
dplyr::filter(violation == violation & rep_number %in% replicate_nums) %>%
purrr::pluck("full_path")
dplyr::filter(violation == violation & rep_number %in% replicate_nums)
}

check_paths <- file.exists(rep_lista)
if (nrow(rep_lista) < length(replicate_nums)) {

if (any(!check_paths)) {

paste("replicates_dir missing replicates:", rep_lista[!check_paths], collapse = ",", recycle0 = TRUE)
stop(glue::glue("replicates_dir missing replicates:\n{paste0(rep_lista[!check_paths], collapse = '\n')}"))
missing_reps <- setdiff(replicate_nums, rep_lista$rep_number)
stop(glue::glue("replicates_dir missing replicates:\n{paste0(missing_reps, collapse = '\n')}"))

}

return(rep_lista)
return(rep_lista %>% purrr::pluck("full_path"))
}

else {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-combine_replicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ testthat::test_that("The function should run if more than two decimal places are
proportions_table <- proportions_imputed(tab_combine,
strata_vars = "sexo",
digits = 3))

testthat::expect_error(
proportions_table <- proportions_imputed(tab_combine,
strata_vars = "sexo",
Expand Down
34 changes: 20 additions & 14 deletions tests/testthat/test-confirm_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,45 @@ testthat::test_that("Hashing wrong files", {
})

testthat::test_that("Function should return an error if the violation type is incorrect", {

testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, 2)))

})

testthat::test_that("Expect message when number of replicates exceed available replicates", {

testthat::expect_error(confirm_files(right_dir, "reclutamiento", 90:110))

})

testthat::test_that("Expect message when first replicate is less than 1", {

testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:2))

})

testthat::test_that("Expect message when first replicate is less than 1 and last is more than 100", {

testthat::expect_error(confirm_files(right_dir, "reclutamiento", 0:101))

})

testthat::test_that("Function should return an error if the first_rep argument dos not have the correct format", {
testthat::test_that("Function should return an error if replicate numbers are misspecified", {

testthat::expect_error(confirm_files(right_dir, "reclutamiento", c("1", 2)))

})

testthat::test_that("Function should return an error if the last_rep argument dos not have the correct format", {
testthat::test_that("Function should return an error if replicate numbers are misspecified", {

testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, "dos")))


})

testthat::test_that("Function should return an error if one or more of the replicates is not in the directory, but within the plausible bounds", {

testthat::expect_error(confirm_files(right_dir, "reclutamiento", 1:10))

})

# --- Done
2 changes: 1 addition & 1 deletion tests/testthat/test-estimate_mse.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ testthat::test_that("mse function returns correct results for estimable and non-


testthat::test_that("mse function returns correct results when using lookup functionality", {

local_dir <- system.file("extdata", "right", package = "verdata")
replicates <- read_replicates(local_dir, "reclutamiento", 1, 1)

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-lookup_estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ testthat::test_that("Lookup non existing estimates", {


testthat::test_that("Return error if the stratum cantains values different ti 0 and 1", {

testthat::expect_error(lookup_estimates(wrong_stratum, estimates_dir))

})

testthat::test_that("Return error if the data frame includes columns different to `in_`", {

testthat::expect_error(lookup_estimates(bad_columns, estimates_dir))

})

testthat::test_that("Return warning if the estimates directory does not have all files", {

testthat::expect_warning(lookup_estimates(my_stratum, estimates_dir))

})

# --- Done
31 changes: 18 additions & 13 deletions tests/testthat/test-read_replicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,44 @@ testthat::test_that("Hashing content of wrong with crash set to F", {
})

testthat::test_that("Function should return an error if the violation type is incorrect", {

testthat::expect_error(read_replicates(right_dir, "desplazamiento", c(1, 2)))

})

testthat::test_that("Expect message when number of replicates exceed available replicates", {

testthat::expect_error(read_replicates(right_dir, "reclutamiento", 90:110))

})

testthat::test_that("Expect message when first replicate is less than 1", {

testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:2))

})

testthat::test_that("Expect message when first replicate is less than 1 and last is more than 100", {

testthat::expect_error(read_replicates(right_dir, "reclutamiento", 0:101))
})

testthat::test_that("Function should return an error if the first_rep argument dos not have the correct format", {
testthat::test_that("Function should return an error if replicate numbers are misspecified", {

testthat::expect_error(read_replicates(right_dir, "reclutamiento", c("1", 2)))

})

testthat::test_that("Function should return an error if the last_rep argument dos not have the correct format", {
testthat::test_that("Function should return an error if replicate numbers are misspecified", {

testthat::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", c(1, "dos")))

})

testthat::test_that("Function should return an error if one or more of the replicates is not in the directory, but within the plausible bounds", {

testthat::expect_error(read_replicates(right_dir, "reclutamiento", 1:10))

})

# --- Done
2 changes: 1 addition & 1 deletion tests/testthat/test-summary-observed.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ testthat::test_that("Confirm sum = 1 in observed and output has desired structur
forced_dis_filter = FALSE,
edad_minors_filter = TRUE,
include_props = TRUE)

testthat::has_names(c("etnia", "observed", "obs_prop_no", "obs_prop"))
testthat::expect_equal(sum(tab_observed$obs_prop_na), 1)

Expand Down

0 comments on commit 8bf2329

Please sign in to comment.