Skip to content

Commit

Permalink
add new mandatory parameter in DataSpec to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgessl committed Jan 15, 2024
1 parent 0c55ff7 commit 3ef5f78
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/split.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ ensure_splits <- function(
new_splits <- setdiff(wanted_splits, present_splits)

# Extract from data_spec
time_col <- data_spec$pfs_col
event_col <- data_spec$progression_col
time_col <- data_spec$time_to_event_col
event_col <- data_spec$event_col
pivot_time_cutoff <- data_spec$pivot_time_cutoff
train_prop <- data_spec$train_prop

Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-data_spec.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
test_that("prepend_to_directory() works", {

model_spec_list = list(
ModelSpec("mock1", fitter = zeroSum::zeroSum, directory = "mock1"),
ModelSpec("mock2", fitter = zeroSum::zeroSum, directory = "mock2")
)
model_spec_1 <- ModelSpec("model", "mock1", zeroSum::zeroSum, split_index = 1, time_cutoffs = 2)
model_spec_2 <- model_spec_1
model_spec_2$directory <- "mock2"
model_spec_list <- list(model_spec_1, model_spec_2)

expect_silent(new_msl <- prepend_to_directory(model_spec_list, "prepend_me"))
expect_equal(new_msl[[1]]$directory, "prepend_me/mock1")
expect_equal(new_msl[[2]]$directory, "prepend_me/mock2")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_that("discretize_ipi_features() works", {
"ecog_performance_status" = sample(0:4, n_samples, replace = TRUE),
"n_extranodal_sites" = sample(0:6, n_samples, replace = TRUE)
)
data_spec <- DataSpec(name = "test")
data_spec <- DataSpec(name = "test", directory = "mock", train_prop = 0.8)

pheno_tbl <- discretize_ipi_features(pheno_tbl, data_spec)

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ test_that("read function works correctly", {
data_spec <- DataSpec(
name = "Schmitz et al. (2018)",
directory = "data/schmitz",
train_prop = .7,
expr_fname = "expr1.csv",
pheno_fname = "pheno1.csv",
patient_id_col = "patient_id",
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-split.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ test_that("split_dataset works", {
pheno_tbl <- generate_mock_data(
n_samples = n_samples,
n_genes = n_genes,
n_na_in_pheno = 0
n_na_in_pheno = 0,
split_index = NULL
)[["pheno_tbl"]]
pheno_tbl[["split_2"]] <- "test"
pheno_tbl[["split_2"]] <- "test" # One split already there
data_spec <- DataSpec(
name = "mock",
directory = dir,
Expand All @@ -20,18 +21,21 @@ test_that("split_dataset works", {
)
model_spec_1 <- ModelSpec(
name = "dummy1",
directory = dir,
fitter = zeroSum::zeroSum,
split_index = 1:2,
time_cutoffs = 2
)
model_spec_2 <- ModelSpec(
name = "dummy2",
directory = dir,
fitter = zeroSum::zeroSum,
split_index = 1,
time_cutoffs = 2
)

for(pivot_time_cutoff in list(NULL, 2)){
data_spec$pivot_time_cutoff <- pivot_time_cutoff
new_pheno_tbl <- ensure_splits(
pheno_tbl = pheno_tbl,
data_spec = data_spec,
Expand Down

0 comments on commit 3ef5f78

Please sign in to comment.