DataArray createDataArray(const std::string &name, const std::string &type, const T &data) { const Hydra<const T> hydra(data); DataType dtype = hydra.element_data_type(); const NDSize shape = hydra.shape(); DataArray da = createDataArray(name, type, dtype, shape); const NDSize offset(shape.size(), 0); da.setData(data, offset); return da; }
void TestBlock::testMultiTagAccess() { vector<string> names = { "tag_a", "tag_b", "tag_c", "tag_d", "tag_e" }; // create a valid positions data array below typedef boost::multi_array<double, 3>::index index; DataArray positions = block.createDataArray("array_one", "testdata", DataType::Double, nix::NDSize({ 3, 4, 2 })); boost::multi_array<double, 3> A(boost::extents[3][4][2]); int values = 0; for(index i = 0; i != 3; ++i) for(index j = 0; j != 4; ++j) for(index k = 0; k != 2; ++k) A[i][j][k] = values++; positions.setData(A); CPPUNIT_ASSERT(block.multiTagCount() == 0); CPPUNIT_ASSERT(block.multiTags().size() == 0); CPPUNIT_ASSERT(block.getMultiTag("invalid_id") == false); vector<string> ids; for (auto it = names.begin(); it != names.end(); it++) { MultiTag tag = block.createMultiTag(*it, "segment", positions); CPPUNIT_ASSERT(tag.name() == *it); ids.push_back(tag.id()); } CPPUNIT_ASSERT_THROW(block.createMultiTag(names[0], "segment", positions), DuplicateName); CPPUNIT_ASSERT(block.multiTagCount() == names.size()); CPPUNIT_ASSERT(block.multiTags().size() == names.size()); for (auto it = ids.begin(); it != ids.end(); it++) { MultiTag tag = block.getMultiTag(*it); CPPUNIT_ASSERT(block.hasMultiTag(*it) == true); CPPUNIT_ASSERT(tag.id() == *it); block.deleteMultiTag(*it); } CPPUNIT_ASSERT(block.multiTagCount() == 0); CPPUNIT_ASSERT(block.multiTags().size() == 0); CPPUNIT_ASSERT(block.getMultiTag("invalid_id") == false); }