Skip to content

Commit

Permalink
Add tests for warn_missing with revalue and mapvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored and wibeasley committed Jan 3, 2014
1 parent d1858cd commit 4712104
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Depends:
R (>= 2.11.0)
Suggests:
abind,
testthat (>= 0.2),
testthat (>= 0.7.1.99),
tcltk,
foreach,
doMC,
Expand Down
17 changes: 17 additions & 0 deletions inst/tests/test-revalue.r
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,20 @@ test_that("revalue and mapvalues accept empty vectors and NULL", {
expect_identical(revalue(NULL, c("3"=30), warn_missing=FALSE), NULL)
expect_identical(mapvalues(NULL, 3, 30, warn_missing=FALSE), NULL)
})

test_that("revalue and mapvalues respect warn_missing", {
# revalue
expect_that(revalue("a", c("a"="A")), not(shows_message()))
expect_that(revalue("a", c("b"="B"), warn_missing=TRUE), shows_message())
expect_that(revalue("a", c("b"="B"), warn_missing=FALSE), not(shows_message()))

# mapvalues
expect_that(mapvalues("a", "a", "A"), not(shows_message()))
expect_that(mapvalues("a", "b", "B", warn_missing=TRUE), shows_message())
expect_that(mapvalues("a", "b", "B", warn_missing=FALSE), not(shows_message()))

# mapvalues with factors
expect_that(mapvalues(factor("a"), "a", "A"), not(shows_message()))
expect_that(mapvalues(factor("a"), "b", "B", warn_missing=TRUE), shows_message())
expect_that(mapvalues(factor("a"), "b", "B", warn_missing=FALSE), not(shows_message()))
})

0 comments on commit 4712104

Please sign in to comment.