Skip to content

Commit

Permalink
Tidying unit test files for pilot3utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Devine committed Feb 14, 2024
1 parent 1b91b22 commit a77407a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
3 changes: 2 additions & 1 deletion R/example.r
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ testthat_example <- function(filename) {
package = "testthat",
mustWork = TRUE
)
}
}

Check warning on line 25 in R/example.r

View workflow job for this annotation

GitHub Actions / lint

file=R/example.r,line=25,col=1,[trailing_blank_lines_linter] Trailing blank lines are superfluous.
5 changes: 0 additions & 5 deletions tests/testthat/test-adam_functions.r
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,3 @@ test_that("round_sas works", {
expect_length(round_sas(10.56, digits = 0), 1)

Check warning on line 48 in tests/testthat/test-adam_functions.r

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-adam_functions.r,line=48,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
})





1 change: 0 additions & 1 deletion tests/testthat/test-eff_models.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ test_that("Pilot3 can use the testthat 3e", {
local_edition(3)
expect_true(TRUE)
})

15 changes: 5 additions & 10 deletions tests/testthat/test-fmt.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ test_that("Pilot3 can use the testthat 3e", {
expect_true(TRUE)
})


test_that("fmt_num works", {
expect_equal(fmt_num(1.25, digits = 1), ' 1.2')
expect_equal(fmt_num(1.25, digits = 2), ' 1.25')
expect_equal(fmt_num(4.25, digits = 3), ' 4.250')
expect_equal(fmt_num(1.25, digits = 0), ' 1')
expect_length(fmt_num(1.25,digits = 4), 1)
expect_equal(fmt_num(1.25, digits = 1), " 1.2")
expect_equal(fmt_num(1.25, digits = 2), " 1.25")
expect_equal(fmt_num(4.25, digits = 3), " 4.250")
expect_equal(fmt_num(1.25, digits = 0), " 1")
expect_length(fmt_num(1.25, digits = 4), 1)
})


Expand All @@ -20,9 +19,7 @@ test_that("fmt_est works", {
expect_length(fmt_est(1.25, 0.5), 1)
})


test_that("fmt_pval works", {

expect_equal(fmt_pval(0.446, digits = 2), " 0.45")
expect_equal(fmt_pval(0.445, digits = 3), " 0.445")
expect_equal(fmt_pval(0.52, digits = 3), " 0.520")
Expand All @@ -31,9 +28,7 @@ test_that("fmt_pval works", {

Check warning on line 28 in tests/testthat/test-fmt.r

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-fmt.r,line=28,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
})


test_that("fmt_ci works", {

expect_equal(fmt_ci(1, -0.25, 1.32), " 1.00 (-0.25, 1.32)")
expect_equal(fmt_ci(1.5, -0.04, 1.09), " 1.50 (-0.04, 1.09)")
expect_equal(fmt_ci(-2.5, -0.09, 2.07), "-2.50 (-0.09, 2.07)")
Expand Down
28 changes: 12 additions & 16 deletions tests/testthat/test-helpers.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ test_that("Pilot3 can use the testthat 3e", {
})

test_that("pad_row works", {

.data <- tibble::tribble(
~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~AVISIT,
"TEST01", "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", "BASELINE",
"TEST01", "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", "WEEK 2",
"TEST01", "01-701-1015", "SYSBP", "Systolic Blood Pressure (mmHg)", "BASELINE",
"TEST01", "01-701-1015", "SYSBP", "Systolic Blood Pressure (mmHg)", "WEEK 2",
"TEST01", "01-701-1028", "DIABP", "Diastolic Blood Pressure (mmHg)", "BASELINE",
"TEST01", "01-701-1028", "SYSBP", "Systolic Blood Pressure (mmHg)", "BASELINE"

.data <- tibble::tribble(
~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~AVISIT,
"TEST01", "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", "BASELINE",
"TEST01", "01-701-1015", "DIABP", "Diastolic Blood Pressure (mmHg)", "WEEK 2",
"TEST01", "01-701-1015", "SYSBP", "Systolic Blood Pressure (mmHg)", "BASELINE",
"TEST01", "01-701-1015", "SYSBP", "Systolic Blood Pressure (mmHg)", "WEEK 2",
"TEST01", "01-701-1028", "DIABP", "Diastolic Blood Pressure (mmHg)", "BASELINE",
"TEST01", "01-701-1028", "SYSBP", "Systolic Blood Pressure (mmHg)", "BASELINE"
)

Check warning on line 15 in tests/testthat/test-helpers.r

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-helpers.r,line=15,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces.
expect_equal(nrow(pad_row(.data)), 7)
expect_equal(nrow(pad_row(.data,n = 3)), 9)
expect_equal(nrow(pad_row(.data,n = 5)), 11)
expect_equal(nrow(pad_row(.data, n = 3)), 9)
expect_equal(nrow(pad_row(.data, n = 5)), 11)
expect_length(nrow(pad_row(.data)), 1)

})


test_that("num_fmt works", {
expect_equal(num_fmt(NA, digits = 0, size = 10, int_len = 3), "")
expect_equal(num_fmt(5, digits = 0, size = 10, int_len = 3), " 5 ")
Expand All @@ -37,8 +33,8 @@ test_that("str_pad works", {
})

test_that("nrow works", {
expect_equal(nrow(matrix(1:12,3,4)), 3)
expect_length(nrow(matrix(1:12,3,4)), 1)
expect_equal(nrow(matrix(1:12, 3, 4)), 3)
expect_length(nrow(matrix(1:12, 3, 4)), 1)
})

test_that("round works", {
Expand Down

0 comments on commit a77407a

Please sign in to comment.