Skip to content

Commit

Permalink
R unit testing WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Sep 29, 2024
1 parent 49a2b21 commit 9c64a11
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions apis/r/tests/testthat/test-shape.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ test_that("SOMADataFrame shape", {
expect_equal(int_mxd, int_dfc)
}
} else {
expect_true(int_mxd[[1]] < -2000000000)
expect_true(int_mxd[[2]] > 2000000000)
expect_true(int_mxd[[1]] < -2000000000)
expect_true(int_mxd[[2]] > 2000000000)
}
}

Expand All @@ -202,7 +202,7 @@ test_that("SOMADataFrame shape", {
expect_equal(str_dom, c("", ""))
} else {
if (is.null(str_dfc)) {
expect_equal(str_dom, c("", ""))
expect_equal(str_dom, c("", ""))
} else {
expect_equal(str_dom, str_dfc)
}
Expand All @@ -213,6 +213,63 @@ test_that("SOMADataFrame shape", {

sdf$close()

# Test resize for dataframes (more general upgrade_domain to be tested
# separately -- see https://github.com/single-cell-data/TileDB-SOMA/issues/2407)
if (.new_shape_feature_flag_is_enabled() && use_domain_at_create) {
has_soma_joinid_dim <- "soma_joinid" %in% index_column_names
sjid_dfc <- domain_for_create[["soma_joinid"]]

# Test resize down
new_shape <- 0
sdf <- SOMADataFrameOpen(uri, "WRITE")
if (has_soma_joinid_dim) {
# It's an error to downsize
expect_error(sdf$resize_soma_joinid(new_shape))
} else {
# There is no problem when soma_joinid is not a dim --
# sdf$resize_soma_joinid is a no-op in that case
expect_no_condition(sdf$resize_soma_joinid(new_shape))
}
sdf$close()

if (has_soma_joinid_dim) {
sdf <- SOMADataFrameOpen(uri, "READ")
expect_equal(sdf$domain()[["soma_joinid"]], sjid_dfc)
sdf$close()
}

# Test writes out of bounds, before resize
new_shape <- 100
if (has_soma_joinid_dim) {
new_shape <- domain_for_create[["soma_joinid"]][[2]] + 1 + 100
}

tbl1 <- arrow::arrow_table(
int_column = 5L:8L,
soma_joinid = (new_shape+1L):(new_shape+4L),
float_column = 5.1:8.1,
string_column = c("egg", "flag", "geese", "hay"),
schema = asch)

sdf <- SOMADataFrameOpen(uri, "WRITE")
# Current status: debug
expect_error(sdf$write(tbl1))
sdf$close()

# Test resize

sdf <- SOMADataFrameOpen(uri, "WRITE")
sdf$resize_soma_joinid(new_shape)
sdf$close();

# Test writes out of old bounds, within new bounds, after resize
sdf <- SOMADataFrameOpen(uri, "WRITE")
expect_no_condition(sdf$write(tbl1))
sdf$close();

rm(tbl1)
}

rm(sdf, tbl0)

gc()
Expand Down

0 comments on commit 9c64a11

Please sign in to comment.