Skip to content

Commit

Permalink
Adding unit-test cases [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Aug 19, 2024
1 parent e03fe5f commit b915255
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libtiledbsoma/test/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ ArrowTable create_column_index_info(int64_t dim_max, bool use_current_domain) {
std::memcpy((void*)d0_info->buffers[1], &dom, sizeof(int64_t) * n);
} else {
// domain small; current_domain feature not being used
int64_t dom[] = {0, dim_max, 1};
int64_t dom[] = {0, CORE_DOMAIN_MAX, 1, 0, dim_max};
std::memcpy((void*)d0_info->buffers[1], &dom, sizeof(int64_t) * n);
}

Expand Down
43 changes: 43 additions & 0 deletions libtiledbsoma/test/unit_soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,46 @@ TEST_CASE("SOMADataFrame: metadata") {
REQUIRE(soma_dataframe->metadata_num() == 2);
}
}

TEST_CASE("SOMADataFrame: bounds-checking") {
bool use_current_domain = true;

auto ctx = std::make_shared<SOMAContext>();
std::string uri = "mem://unit-test-bounds-checking";

auto [schema, index_columns] = helper::create_arrow_schema(
100, use_current_domain);

SOMADataFrame::create(
uri,
std::move(schema),
ArrowTable(
std::move(index_columns.first), std::move(index_columns.second)),
ctx);

auto soma_dataframe = SOMADataFrame::open(uri, OpenMode::write, ctx);

std::vector<int64_t> d0({101, 102});
std::vector<double> a0({1.5, 2.5});
soma_dataframe->set_column_data("d0", d0.size(), d0.data());
soma_dataframe->set_column_data("a0", a0.size(), a0.data());
REQUIRE_THROWS(soma_dataframe->write());
soma_dataframe->close();

soma_dataframe = SOMADataFrame::open(uri, OpenMode::write, ctx);
soma_dataframe->resize(std::vector<int64_t>({200}));
soma_dataframe->close();

// soma_dataframe = SOMADataFrame::open(
// uri,
// OpenMode::write,
// ctx,
// {},
// ResultOrder::automatic,
// TimestampRange(1, 1));
// soma_dataframe->set_column_data("d0", d0.size(), d0.data());
// soma_dataframe->set_column_data("a0", a0.size(), a0.data());
// soma_dataframe->write();

soma_dataframe->close();
}
11 changes: 9 additions & 2 deletions libtiledbsoma/test/unit_soma_sparse_ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ TEST_CASE("SOMASparseNDArray: basic") {
REQUIRE(soma_sparse->ndim() == 1);
REQUIRE(soma_sparse->nnz() == 0);

printf("\n");
printf("UCD %d\n", (int)use_current_domain);
printf("SHP %lld\n", soma_sparse->shape()[0]);
printf("MXP %lld\n", soma_sparse->maxshape()[0]);
printf("\n");

if (use_current_domain) {
REQUIRE(soma_sparse->shape() == std::vector<int64_t>{dim_max + 1});
} else {
REQUIRE(
soma_sparse->maxshape() == std::vector<int64_t>{dim_max + 1});
// DEBUG:
// REQUIRE(soma_sparse->shape() == std::vector<int64_t>{dim_max +
// 1});
}

soma_sparse->close();
Expand Down

0 comments on commit b915255

Please sign in to comment.