Skip to content

Commit

Permalink
make test more informative
Browse files Browse the repository at this point in the history
add labels

Add stresstest for addresses

fix bug
  • Loading branch information
RMHogervorst committed Oct 21, 2023
1 parent 4f9f587 commit 99cda9f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
11 changes: 6 additions & 5 deletions R/address-provider-en_NZ.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ AddressProvider_en_NZ <- R6::R6Class(
pattern <- super$random_element(private$city_formats)
dat <- list(
# , , te_reo_first, te_reo_ending, te_reo_part

first_name = private$pp$first_name(),
last_name = private$pp$last_name(),
city_suffix = super$random_element(private$city_suffix),
city_prefix = super$random_element(private$city_prefix),
city_suffix = super$random_element(private$street_suffixes),
city_prefix = super$random_element(private$city_prefixes),
te_reo_first = super$random_element(private$te_reo_first),
te_reo_ending = super$random_element(private$te_reo_ending),
te_reo_part = super$random_element(private$te_reo_part)
te_reo_part = super$random_element(private$te_reo_parts)
)
whisker::whisker.render(pattern, data = dat)
},
Expand All @@ -54,7 +55,7 @@ AddressProvider_en_NZ <- R6::R6Class(
street_suffix = super$random_element(private$street_suffixes),
te_reo_first = super$random_element(private$te_reo_first),
te_reo_ending = super$random_element(private$te_reo_ending),
re_reo_part = super$random_element(private$re_reo_part)
re_reo_part = super$random_element(private$re_reo_parts)
)
whisker::whisker.render(pattern, data = dat)
},
Expand Down Expand Up @@ -147,7 +148,7 @@ AddressProvider_en_NZ <- R6::R6Class(
),

# Māori nouns commonly present in placenames.
te_reo_parts = c(
te_reo_part = c(
"ara",
"awa",
"horo",
Expand Down
1 change: 1 addition & 0 deletions R/address-provider.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ AddressProvider <- R6::R6Class(
provider_ = "AddressProvider"
)
)

25 changes: 21 additions & 4 deletions tests/testthat/test-addresses.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ test_that("every_locale has the same basic functions", {
expect_false(bb$address() == "")
expect_is(bb$city, "function")
expect_type(bb$city(), "character")
expect_false(bb$city() == "")
expect_false(bb$city() == "",label = sprintf("city - %s", locale))
expect_is(bb$street_address, "function")
expect_type(bb$street_address(), "character")
expect_false(bb$street_address() == "")
expect_false(bb$street_address() == "",label = sprintf("city - %s", locale))
expect_is(bb$street_name, "function")
expect_type(bb$street_name(), "character")
expect_false(bb$street_name() == "")
expect_false(bb$street_name() == "",label = sprintf("city - %s", locale))
expect_is(bb$postcode, "function")
expect_type(bb$postcode(), "character")
expect_false(bb$postcode() == "")
expect_false(bb$postcode() == "", label = sprintf("postcode - %s", locale))
# locale should match locale
expect_equal(bb$locale, locale)
}
})


# For every specific locale, test custom functions you create
test_that("custom functions from AddressProvider_en_US work", {
aa <- cr_loc_spec_provider("AddressProvider", "en_US")
Expand Down Expand Up @@ -73,3 +74,19 @@ test_that("custom functions from AddressProvider_nl_NL work", {
expect_equal(length(aa$province()), 1)
expect_true(aa$province() %in% aa$.__enclos_env__$private$provinces)
})

test_that("all locales consistently give results -- stresstest",{
skip_on_cran()
skip_on_ci()

aa <- cr_loc_spec_provider("AddressProvider", "en_US")
for (locale in aa$allowed_locales()) {
bb <- cr_loc_spec_provider("AddressProvider", locale)
for (i in 1:50){
expect_false(bb$city() == "",label = sprintf("city - %s", locale))
expect_false(bb$street_address() == "",label = sprintf("city - %s", locale))
expect_false(bb$street_name() == "",label = sprintf("city - %s", locale))
expect_false(bb$postcode() == "", label = sprintf("postcode - %s", locale))
}
}
})
1 change: 1 addition & 0 deletions tests/testthat/test-company.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test_that("all locales have `company()` function", {
for (loc in CompanyProvider_en_US$new()$allowed_locales()) {
aa <- cr_loc_spec_provider("CompanyProvider", locale = loc)
expect_gt(nchar(aa$company()), 0)
expect_false(aa$company() == "",label = sprintf("company - %s", loc))
expect_type(aa$company, "closure")
}
})
Expand Down

0 comments on commit 99cda9f

Please sign in to comment.