-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed examples for non exported functions for CRAN + more tests
- Loading branch information
Showing
11 changed files
with
217 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
test_that("bsummary errors if invalid input", { | ||
expect_error(bsummary(letters[1:5])) | ||
}) | ||
|
||
test_that("bsummary works", { | ||
x <- bsummary(1:100) | ||
|
||
## check types | ||
expect_s3_class(x, "data.table") | ||
expect_type(x$M, "double") | ||
expect_type(x$Mdn, "double") | ||
expect_type(x$LL, "double") | ||
expect_type(x$UL, "double") | ||
expect_type(x$PercentROPE, "double") | ||
expect_type(x$PercentMID, "double") | ||
expect_type(x$CI, "double") | ||
expect_type(x$CIType, "character") | ||
expect_type(x$ROPE, "character") | ||
expect_type(x$MID, "character") | ||
|
||
## check values | ||
expect_equal(x$M, 50.5) | ||
expect_equal(x$Mdn, 50.5) | ||
expect_equal(x$LL, 1) | ||
expect_equal(x$UL, 100) | ||
expect_equal(x$PercentROPE, NA_real_) | ||
expect_equal(x$PercentMID, NA_real_) | ||
expect_equal(x$CI, 0.99) | ||
expect_equal(x$CIType, "HDI") | ||
expect_equal(x$ROPE, NA_character_) | ||
expect_equal(x$MID, NA_character_) | ||
}) | ||
|
||
test_that("bsummary works with ROPEs and MIDs", { | ||
x <- bsummary((-50:60) / 100, ROPE = c(-.5, .5), MID = c(-1, 1)) | ||
|
||
## check types | ||
expect_s3_class(x, "data.table") | ||
expect_type(x$M, "double") | ||
expect_type(x$Mdn, "double") | ||
expect_type(x$LL, "double") | ||
expect_type(x$UL, "double") | ||
expect_type(x$PercentROPE, "double") | ||
expect_type(x$PercentMID, "double") | ||
expect_type(x$CI, "double") | ||
expect_type(x$CIType, "character") | ||
expect_type(x$ROPE, "character") | ||
expect_type(x$MID, "character") | ||
|
||
## check values | ||
expect_equal(x$M, 0.05) | ||
expect_equal(x$Mdn, 0.05) | ||
expect_true(x$PercentROPE > 50) | ||
expect_equal(x$PercentMID, 0) | ||
expect_equal(x$CI, 0.99) | ||
expect_equal(x$CIType, "HDI") | ||
expect_equal(x$ROPE, "[-0.5, 0.5]") | ||
expect_equal(x$MID, "[-Inf, -1] | [1, Inf]") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test_that(".namesL creates proper names that can be converted to a matrix", { | ||
expect_equal( | ||
brmsmargins:::.namesL(1, 1), | ||
"L_1[1,1]") | ||
|
||
expect_equal( | ||
dim(brmsmargins:::tab2matR( | ||
matrix(brmsmargins:::.namesL(1, 3), 1))), | ||
c(3L, 3L)) | ||
}) | ||
|
||
test_that(".namesZ creates proper names", { | ||
expect_equal( | ||
brmsmargins:::.namesZ(1, 3, NULL), | ||
c("Z_1_1", "Z_1_2", "Z_1_3")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test_that(".checktab returns a non zero character string if invalid input", { | ||
x <- brmsmargins:::.checktab(1:5) | ||
expect_type(x, "character") | ||
expect_true(nzchar(x)) | ||
}) | ||
|
||
test_that(".checktab returns an empty character string if invalid input", { | ||
x <- brmsmargins:::.checktab(mtcars) | ||
expect_type(x, "character") | ||
expect_false(nzchar(x)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
test_that(".links returns correct values with identity link and fixedonly", { | ||
x <- brmsmargins:::.links( | ||
link = "identity", effects = "fixedonly", backtrans = "response") | ||
|
||
expect_type(x, "list") | ||
expect_equal(x$scale, "response") | ||
expect_equal(x$ilink, "identity") | ||
expect_equal(x$ilinknum, -9) | ||
}) | ||
|
||
test_that(".links returns correct values with logit link and fixedonly", { | ||
x <- brmsmargins:::.links( | ||
link = "logit", effects = "fixedonly", backtrans = "response") | ||
|
||
expect_type(x, "list") | ||
expect_equal(x$scale, "response") | ||
expect_equal(x$ilink, "identity") | ||
expect_equal(x$ilinknum, -9) | ||
}) | ||
|
||
test_that(".links returns correct values with identity link and integrateoutRE", { | ||
x <- brmsmargins:::.links( | ||
link = "identity", effects = "integrateoutRE", backtrans = "response") | ||
|
||
expect_type(x, "list") | ||
expect_equal(x$scale, "linear") | ||
expect_equal(x$ilink, "identity") | ||
expect_equal(x$ilinknum, -9) | ||
}) | ||
|
||
test_that(".links returns correct values with logit link and integrateoutRE", { | ||
x <- brmsmargins:::.links( | ||
link = "logit", effects = "integrateoutRE", backtrans = "response") | ||
|
||
expect_type(x, "list") | ||
expect_equal(x$scale, "linear") | ||
expect_equal(x$ilink, "invlogit") | ||
expect_equal(x$ilinknum, 0) | ||
}) | ||
|
||
test_that(".links returns correct values with log link and integrateoutRE", { | ||
x <- brmsmargins:::.links( | ||
link = "log", effects = "integrateoutRE", backtrans = "response") | ||
|
||
expect_type(x, "list") | ||
expect_equal(x$scale, "linear") | ||
expect_equal(x$ilink, "exp") | ||
expect_equal(x$ilinknum, 1) | ||
}) | ||
|
||
test_that(".links returns correct values with sqrt link and integrateoutRE", { | ||
x <- brmsmargins:::.links( | ||
link = "sqrt", effects = "integrateoutRE", backtrans = "response") | ||
|
||
expect_type(x, "list") | ||
expect_equal(x$scale, "linear") | ||
expect_equal(x$ilink, "square") | ||
expect_equal(x$ilinknum, 2) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
test_that(".percent returns NA values when window is NULL", { | ||
x <- brmsmargins:::.percent(1:10, window = NULL) | ||
|
||
## check types | ||
expect_type(x, "list") | ||
expect_type(x$Window, "double") | ||
expect_type(x$Percent, "double") | ||
expect_type(x$Label, "character") | ||
|
||
## check values | ||
expect_equal(x$Window, NA_real_) | ||
expect_equal(x$Percent, NA_real_) | ||
expect_equal(x$Label, NA_character_) | ||
}) | ||
|
||
test_that(".percent returns NA values when within is TRUE", { | ||
x <- brmsmargins:::.percent(1:10, window = c(3, 5)) | ||
|
||
## check types | ||
expect_type(x, "list") | ||
expect_type(x$Window, "double") | ||
expect_type(x$Percent, "double") | ||
expect_type(x$Label, "character") | ||
|
||
## check values | ||
expect_equal(x$Window, c(3, 5)) | ||
expect_equal(x$Percent, 30) | ||
expect_equal(x$Label, "[3, 5]") | ||
}) | ||
|
||
test_that(".percent returns NA values when within is FALSE", { | ||
x <- brmsmargins:::.percent(1:10, window = c(2, 6), within = FALSE) | ||
|
||
## check types | ||
expect_type(x, "list") | ||
expect_type(x$Window, "double") | ||
expect_type(x$Percent, "double") | ||
expect_type(x$Label, "character") | ||
|
||
## check values | ||
expect_equal(x$Window, c(2, 6)) | ||
expect_equal(x$Percent, 70) | ||
expect_equal(x$Label, "[-Inf, 2] | [6, Inf]") | ||
}) | ||
|
||
test_that(".percent errors if window is not valid", { | ||
expect_error(brmsmargins:::.percent(1:10, window = c(2))) | ||
expect_error(brmsmargins:::.percent(1:10, window = c("b", "c"))) | ||
}) |