-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There's (at least) three attempts at testing read/write cycles for multi-dimensional arrays. The first is whatever is in tests_*multi_dims.cpp. Since it's partial, a second attempt was made: the first half of test_all_types.cpp. Since this was still partial and not quite DRY enough, a third attempt was made. This PR removes the duplicated tests from the first and second attempt, one-by-one. Each commit removes one test. Or moves/reimplements a test if it's not yet covered by the third attempt. There's a fourth attempt in test_high_five_base.cpp; but that's left for another PR.
- Loading branch information
Showing
8 changed files
with
234 additions
and
474 deletions.
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
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,80 @@ | ||
/* | ||
* Copyright (c), 2023, 2024 Blue Brain Project - EPFL | ||
* | ||
* Distributed under the Boost Software License, Version 1.0. | ||
* (See accompanying file LICENSE_1_0.txt or copy at | ||
* http://www.boost.org/LICENSE_1_0.txt) | ||
* | ||
*/ | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <type_traits> | ||
|
||
#include <catch2/catch_template_test_macros.hpp> | ||
|
||
#include "data_generator.hpp" | ||
|
||
namespace HighFive { | ||
namespace testing { | ||
|
||
template <class T, class = void> | ||
struct DiffMessageTrait; | ||
|
||
template <class T> | ||
struct DiffMessageTrait<T, typename std::enable_if<std::is_floating_point<T>::value>::type> { | ||
static std::string diff(T a, T b) { | ||
std::stringstream sstream; | ||
sstream << std::scientific << " delta: " << a - b; | ||
return sstream.str(); | ||
} | ||
}; | ||
|
||
template <class T> | ||
struct DiffMessageTrait<T, typename std::enable_if<!std::is_floating_point<T>::value>::type> { | ||
static std::string diff(T /* a */, T /* b */) { | ||
return ""; | ||
} | ||
}; | ||
|
||
template <class T> | ||
std::string diff_message(T a, T b) { | ||
return DiffMessageTrait<T>::diff(a, b); | ||
} | ||
|
||
template <class Actual, class Expected, class Comp> | ||
void compare_arrays(const Actual& actual, | ||
const Expected& expected, | ||
const std::vector<size_t>& dims, | ||
Comp comp) { | ||
using actual_trait = testing::ContainerTraits<Actual>; | ||
using expected_trait = testing::ContainerTraits<Expected>; | ||
using base_type = typename actual_trait::base_type; | ||
|
||
auto n = testing::flat_size(dims); | ||
|
||
for (size_t i = 0; i < n; ++i) { | ||
auto indices = testing::unravel(i, dims); | ||
base_type actual_value = actual_trait::get(actual, indices); | ||
base_type expected_value = expected_trait::get(expected, indices); | ||
auto c = comp(actual_value, expected_value); | ||
if (!c) { | ||
std::stringstream sstream; | ||
sstream << std::scientific << "i = " << i << ": " << actual_value | ||
<< " != " << expected_value << diff_message(actual_value, expected_value); | ||
INFO(sstream.str()); | ||
} | ||
REQUIRE(c); | ||
} | ||
} | ||
|
||
template <class Actual, class Expected> | ||
void compare_arrays(const Actual& actual, | ||
const Expected& expected, | ||
const std::vector<size_t>& dims) { | ||
using base_type = typename testing::ContainerTraits<Actual>::base_type; | ||
compare_arrays(expected, actual, dims, [](base_type a, base_type b) { return a == b; }); | ||
} | ||
|
||
} // namespace testing | ||
} // namespace HighFive |
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
Oops, something went wrong.