Skip to content

Commit

Permalink
add test skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
advieser committed Nov 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e0f6e82 commit 33dbac7
Showing 1 changed file with 57 additions and 13 deletions.
70 changes: 57 additions & 13 deletions tests/testthat/test_pipeop_decode.R
Original file line number Diff line number Diff line change
@@ -17,32 +17,76 @@ test_that("PipeOpDecode - basic properties", {
expect_datapreproc_pipeop_class(PipeOpDecode, task = task)
})

test_that("PipeOpDecode - assertions", {
# test that edge cases are caught
})

test_that("PipeOpDecode - one-hot-encoding", {
po = PipeOpDecode$new()
op = PipeOpDecode$new()

df = data.frame(
target = runif(120),
x.1 = rep(c(1, 0, 0), 40),
x.2 = rep(c(0, 1, 0), 40),
x.3 = rep(c(0, 0, 1), 40),
y.1 = rep(c(1, 0, 0), 40),
y.2 = rep(c(0, 1, 0), 40),
y.3 = rep(c(0, 0, 1), 40),
a = runif(120)
target = runif(10),
x.1 = rep(c(1, 0), 5),
x.2 = rep(c(0, 1), 5),
a = runif(10)
)
task = TaskRegr$new(id = "decode", backend = df, target = "target")

train_out = op$train(list(task))[[1]]$data()
dt = data.table(
x = rep(c(1, 2), each = 5),
a = df$a
)
expect_equal(train_out, dt)

})

test_that("PipeOpDecode - treatment encoding", {
op = PipeOpDecode$new()
op$param_set$values$treatment_encoding = TRUE

df = data.frame(
target = runif(15),
x.1 = rep(c(1, 0, 0), 5),
x.2 = rep(c(0, 0, 1), 5),
a = runif(15)
)
task = TaskRegr$new(id = "decode", backend = df, target = "target")

train_out = op$train(list(task))[[1]]$data()
dt = data.table(
x = rep(c("1", "ref", "2"), times = 5),
a = df$a
)
expect_equal(train_out, dt)
})

test_that("PipOpDecode - different regex patterns", {
op = PipeOpDecode$new()
op$param_set$values$regex_pattern = ""

df = data.frame(
target = runif(15),
x.1 = rep(c(1, 0, 0), 5),
x.2 = rep(c(0, 0, 1), 5),
a = rep(c(0, 1, 0), 5)
)
task = TaskRegr$new(id = "decode", backend = df, target = "target")

train_out = op$train(list(task))[[1]]$data()
dt = data.table(
x = rep(c("x.1", "a", "x.2"), times = 5)
)
expect_equal(train_out, dt)
})

test_that("PipeOpDecode - errors", {
op = PipeOpDecode$new()

df = data.frame(
target = runif(15),
x.1 = rep(c(1, 0, 0), 5),
x.2 = rep(c(0, 1, 1), 5),
a = runif(15)
)
task = TaskRegr$new(id = "decode", backend = df, target = "target")

expect_error(op$train(list(task))) # due to non-unique which.max

})

0 comments on commit 33dbac7

Please sign in to comment.