From bad3c966312f9153db254293922bae6a544e5f11 Mon Sep 17 00:00:00 2001 From: "Roel M. Hogervorst" Date: Thu, 25 Apr 2024 21:44:50 +0200 Subject: [PATCH] :lipstick: style files --- R/address-provider-en_NZ.R | 1 - R/address-provider.R | 1 - R/isbn-provider.R | 2 +- R/zzz.R | 8 ++++---- tests/testthat/test-addresses.R | 32 ++++++++++++++++---------------- tests/testthat/test-company.R | 2 +- tests/testthat/test-isbn.R | 14 +++++++------- tests/testthat/test-zzz.R | 16 ++++++++-------- 8 files changed, 37 insertions(+), 39 deletions(-) diff --git a/R/address-provider-en_NZ.R b/R/address-provider-en_NZ.R index 313854d..6fa4989 100644 --- a/R/address-provider-en_NZ.R +++ b/R/address-provider-en_NZ.R @@ -35,7 +35,6 @@ 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$street_suffixes), diff --git a/R/address-provider.R b/R/address-provider.R index a11f24e..0d07f43 100644 --- a/R/address-provider.R +++ b/R/address-provider.R @@ -52,4 +52,3 @@ AddressProvider <- R6::R6Class( provider_ = "AddressProvider" ) ) - diff --git a/R/isbn-provider.R b/R/isbn-provider.R index b84894f..78a3151 100644 --- a/R/isbn-provider.R +++ b/R/isbn-provider.R @@ -67,7 +67,7 @@ ISBNProvider <- R6::R6Class( isbn }, generate_isbn13_checkdigit = function(first12isbn) { - # first12isbn should be a vector of 12 long. + # first12isbn should be a vector of 12 long. first_12 <- as.integer(first12isbn) if (length(first_12) != 12) { stop("needs exactly 12 tokens") diff --git a/R/zzz.R b/R/zzz.R index 22ade1a..ae57a94 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -120,11 +120,11 @@ locale_mismatch <- function(parent_provider, child_provider) { } #' generalized util function for sequence multiplication -#' +#' #' Util function for ISBN, ean, SSN providers. #' for cases such as sum(x[4]*5 + x[3]*4 + x[2]*3 + x[1] *2) #' @keywords internal -checksum_util = function(vector,multiplicationvector){ - stopifnot(length(vector)==length(multiplicationvector)) - sum(vector * multiplicationvector) +checksum_util <- function(vector, multiplicationvector) { + stopifnot(length(vector) == length(multiplicationvector)) + sum(vector * multiplicationvector) } diff --git a/tests/testthat/test-addresses.R b/tests/testthat/test-addresses.R index 33b3379..a75e6c5 100644 --- a/tests/testthat/test-addresses.R +++ b/tests/testthat/test-addresses.R @@ -28,13 +28,13 @@ 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() == "",label = sprintf("city - %s", locale)) + 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() == "",label = sprintf("city - %s", locale)) + 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() == "",label = sprintf("city - %s", locale)) + expect_false(bb$street_name() == "", label = sprintf("city - %s", locale)) expect_is(bb$postcode, "function") expect_type(bb$postcode(), "character") expect_false(bb$postcode() == "", label = sprintf("postcode - %s", locale)) @@ -75,18 +75,18 @@ test_that("custom functions from AddressProvider_nl_NL work", { 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)) - } +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)) } + } }) diff --git a/tests/testthat/test-company.R b/tests/testthat/test-company.R index a70f01e..45007e4 100644 --- a/tests/testthat/test-company.R +++ b/tests/testthat/test-company.R @@ -45,7 +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_false(aa$company() == "", label = sprintf("company - %s", loc)) expect_type(aa$company, "closure") } }) diff --git a/tests/testthat/test-isbn.R b/tests/testthat/test-isbn.R index ff9f9c7..17a0d8a 100644 --- a/tests/testthat/test-isbn.R +++ b/tests/testthat/test-isbn.R @@ -3,7 +3,7 @@ test_that("ISBN 13 creates valid ISBN", { # ISBN version 13 # 978-0-306-40615-? 7 # LOW LEVEL CHECKDIGIT - expect_equal(ISBNP$.__enclos_env__$private$generate_isbn13_checkdigit(c(9,7,8,0,3,0,6,4,0,6,1,5)), 7) + expect_equal(ISBNP$.__enclos_env__$private$generate_isbn13_checkdigit(c(9, 7, 8, 0, 3, 0, 6, 4, 0, 6, 1, 5)), 7) # UNDERLYING GENERATOR expect_equal(nchar(ISBNP$.__enclos_env__$private$generate_isbn13()), 13) # USER FACING FUNCTION @@ -17,12 +17,12 @@ test_that("ISBN 10 creates valid ISBN", { # LOW LEVEL CHECKDIGIT # 0575055030 men at arms - expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0,5,7,5,0,5,5,0,3)), "0") + expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0, 5, 7, 5, 0, 5, 5, 0, 3)), "0") # 038553826X raising steam - expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0,3,8,5,5,3,8,2,6)), "X") - # 0062429981 The Shepherd's Crown - expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0,0,6,2,4,2,9,9,8)), "1") - + expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0, 3, 8, 5, 5, 3, 8, 2, 6)), "X") + # 0062429981 The Shepherd's Crown + expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0, 0, 6, 2, 4, 2, 9, 9, 8)), "1") + ## optional extra checks # # 0192854259 good omens # expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0,1,9,2,8,5,4,2,5)), "9") @@ -32,7 +32,7 @@ test_that("ISBN 10 creates valid ISBN", { # expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0,5,5,2,1,4,2,3,5)), "2") # # 0552134635 moving pictures # expect_equal(ISBNP$.__enclos_env__$private$generate_isbn10_checkdigit(c(0,5,5,2,1,3,4,6,3)), "5") - + # UNDERLYING GENERATOR expect_equal(nchar(ISBNP$.__enclos_env__$private$generate_isbn10()), 10) # USER FACING FUNCTION diff --git a/tests/testthat/test-zzz.R b/tests/testthat/test-zzz.R index 7e13969..b4cce96 100644 --- a/tests/testthat/test-zzz.R +++ b/tests/testthat/test-zzz.R @@ -74,12 +74,12 @@ test_that("All non-localized providers inherit from BareProvider", { }) -test_that("checksum_util works for our usecases",{ - # ISBN 10 - expect_equal(checksum_util(c(0,3,0,6,4,0,6,1,5),10:2), 130) - # ISBN 13 - expect_equal(checksum_util(c(9,7,8,0,3,0,6,4,0,6,1,5),rep(c(1,3),6)), 93) - #SSN dutch - #111222333 en 123456782 - expect_equal(checksum_util(c(1,1,1,2,2,2,3,3),9:2), 69) +test_that("checksum_util works for our usecases", { + # ISBN 10 + expect_equal(checksum_util(c(0, 3, 0, 6, 4, 0, 6, 1, 5), 10:2), 130) + # ISBN 13 + expect_equal(checksum_util(c(9, 7, 8, 0, 3, 0, 6, 4, 0, 6, 1, 5), rep(c(1, 3), 6)), 93) + # SSN dutch + # 111222333 en 123456782 + expect_equal(checksum_util(c(1, 1, 1, 2, 2, 2, 3, 3), 9:2), 69) })