From 82692157a272af74195c0f9f5f1f58e22cddf96e Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Tue, 5 Dec 2023 16:44:39 +0000 Subject: [PATCH] test: implemented test_Indexed, should fail --- .../tests/test_1494-layout-builder.cpp | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/header-only/tests/test_1494-layout-builder.cpp b/header-only/tests/test_1494-layout-builder.cpp index c9c6201fef..bb813c73e6 100644 --- a/header-only/tests/test_1494-layout-builder.cpp +++ b/header-only/tests/test_1494-layout-builder.cpp @@ -58,6 +58,9 @@ using TupleBuilder = awkward::LayoutBuilder::Tuple; template using RegularBuilder = awkward::LayoutBuilder::Regular; +template +using IndexedBuilder = awkward::LayoutBuilder::Indexed; + template using IndexedOptionBuilder = awkward::LayoutBuilder::IndexedOption; @@ -1209,6 +1212,62 @@ test_Regular_size0() { assert(builder.length() == 0); } +void +test_Indexed() { + IndexedBuilder> builder; + assert(builder.length() == 0); + + std::cout << "Executing test_Indexed"; + + auto& subbuilder = builder.append_index(); + subbuilder.append(1.1); + + builder.append_index(); + subbuilder.append(2.2); + + double data[3] = {3.3, 4.4, 5.5}; + + builder.extend_index(1); + subbuilder.extend(data, 3); + + // [1.1, 2.2, 3.3, 4.4, 5.5] + + std::string error; + assert(builder.is_valid(error) == true); + + std::map names_nbytes = {}; + builder.buffer_nbytes(names_nbytes); + assert(names_nbytes.size() == 2); + + auto buffers = empty_buffers(names_nbytes); + builder.to_buffers(buffers); + + std::ostringstream out; + dump(out, + "node0-index", (uint32_t*)buffers["node0-index"], names_nbytes["node0-index"]/sizeof(uint32_t), + "node1-data", (double*)buffers["node1-data"], names_nbytes["node1-data"]/sizeof(double)); + + std::string check{"node0-index: 0 1 2 3 4 \n" + "node1-data: 1.1 2.2 3.3 4.4 5.5 \n"}; + assert(out.str().compare(check) == 0); + + assert(builder.form() == + "{ " + "\"class\": \"IndexedArray\", " + "\"index\": \"u32\", " + "\"content\": { " + "\"class\": \"NumpyArray\", " + "\"primitive\": \"float64\", " + "\"form_key\": \"node1\" " + "}, " + "\"form_key\": \"node0\" " + "}"); + + clear_buffers(buffers); + builder.clear(); + assert(builder.length() == 0); +} + void test_Indexed_as_IndexedOption() { IndexedOptionBuilder> builder; @@ -1875,6 +1934,7 @@ int main(int /* argc */, char ** /* argv */) { test_Regular(); test_Regular_size0(); test_Indexed_as_IndexedOption(); + test_Indexed(); test_IndexedOption(); test_IndexedOption_Record(); test_Unmasked();