From 82f33a9ca42cb517723e31b5bfacd71f4024d469 Mon Sep 17 00:00:00 2001 From: Metin Cakircali Date: Tue, 21 Nov 2023 13:19:06 +0100 Subject: [PATCH 1/8] fix typo --- src/metkit/mars/TypeToByListFloat.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metkit/mars/TypeToByListFloat.cc b/src/metkit/mars/TypeToByListFloat.cc index 24fbce3d..b7eedd27 100644 --- a/src/metkit/mars/TypeToByListFloat.cc +++ b/src/metkit/mars/TypeToByListFloat.cc @@ -61,7 +61,7 @@ void TypeToByListFloat::expand(const MarsExpandContext& ctx, std::vector 0, name_ + ": 'by' value must be a positive number"); for (float j = from + by; j <= to; j += by) { newval.push_back(l2s(j)); From dd3f2bed20a9f3889d9ea5d3297c0dd58aae56bf Mon Sep 17 00:00:00 2001 From: Metin Cakircali Date: Tue, 21 Nov 2023 13:23:29 +0100 Subject: [PATCH 2/8] add detail to assert msg --- src/metkit/mars/TypeToByListFloat.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/metkit/mars/TypeToByListFloat.cc b/src/metkit/mars/TypeToByListFloat.cc index b7eedd27..3450cb0b 100644 --- a/src/metkit/mars/TypeToByListFloat.cc +++ b/src/metkit/mars/TypeToByListFloat.cc @@ -61,8 +61,9 @@ void TypeToByListFloat::expand(const MarsExpandContext& ctx, std::vector 0, name_ + ": 'by' value must be a positive number"); + ASSERT_MSG(from <= to, name_ + ": [" + std::to_string(from) + "] value must be less than [" + + std::to_string(to) + "] value!"); + ASSERT_MSG(by > 0, name_ + ": [" + std::to_string(by) + "] value must be a positive number!"); for (float j = from + by; j <= to; j += by) { newval.push_back(l2s(j)); } From 98440cba734ae198a813f078a2f81efafefa8725 Mon Sep 17 00:00:00 2001 From: Metin Cakircali Date: Tue, 21 Nov 2023 14:19:46 +0100 Subject: [PATCH 3/8] add support for by < 0 --- src/metkit/mars/TypeToByListFloat.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/metkit/mars/TypeToByListFloat.cc b/src/metkit/mars/TypeToByListFloat.cc index 3450cb0b..ee7a9dec 100644 --- a/src/metkit/mars/TypeToByListFloat.cc +++ b/src/metkit/mars/TypeToByListFloat.cc @@ -61,11 +61,14 @@ void TypeToByListFloat::expand(const MarsExpandContext& ctx, std::vector 0, name_ + ": [" + std::to_string(by) + "] value must be a positive number!"); - for (float j = from + by; j <= to; j += by) { - newval.push_back(l2s(j)); + if (by > 0) { + ASSERT_MSG(from <= to, name_ + ": [" + std::to_string(from) + "] value must be less than [" + + std::to_string(to) + "] value!"); + for (float j = from + by; j <= to; j += by) { newval.push_back(l2s(j)); } + } else if (by < 0) { + ASSERT_MSG(from >= to, name_ + ": [" + std::to_string(from) + "] value must be greater than [" + + std::to_string(to) + "] value!"); + for (float j = from + by; j >= to; j += by) { newval.push_back(l2s(j)); } } i++; From efde4c90618f13a9eeac9df05f4d4490ddc40d00 Mon Sep 17 00:00:00 2001 From: Metin Cakircali Date: Tue, 21 Nov 2023 14:21:08 +0100 Subject: [PATCH 4/8] add test for levelist --- tests/CMakeLists.txt | 2 +- tests/test_type_levelist.cc | 78 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/test_type_levelist.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 05a781a3..af06050d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,7 +61,7 @@ ecbuild_add_test( TARGET metkit_test_odbsplitter NO_AS_NEEDED LIBS metkit ) -list(APPEND testFileSuffixes typesfactory expand param_axis steprange_axis time hypercube ) +list(APPEND testFileSuffixes typesfactory expand param_axis steprange_axis time hypercube type_levelist ) foreach(test IN LISTS testFileSuffixes) ecbuild_add_test( TARGET "metkit_test_${test}" diff --git a/tests/test_type_levelist.cc b/tests/test_type_levelist.cc new file mode 100644 index 00000000..c5109154 --- /dev/null +++ b/tests/test_type_levelist.cc @@ -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 values, + const std::vector& 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); +} From 81161baa8572d3ff443ad727d27b6c93c85da97f Mon Sep 17 00:00:00 2001 From: Metin Cakircali Date: Tue, 21 Nov 2023 15:02:09 +0100 Subject: [PATCH 5/8] remove redundant check --- tests/test_type_levelist.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_type_levelist.cc b/tests/test_type_levelist.cc index c5109154..1f32a1c0 100644 --- a/tests/test_type_levelist.cc +++ b/tests/test_type_levelist.cc @@ -63,8 +63,6 @@ CASE("test_metkit_expand_levelist") { // 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 From 9d1f9bb35c696cb1a05fc379f4987ffd9abb2559 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Fri, 8 Dec 2023 14:09:41 +0000 Subject: [PATCH 6/8] version bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6323875d..1cac385c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.20 +1.11.0 From fc407e494cf1f77176c11e5930e4f4853832c021 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Tue, 2 Jan 2024 14:55:40 +0000 Subject: [PATCH 7/8] fix unit test --- tests/marsgen/metkit_marsgen_obs.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/marsgen/metkit_marsgen_obs.sh.in b/tests/marsgen/metkit_marsgen_obs.sh.in index b6cbf2a8..d9222f64 100755 --- a/tests/marsgen/metkit_marsgen_obs.sh.in +++ b/tests/marsgen/metkit_marsgen_obs.sh.in @@ -2,7 +2,7 @@ set -uex -[ -e outfile.simple ] && rm outfile.simple +[ -e outfile.obs ] && rm outfile.obs MARSGEN="@CMAKE_BINARY_DIR@/bin/mars-archive-script" GENFILE="@CMAKE_CURRENT_SOURCE_DIR@/genfile" From 36d1d22ba8de71b9238eacbe5bfb78ed5ce77782 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Tue, 9 Jan 2024 09:02:39 +0000 Subject: [PATCH 8/8] version bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1cac385c..720c7384 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.11.0 +1.11.1