1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "eckit/testing/Test.h"
#include "mir/data/Space.h"
#include "mir/param/CombinedParametrisation.h"
#include "mir/param/DefaultParametrisation.h"
#include "mir/param/SimpleParametrisation.h"
#include "mir/util/Exceptions.h"
#include "mir/util/Log.h"
namespace mir::tests::unit {
CASE("vector-space") {
static const std::string key = "vector-space";
static const param::DefaultParametrisation defaults;
std::string defaultSpace;
ASSERT(defaults.get(key, defaultSpace));
auto combined = [](const param::MIRParametrisation& user, const param::MIRParametrisation& input,
const param::MIRParametrisation& defaults) {
return std::unique_ptr<const param::MIRParametrisation>(
new param::CombinedParametrisation(user, input, defaults));
};
std::vector<std::pair<std::string, size_t>> tests{{"1d-angle-degree-asymmetric", 1},
{"1d-angle-degree-symmetric", 1},
{"1d-angle-radian-asymmetric", 1},
{"1d-angle-radian-symmetric", 1},
{"1d-linear", 1},
{"1d-logarithmic", 1},
{"2d-vector-u", 2},
{"2d-vector-v", 2},
{"3d-cartesian-x", 3},
{"3d-cartesian-y", 3},
{"3d-cartesian-z", 3},
{"3d-vector-u", 3},
{"3d-vector-v", 3},
{"3d-vector-w", 3}};
SECTION("vector-space default") {
const param::SimpleParametrisation user; // empty
const param::SimpleParametrisation input; // empty
std::string space;
ASSERT(combined(user, input, defaults)->get(key, space));
EXPECT_NOT(defaultSpace.empty());
EXPECT_EQUAL(space, defaultSpace);
}
SECTION("vector-space field-set") {
const param::SimpleParametrisation user; // empty
for (auto& f : tests) {
param::SimpleParametrisation input;
input.set(key, f.first);
std::string space;
ASSERT(combined(user, input, defaults)->get(key, space));
EXPECT_NOT(space.empty());
const auto& sp = data::SpaceChooser::lookup(space);
Log::info() << "field-set: " << f.first << " dimensions = " << sp.dimensions()
<< ", expected = " << f.second << std::endl;
EXPECT(sp.dimensions() == f.second);
}
}
SECTION("vector-space user- and field-set") {
for (auto& f : tests) {
param::SimpleParametrisation input;
input.set(key, f.first);
for (auto& u : tests) {
Log::info() << "user-set: " << u.first << ", field-set: " << u.first << "...";
param::SimpleParametrisation user;
user.set(key, u.first);
std::string space;
ASSERT(combined(user, input, defaults)->get(key, space));
EXPECT_NOT(space.empty());
const auto& sp = data::SpaceChooser::lookup(space);
Log::info() << "user-set: " << u.first << " dimensions = " << sp.dimensions()
<< ", expected = " << u.second << std::endl;
EXPECT(sp.dimensions() == u.second);
}
}
}
}
} // namespace mir::tests::unit
int main(int argc, char** argv) {
return eckit::testing::run_tests(argc, argv);
}
|