Skip to content

Commit b98d1d5

Browse files
committed
add tests
1 parent 6ef38f6 commit b98d1d5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/testthat/test_materialize.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@ test_that("0-length", {
189189
expect_equal(list(), materialize(lazy_tensor(), rbind = FALSE))
190190
})
191191

192+
test_that("materialize.data.frame with empty data.frame", {
193+
lt = as_lazy_tensor(torch_randn(5, 3))
194+
df = data.frame(x = I(lt[integer(0)]))
195+
196+
res_rbind = materialize(df, rbind = TRUE)
197+
expect_list(res_rbind)
198+
expect_equal(names(res_rbind), "x")
199+
expect_class(res_rbind$x, "torch_tensor")
200+
expect_equal(res_rbind$x$shape, 0L)
201+
202+
res_list = materialize(df, rbind = FALSE)
203+
expect_list(res_list)
204+
expect_equal(names(res_list), "x")
205+
expect_list(res_list$x, len = 0)
206+
})
207+
192208
test_that("materialize with shape (NA, NA) and .getbatch implementation", {
193209
# this can e.g. happen when we do padding in the dataset
194210
ds = dataset(

tests/testthat/test_utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
test_that("auto_device handles NULL and 'auto'", {
2+
# NULL should be returned as-is
3+
expect_null(auto_device(NULL))
4+
# explicit device should be returned as-is
5+
expect_equal(auto_device("cpu"), "cpu")
6+
# "auto" should return either "cuda" or "cpu"
7+
expect_true(auto_device("auto") %in% c("cuda", "cpu"))
8+
})
9+
110
test_that("make_check_vector works", {
211
check_vector1 = make_check_vector(1)
312
expect_true(check_vector1(1))

0 commit comments

Comments
 (0)