-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve testing infrastructure. (#871)
Adds/reimplements abstractions for the following: * Create multi-dimensional array filled with suitable values. * Traits for accessing values. * Traits for hiding the difference of DataSet and Attribute. * Useful utilities such as `ravel`, `unravel` and `flat_size`.
- Loading branch information
Showing
6 changed files
with
1,019 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
namespace HighFive { | ||
namespace testing { | ||
|
||
/// \brief Trait for `createAttribute`. | ||
/// | ||
/// The point of these is to simplify testing. The typical issue is that we | ||
/// need to write the tests twice, one with `createDataSet` and then again with | ||
/// `createAttribute`. This trait allows us to inject this difference. | ||
struct AttributeCreateTraits { | ||
using type = Attribute; | ||
|
||
template <class Hi5> | ||
static Attribute get(Hi5& hi5, const std::string& name) { | ||
return hi5.getAttribute(name); | ||
} | ||
|
||
|
||
template <class Hi5, class Container> | ||
static Attribute create(Hi5& hi5, const std::string& name, const Container& container) { | ||
return hi5.createAttribute(name, container); | ||
} | ||
|
||
template <class Hi5> | ||
static Attribute create(Hi5& hi5, | ||
const std::string& name, | ||
const DataSpace& dataspace, | ||
const DataType& datatype) { | ||
return hi5.createAttribute(name, dataspace, datatype); | ||
} | ||
|
||
template <class T, class Hi5> | ||
static Attribute create(Hi5& hi5, const std::string& name, const DataSpace& dataspace) { | ||
auto datatype = create_datatype<T>(); | ||
return hi5.template createAttribute<T>(name, dataspace); | ||
} | ||
}; | ||
|
||
/// \brief Trait for `createDataSet`. | ||
struct DataSetCreateTraits { | ||
using type = DataSet; | ||
|
||
template <class Hi5> | ||
static DataSet get(Hi5& hi5, const std::string& name) { | ||
return hi5.getDataSet(name); | ||
} | ||
|
||
template <class Hi5, class Container> | ||
static DataSet create(Hi5& hi5, const std::string& name, const Container& container) { | ||
return hi5.createDataSet(name, container); | ||
} | ||
|
||
template <class Hi5> | ||
static DataSet create(Hi5& hi5, | ||
const std::string& name, | ||
const DataSpace& dataspace, | ||
const DataType& datatype) { | ||
return hi5.createDataSet(name, dataspace, datatype); | ||
} | ||
|
||
template <class T, class Hi5> | ||
static DataSet create(Hi5& hi5, const std::string& name, const DataSpace& dataspace) { | ||
auto datatype = create_datatype<T>(); | ||
return hi5.template createDataSet<T>(name, dataspace); | ||
} | ||
}; | ||
|
||
} // namespace testing | ||
} // namespace HighFive |
Oops, something went wrong.