Use the function testthat::expect_equal to check if the output of the report_p() function with different p values and the default digits value gives you the expected output. Now add another testthat::test_that block called "default values". You should see output like: Loading demopckg You can test more values than these, but we'll start with just these two.Īfter you save this file, run devtools::test(). We're going to check two expectations, that we'll get the error message "p cannot be less than 0" if p = -1, and that we'll get the error message "p cannot be greater than 1" id p = 2. The first set we're going to make checks if we get the error messages we expect, so we've called it "errors". You can create the same filename as your function name. You can now add your functions under this package. Code: devtools::create ('packagename') In the place of packagename, you can give the name you wish. The test_that function checks a groups of expectataions. After installing the package devtools, you can create your own package. The context function lets you know what function you're testing when you run all the unit tests in a package. B.2.2 Enable version control in RStudio.
0 Comments
Leave a Reply. |