Skip to content

Commit

Permalink
all existing checks pass
Browse files Browse the repository at this point in the history
  • Loading branch information
thegargiulian committed Aug 16, 2023
1 parent 0583bdc commit d7d049d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 46 deletions.
10 changes: 4 additions & 6 deletions R/read_replicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
#' @param replicate_path Path to the replicate. The name of the file must include
#' the violation in Spanish and lower case letters (homicidio, secuestro,
#' reclutamiento, desaparicion).
#' @param crash A parameter to define whether the function should crash if the file
#' is not identical to the one published. If crash = TRUE (default), the data won't
#' be loaded. If crash = FALSE, the data will be loaded with a warning.
#'
#' @return A data frame with the data from the indicated replicate.
#' @return A data frame with the data from the indicated replicate and a column
#' `match` indicating whether the file hash matches the expected hash.
#'
#' @importFrom dplyr %>%
#'
Expand All @@ -27,7 +25,7 @@
#' read_replicate(local_dir)
#'
#' @noRd
read_replicate <- function(replicate_path, crash = TRUE) {
read_replicate <- function(replicate_path) {

violacion <- stringr::str_extract(pattern = "homicidio|desaparicion|secuestro|reclutamiento",
replicate_path)
Expand Down Expand Up @@ -121,7 +119,7 @@ read_replicates <- function(replicates_dir, violation, replicate_nums,
crash = TRUE) {

files <- build_path(replicates_dir, violation, replicate_nums)
replicate_data <- purrr::map_dfr(files, read_replicate, crash)
replicate_data <- purrr::map_dfr(files, read_replicate)

corrupted_replicates <- replicate_data %>%
dplyr::filter(!match) %>%
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 @@ -6,7 +6,7 @@

local_dir <- system.file("extdata", "right", package = "verdata")

replicates_data <- read_replicates(local_dir, "reclutamiento", 1, 2)
replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2))

replicates_data_filter <- filter_standard_cev(replicates_data,
"reclutamiento",
Expand Down
25 changes: 11 additions & 14 deletions tests/testthat/test-confirm_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ csv_right <- system.file("extdata", "right", package = "verdata", "verdata-reclu

testthat::test_that("Hashing file", {

testthat::expect_message(confirm_file(right_dir), "You have the right file!")
testthat::expect_true(confirm_file(right_dir)$confirmed)

})

testthat::test_that("Hashing wrong file", {

testthat::expect_error(confirm_file(wrong_dir))
testthat::expect_false(confirm_file(wrong_dir)$confirmed)

})

testthat::test_that("Hashing right csv file", {

testthat::expect_message(confirm_file(csv_right), "You have the right file!")
testthat::expect_true(confirm_file(csv_right)$confirmed)

})

Expand All @@ -31,52 +31,49 @@ wrong_dir <- system.file("extdata", "wrong", package = "verdata")

testthat::test_that("Hashing files", {

testthat::expect_message(confirm_files(right_dir, "reclutamiento", 1, 2), "You have the right file!")
testthat::expect_true(all(confirm_files(right_dir, "reclutamiento", c(1, 2))$confirmed))

})

testthat::test_that("Hashing wrong files", {

testthat::expect_error(confirm_files(wrong_dir, "reclutamiento", 1, 2))
testthat::expect_false(all(confirm_files(wrong_dir, "reclutamiento", c(1, 2))$confirmed))

})

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

testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", 1, 2))
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_message(confirm_files(right_dir, "reclutamiento", 90, 110),
"There are only 100 replicates available. Authenticated replicates 90 to 100")
testthat::expect_error(confirm_files(right_dir, "reclutamiento", 90:110))

})

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

testthat::expect_message(confirm_files(right_dir, "reclutamiento", 0, 2),
"First replicate available is replicate 1. Authenticated replicates 1 to 2")
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_message(confirm_files(right_dir, "reclutamiento", 0, 101),
"Replicates available go from 1 to 100. Authenticated replicates 1 to 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::expect_error(confirm_files(right_dir, "reclutamiento", "1", 2))
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::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", 1, "dos"))
testthat::expect_error(confirm_files(right_dir, "RECLUTAMIENTO", c(1, "dos")))

})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-filter_standard_cev.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

local_dir <- system.file("extdata", "right", package = "verdata")

replicates_data <- read_replicates(local_dir, "reclutamiento", 1, 2)
replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2))

expected <- filter_standard_cev(replicates_data,
"reclutamiento",
Expand Down
37 changes: 14 additions & 23 deletions tests/testthat/test-read_replicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@ csv_right <- system.file("extdata", "right", package = "verdata", "verdata-reclu

testthat::test_that("Hashing content", {

testthat::expect_true(all(read_replicate(right_dir)$match))
testthat::expect_s3_class(read_replicate(right_dir), "data.frame")

})

testthat::test_that("Hashing csv content", {

testthat::expect_s3_class(read_replicate(csv_right), "data.frame")
testthat::expect_true(all(read_replicate(csv_right)$match))

})

testthat::test_that("Hashing wrong content with default crash", {

testthat::expect_error(read_replicate(wrong_dir))

})

testthat::test_that("Hashing wrong content with crash set to F", {

testthat::expect_s3_class(read_replicate(wrong_dir, FALSE),
"data.frame")
testthat::expect_warning(read_replicate(wrong_dir, FALSE), "The content of the files is not identical to the ones published.
The results of the analysis may be inconsistent.")
testthat::expect_s3_class(read_replicate(wrong_dir), "data.frame")
testthat::expect_false(all(read_replicate(wrong_dir)$match))

})

Expand All @@ -40,57 +34,54 @@ wrong_dir <- system.file("extdata", "wrong", package = "verdata")

testthat::test_that("Hashing content of files", {

testthat::expect_s3_class(read_replicates(right_dir, "reclutamiento", 1, 2), "data.frame")
testthat::expect_s3_class(read_replicates(right_dir, "reclutamiento", c(1, 2)), "data.frame")

})

testthat::test_that("Hashing content of wrong files with default crash", {

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

})

testthat::test_that("Hashing content of wrong with crash set to F", {
testthat::expect_warning(read_replicates(wrong_dir, "reclutamiento", 1, 2, FALSE))
testthat::expect_s3_class(read_replicates(wrong_dir, "reclutamiento", 1, 2, FALSE), "data.frame")
testthat::expect_warning(read_replicates(wrong_dir, "reclutamiento", c(1, 2), FALSE))
testthat::expect_s3_class(read_replicates(wrong_dir, "reclutamiento", c(1, 2), FALSE), "data.frame")

})

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

testthat::expect_error(read_replicates(right_dir, "desplazamiento", 1, 2))
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_message(read_replicates(right_dir, "reclutamiento", 90, 110),
"There are only 100 replicates available. Authenticated and loaded replicates 90 to 100")
testthat::expect_error(read_replicates(right_dir, "reclutamiento", 90:110))

})

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

testthat::expect_message(read_replicates(right_dir, "reclutamiento", 0, 2),
"First replicate available is replicate 1. Authenticated and loaded replicates 1 to 2")
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_message(read_replicates(right_dir, "reclutamiento", 0, 101),
"Replicates available go from 1 to 100. Authenticated and loaded replicates 1 to 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::expect_error(read_replicates(right_dir, "reclutamiento", "1", 2))
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::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", 1, "dos"))
testthat::expect_error(read_replicates(right_dir, "RECLUTAMIENTO", c(1, "dos")))

})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-summary-observed.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
local_dir <- system.file("extdata", "right", package = "verdata")

replicates_data <- read_replicates(local_dir, "reclutamiento", 1, 2)
replicates_data <- read_replicates(local_dir, "reclutamiento", c(1, 2))

replicates_data_filter <- filter_standard_cev(replicates_data,
"reclutamiento",
Expand Down

0 comments on commit d7d049d

Please sign in to comment.