-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98440cb
commit efde4c9
Showing
2 changed files
with
79 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,78 @@ | ||
/* | ||
* (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. | ||
*/ | ||
|
||
/// @file test_levelist.cc | ||
/// @author Metin Cakircali | ||
/// @date November 2023 | ||
|
||
#include "metkit/mars/TypesFactory.h" | ||
#include "metkit/mars/TypeToByListFloat.h" | ||
#include "metkit/mars/MarsParser.h" | ||
#include "metkit/mars/MarsLanguage.h" | ||
|
||
#include "eckit/exception/Exceptions.h" | ||
#include "eckit/testing/Test.h" | ||
|
||
using namespace eckit::testing; | ||
|
||
namespace metkit { | ||
namespace mars { | ||
namespace test { | ||
|
||
//----------------------------------------------------------------------------- | ||
|
||
CASE("test_metkit_exists_to-by-list-float") { | ||
std::stringstream ss; | ||
TypesFactory::list(ss); | ||
const std::string str(ss.str()); | ||
std::cout << "types=" << str << std::endl; | ||
EXPECT(str.find_first_of("to-by-list-float")); | ||
} | ||
|
||
void assertTypeExpansion(const std::string& name, std::vector<std::string> values, | ||
const std::vector<std::string>& expected) { | ||
static MarsLanguage language("retrieve"); | ||
language.type(name)->expand(DummyContext(), values); | ||
ASSERT(values == expected); | ||
} | ||
|
||
CASE("test_metkit_expand_levelist") { | ||
// by > 0 | ||
assertTypeExpansion("levelist", {"-1", "to", "2", "by", "0.5"}, {"-1", "-0.5", "0", ".5", "1", "1.5", "2"}); | ||
// by > 0 | ||
assertTypeExpansion("levelist", {"-10.0", "to", "2.0", "by", "1"}, | ||
{"-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", "1", "2"}); | ||
// by > 0 && from < to | ||
assertTypeExpansion("levelist", {"4", "to", "20", "by", "4"}, {"4", "8", "12", "16", "20"}); | ||
// by > 0 && from > to | ||
EXPECT_THROWS(assertTypeExpansion("levelist", {"20", "to", "4", "by", "4"}, {"4", "8", "12", "16", "20"})); | ||
// by = 0 | ||
assertTypeExpansion("levelist", {"4", "to", "20", "by", "0"}, {"4"}); | ||
assertTypeExpansion("levelist", {"-1", "to", "2", "by", "0"}, {"-1"}); | ||
// by < 0 && from > to | ||
assertTypeExpansion("levelist", {"10", "to", "4", "by", "-2"}, {"10", "8", "6", "4"}); | ||
assertTypeExpansion("levelist", {"-2", "to", "-4", "by", "-0.5"}, {"-2", "-2.5", "-3", "-3.5", "-4"}); | ||
assertTypeExpansion("levelist", {"0", "to", "-2", "by", "-0.5"}, {"0", "-0.5", "-1", "-1.5", "-2"}); | ||
// by < 0 && from < to | ||
EXPECT_THROWS(assertTypeExpansion("levelist", {"4", "to", "10", "by", "-4"}, {"4", "8", "12", "16", "20"})); | ||
EXPECT_THROWS(assertTypeExpansion("levelist", {"-4", "to", "2", "by", "-0.5"}, {"0", "-0.5", "-1", "-1.5", "-2"})); | ||
// by < 0 && from < to | ||
EXPECT_THROWS(assertTypeExpansion("levelist", {"-1", "to", "2", "by", "-0.5"}, {"-1"})); | ||
} | ||
|
||
} // namespace test | ||
} // namespace mars | ||
} // namespace metkit | ||
|
||
//----------------------------------------------------------------------------- | ||
|
||
int main(int argc, char** argv) { | ||
return run_tests(argc, argv); | ||
} |