Skip to content

Commit

Permalink
Add expect_warning() assertion
Browse files Browse the repository at this point in the history
- Minor  tests refactor
  • Loading branch information
bahadzie committed Jun 10, 2024
1 parent 33b6e1b commit 7222d30
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions tests/testthat/test-numberize.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ test_that("translating vector of Spanish numbers works", {
expect_identical(res, test_df[["num"]])
})

test_that("translating single french text works", {
res <- numberize("mille cinq cent quinze", lang = "fr")
expect_identical(res, 1515)
})


test_that("text with non digit word returns NA", {
res <- numberize("epiverse", lang = "en")
expect_true(is.na(res))
Expand All @@ -100,32 +94,31 @@ test_that("vector with number and words and NA is properly handled", {
})

test_that("text with leading and trailing whitespace works", {
res <- numberize(" mille cinq cent quinze
", lang = "fr")
res <- numberize(" mille cinq cent quinze ", lang = "fr")
expect_identical(res, 1515)
})

test_that("text with ambigious number conversion returns NA", {
res <- numberize("twenty twenty four", lang = "fr")
test_that("warning for ambiguous conversion", {
expect_warning(res <- numberize("twenty twenty four"))
expect_true(is.na(res))
})

test_that("NA to return NA", {
res <- numberize(NA, lang = "fr")
res <- numberize(NA, lang = "es")
expect_true(is.na(res))
})

test_that("NaN to return NA", {
res <- numberize(NaN, lang = "fr")
res <- numberize(NaN, lang = "es")
expect_true(is.na(res))
})

test_that("TRUE to return NA", {
res <- numberize(TRUE, lang = "fr")
res <- numberize(TRUE, lang = "en")
expect_true(is.na(res))
})
test_that("FALSE to return NA", {
res <- numberize(FALSE, lang = "fr")
res <- numberize(FALSE, lang = "en")
expect_true(is.na(res))
})
test_that("NULL to return NA", {
Expand Down

0 comments on commit 7222d30

Please sign in to comment.