diff --git a/src/test/test_dataset.cxx b/src/test/test_dataset.cxx index 1596fd5..ec0f141 100644 --- a/src/test/test_dataset.cxx +++ b/src/test/test_dataset.cxx @@ -13,10 +13,11 @@ namespace z5 { class DatasetTest : public ::testing::Test { protected: - DatasetTest() : fileHandle_("data.zr"), floatHandle_(fileHandle_, "float"), intHandle_(fileHandle_, "int") { + DatasetTest() : fileHandle_("data.zr"), intHandle_(fileHandle_, "int"), floatHandle_(fileHandle_, "float"), complexFloatHandle_(fileHandle_, "complexFloat") { // int zarray metadata jInt_ = "{ \"chunks\": [10, 10, 10], \"compressor\": { \"clevel\": 5, \"cname\": \"lz4\", \"id\": \"blosc\", \"shuffle\": 1}, \"dtype\": \" dataComplexFloat_[size_]; }; @@ -222,6 +237,76 @@ namespace z5 { } } + TEST_F(DatasetTest, OpenComplexFloatDataset) { + + auto ds = openDataset(fileHandle_, "complexFloat"); + const auto & chunksPerDim = ds->chunksPerDimension(); + + std::default_random_engine generator; + + // test uninitialized chunk -> this is expected to throw a runtime error + std::complex dataTmp[size_]; + ASSERT_THROW(ds->readChunk(types::ShapeType({0, 0, 0}), dataTmp), std::runtime_error); + + // test for 10 random chunks + for(unsigned t = 0; t < 10; ++t) { + + // get a random chunk + types::ShapeType chunkId(ds->dimension()); + for(unsigned d = 0; d < ds->dimension(); ++d) { + std::uniform_int_distribution distr(0, chunksPerDim[d] - 1); + chunkId[d] = distr(generator); + } + + ds->writeChunk(chunkId, dataComplexFloat_); + + // read a chunk + std::complex dataTmp[size_]; + ds->readChunk(chunkId, dataTmp); + + // check + for(std::size_t i = 0; i < size_; ++i) { + ASSERT_EQ(dataTmp[i], dataComplexFloat_[i]); + } + } + } + + TEST_F(DatasetTest, CreateComplexFloatDataset) { + + DatasetMetadata complexFloatMeta; + complexFloatMeta.fromJson(jComplexFloat_, true); + + auto ds = createDataset(fileHandle_, "complexFloat1", complexFloatMeta); + const auto & chunksPerDim = ds->chunksPerDimension(); + + std::default_random_engine generator; + + // test uninitialized chunk -> this is expected to throw a runtime error + std::complex dataTmp[size_]; + ASSERT_THROW(ds->readChunk(types::ShapeType({0, 0, 0}), dataTmp), std::runtime_error); + + // test for 10 random chunks + for(unsigned t = 0; t < 10; ++t) { + + // get a random chunk + types::ShapeType chunkId(ds->dimension()); + for(unsigned d = 0; d < ds->dimension(); ++d) { + std::uniform_int_distribution distr(0, chunksPerDim[d] - 1); + chunkId[d] = distr(generator); + } + + ds->writeChunk(chunkId, dataComplexFloat_); + + // read a chunk + std::complex dataTmp[size_]; + ds->readChunk(chunkId, dataTmp); + + // check + for(std::size_t i = 0; i < size_; ++i) { + ASSERT_EQ(dataTmp[i], dataComplexFloat_[i]); + } + } + } TEST_F(DatasetTest, CreateBloscDataset) {