Skip to content

Commit

Permalink
Tests for all functions in the package are added.
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSpejbl committed May 5, 2019
1 parent 61e0532 commit c3d79c6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/testthat/test_correct_input_meanimpute.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("Incorrect input of meanimpute", {
#tests related to input vector
expect_error(meanimpute(NULL),"Input vector cannot be NULL.")
expect_error(meanimpute(c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)),"Input vector should contain at least one numeric element.")
expect_error(meanimpute(c(1,2,3,4,"Dracula"), "Input vector should contain at least one numeric element."))

})
8 changes: 8 additions & 0 deletions tests/testthat/test_correct_input_transform_log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("Input of transform_log() is correct.", {
#tests related to input vector
expect_error(transform_log(NULL), "Input vector is not allowed to be NULL.")
expect_error(transform_log(c(NA,NA,NA,6,NA,5,NA,NA,7,NA,NA)), "There is at least one NA value in input vector.")
expect_error(transform_log(c(1,2,3,4,5,6,7,8,"string",1000)), "There is at least one non-numeric value.")
expect_error(transform_log(c(1,2,3,4,5,6,7,8,-5)), "There is at least one negative value.")

})
10 changes: 10 additions & 0 deletions tests/testthat/test_correct_input_windsorization.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test_that("Incorrect input", {
#tests related to input vector
expect_error(windsorize(NULL, .9), "Input vector cannot be NULL.")
expect_error(windsorize(c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA), .9), "There should be no NA's in input vector.")
expect_error(windsorize(c(-1000,1,2,3,4,5,6,7,8,"string",1000), .9), "There should only numeric values in the input vector.")
expect_error(windsorize(c(-1000,1,2,3,4,6,7,8,9,1000), "string"), "Input quantile should be a number between 0 and 1.")
expect_error(windsorize(c(-1000,1,2,3,4,6,7,8,9,1000), 2), "Input quantile should be a number between 0 and 1")
expect_error(windsorize(c(-1000,1,2,3,4,6,7,8,9,1000), -2), "Input quantile should be a number between 0 and 1")

})
3 changes: 3 additions & 0 deletions tests/testthat/test_correct_result_meanimpute.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("NA's in vector are correctly replace by mean", {
expect_equal(meanimpute(c(2,4,6,NA)), c(2,4,6,4))
})
3 changes: 3 additions & 0 deletions tests/testthat/test_correct_result_transform_log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("Vector is correctly log-transformed", {
expect_equal(transform_log(c(1,1,1)), c(0,0,0))
})
3 changes: 3 additions & 0 deletions tests/testthat/test_correct_result_windsorization.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("vector is correctly windsorized", {
expect_equal(windsorize(c(-1000,1,2,3,4,5,6,7,8,9,1000),0.9), c(-499.5,1,2,3,4,5,6,7,8,9,504.5) )
})

0 comments on commit c3d79c6

Please sign in to comment.