Developing R Packages
Jasmin Ludolf
Content Developer
expect_equal(temp_converter(32, "Fahrenheit", "Celsius"), 0)
expect_warning(temp_converter(-40, "Celsius", "Celsius"))
expect_error(temp_converter(300, "Kelvin", "Fahrenheit"))
library(testthat)
test_that("Conversion from F to C and C to F works", {
expect_equal(temp_converter(32, "Fahrenheit", "Celsius"), 0) expect_warning(temp_converter(-40, "Celsius", "Celsius")) expect_error(temp_converter(300, "Kelvin", "Fahrenheit")) })
library(testthat)
test_that("Conversion from F to C and C to F works", {
expect_equal(temp_converter(32, "Fahrenheit", "Celsius")), 1)
expect_warning(temp_converter(-40), "Celsius", "Fahrenheit")
expect_error(temp_converter(25))
})
X Conversion from F to C and C to F works
-- 1. Error: `temp_converter(32, "Fahrenheit", "Celsius")` not equal to 1
(@test_conversion.R:2)
--
-- 2. Error: `temp_converter(-40)` did not throw the expected warning.
(@test_conversion.R:3)
--
temp_converter(25) did not throw an error.
test_file()
library(testthat)
test_file("test-temp_conversion.R")
Conversion from F to C and C to F works
#' @examples
#' # Convert 25 degrees Celsius to Fahrenheit
#' temp_converter(25, unit_from = "Celsius", unit_to = "Fahrenheit")
#' # Convert 100 degrees Fahrenheit to Celsius
#' temp_converter(100, unit_from = "Fahrenheit", unit_to = "Celsius")
roxygenize()
generates a help file for temp_converter
in man
directory test_example("man/temp_converter.Rd")
test_file()
if you want to focus on a particular filetest_file()
on each testing file each timetest_package()
to run them all!test_package("unitConverter")
Developing R Packages