Skip to content

Commit

Permalink
started some unit tests with copilot
Browse files Browse the repository at this point in the history
  • Loading branch information
n8thangreen committed Feb 13, 2024
1 parent 3abc5a4 commit 71728b8
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/mimR.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#' mimR_gcomp_stan <- mimR(AC_IPD, BC_ALD, strategy = strategy_gcomp_stan())
#'
mimR <- function(AC.IPD, BC.ALD, strategy, CI = 0.95, ...) {

if (CI <= 0 || CI >= 1) stop("CI argument must be between 0 and 1.")
##TODO: as method instead?
if (!inherits(strategy, "strategy"))
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-parse_formula.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# unit test functions in parse_formula.R


test_that("test get_effect_modifiers", {
expect_equal(get_effect_modifiers(y ~ x), character(0))
expect_equal(get_effect_modifiers(y ~ x + z), "z")
})

test_that("test get_treatment_name", {
expect_equal(get_treatment_name(y ~ x), "x")
expect_equal(get_treatment_name(y ~ x + z), "x")
expec
})

test_that("get_mean_names", {
expect_equal(get_mean_names(y ~ x), "y")
expect_equal(get_mean_names(y ~ x + z), "y")
})

test_that("get_sd_names", {
expect_equal(get_sd_names(y ~ x), "y")
expect_equal(get_sd_names(y ~ x + z), "y")
})

test_that("get_covariate_names", {
expect_equal(get_covariate_names(y ~ x), character(0))
expect_equal(get_covariate_names(y ~ x + z), "z")
})

68 changes: 68 additions & 0 deletions tests/testthat/test-xxx_stats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# unit tests for ALD_stats()

test_that("ALD_stats() returns the correct values", {
# test 1
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(ALD_stats(x, y), c(0, 0, 0, 0, 0))
# test 2
x <- c(1, 2, 3, 4, 5)
y <- c(5, 4, 3, 2, 1)
expect_equal(ALD_stats(x, y), c(4, 4, 4, 4, 4))
# test 3
x <- c(1, 2, 3, 4, 5)
y <- c(1, 1, 1, 1, 1)
expect_equal(ALD_stats(x, y), c(0, 0, 0, 0, 0))
# test 4
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(ALD_stats(x, y), c(0, 0, 0, 0, 0))
# test 5
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(ALD_stats(x, y), c(0, 0, 0, 0, 0))
# test 6
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(ALD_stats(x, y), c(0, 0, 0, 0, 0))
# test 7
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(ALD_stats(x, y), c(0, 0, 0, 0, 0))
})


# unit tests for IPD_stats()

test_that("IPD_stats() returns the correct values", {
# test 1
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(IPD_stats(x, y), c(0, 0, 0, 0, 0))
# test 2
x <- c(1, 2, 3, 4, 5)
y <- c(5, 4, 3, 2, 1)
expect_equal(IPD_stats(x, y), c(4, 4, 4, 4, 4))
# test 3
x <- c(1, 2, 3, 4, 5)
y <- c(1, 1, 1, 1, 1)
expect_equal(IPD_stats(x, y), c(0, 0, 0, 0, 0))
# test 4
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(IPD_stats(x, y), c(0, 0, 0, 0, 0))
# test 5
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(IPD_stats(x, y), c(0, 0, 0, 0, 0))
# test 6
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(IPD_stats(x, y), c(0, 0, 0, 0, 0))
# test 7
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
expect_equal(IPD_stats(x, y), c(0, 0, 0, 0, 0))
})


0 comments on commit 71728b8

Please sign in to comment.