From b915255fc0b77d21cc3e3f820e61bec032f59d23 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 18 Aug 2024 22:56:32 -0400 Subject: [PATCH] Adding unit-test cases [skip ci] --- libtiledbsoma/test/common.cc | 2 +- libtiledbsoma/test/unit_soma_dataframe.cc | 43 +++++++++++++++++++ .../test/unit_soma_sparse_ndarray.cc | 11 ++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/libtiledbsoma/test/common.cc b/libtiledbsoma/test/common.cc index cc81060eb7..c60ed9946c 100644 --- a/libtiledbsoma/test/common.cc +++ b/libtiledbsoma/test/common.cc @@ -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); } diff --git a/libtiledbsoma/test/unit_soma_dataframe.cc b/libtiledbsoma/test/unit_soma_dataframe.cc index 77f36fae92..b2acfbc53e 100644 --- a/libtiledbsoma/test/unit_soma_dataframe.cc +++ b/libtiledbsoma/test/unit_soma_dataframe.cc @@ -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(); + 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 d0({101, 102}); + std::vector 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({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(); +} diff --git a/libtiledbsoma/test/unit_soma_sparse_ndarray.cc b/libtiledbsoma/test/unit_soma_sparse_ndarray.cc index f4c8e11083..9c276f21b1 100644 --- a/libtiledbsoma/test/unit_soma_sparse_ndarray.cc +++ b/libtiledbsoma/test/unit_soma_sparse_ndarray.cc @@ -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{dim_max + 1}); } else { - REQUIRE( - soma_sparse->maxshape() == std::vector{dim_max + 1}); + // DEBUG: + // REQUIRE(soma_sparse->shape() == std::vector{dim_max + + // 1}); } soma_sparse->close();