Skip to content

Commit

Permalink
some geocode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Dec 19, 2024
1 parent e6b9ac3 commit 03d92c3
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/testthat/test-geocode.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
data_path <- system.file("extdata/sample_1.csv", package = "geocodebr")
input_df <- read.csv(data_path)

fields <- setup_address_fields(
logradouro = "nm_logradouro",
numero = "Numero",
cep = "Cep",
bairro = "Bairro",
municipio = "nm_municipio",
estado = "nm_uf"
)

tester <- function(addresses_table = input_df,
address_fields = fields,
n_cores = 1,
progress = TRUE,
cache = TRUE) {
geocode(addresses_table, address_fields, n_cores, progress, cache)
}

test_that("errors with incorrect input", {
expect_error(tester(unclass(input_df)))

expect_error(tester(address_fields = 1))
expect_error(tester(address_fields = c(hehe = "nm_logradouro")))
expect_error(tester(address_fields = c(logradouro = "hehe")))

expect_error(tester(n_cores = "a"))
expect_error(tester(n_cores = 0))
expect_error(tester(n_cores = Inf))

expect_error(tester(progress = 1))
expect_error(tester(progress = NA))
expect_error(tester(progress = c(TRUE, TRUE)))

expect_error(tester(cache = 1))
expect_error(tester(cache = NA))
expect_error(tester(cache = c(TRUE, TRUE)))
})

0 comments on commit 03d92c3

Please sign in to comment.