Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #165

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Viewer/ecflowUI/src/VRepeatAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "VAttributeType.hpp"
#include "VNode.hpp"
#include "ecflow/attribute/RepeatRange.hpp"
#include "ecflow/core/Cal.hpp"
#include "ecflow/core/Calendar.hpp"

std::string VRepeatDateAttr::subType_("date");
std::string VRepeatDateTimeAttr::subType_("datetime");
Expand Down Expand Up @@ -195,8 +195,8 @@ int VRepeatDateAttr::endIndex() const {
if (node_ptr node = parent_->node()) {
const Repeat& r = node->repeat();
if (r.step() > 0) {
long jStart = Cal::date_to_julian(r.start());
long jEnd = Cal::date_to_julian(r.end());
long jStart = ecf::CalendarDate(r.start()).as_julian_day().value();
long jEnd = ecf::CalendarDate(r.end()).as_julian_day().value();

int index = (jEnd - jStart) / r.step();
long val = jStart + index * r.step();
Expand All @@ -213,7 +213,9 @@ int VRepeatDateAttr::endIndex() const {
int VRepeatDateAttr::currentIndex() const {
if (node_ptr node = parent_->node()) {
const Repeat& r = node->repeat();
int cur = (Cal::date_to_julian(r.index_or_value()) - Cal::date_to_julian(r.start())) / r.step();
int cur = (ecf::CalendarDate(r.index_or_value()).as_julian_day().value() -
ecf::CalendarDate(r.start()).as_julian_day().value()) /
r.step();
return cur;
}
return 0;
Expand All @@ -239,7 +241,8 @@ std::string VRepeatDateAttr::value(int index) const {
std::stringstream ss;
if (node_ptr node = parent_->node()) {
const Repeat& r = node->repeat();
ss << (Cal::julian_to_date(Cal::date_to_julian(r.start()) + index * r.step()));
auto date = ecf::CalendarDate(r.start()) + (index * r.step());
ss << date.value();
}

return ss.str();
Expand All @@ -252,7 +255,7 @@ int VRepeatDateAttr::currentPosition() const {
return -1;
else if (r.value() == r.start())
return 0;
else if (r.value() == r.end() || Cal::date_to_julian(r.value()) + r.step() > Cal::date_to_julian(r.end()))
else if (r.value() == r.end() || ecf::CalendarDate(r.value()) + r.step() > ecf::CalendarDate(r.end()))
return 2;
else
return 1;
Expand All @@ -272,7 +275,7 @@ int VRepeatDateTimeAttr::endIndex() const {
auto& r = node->repeat();
auto rng = ecf::make_range<RepeatDateTime>(r);
auto idx = rng.end();
idx = std::min(idx, rng.size() - 1); // ensure idx is within range [0, size-1]
idx = std::min(idx, rng.size() - 1); // ensure idx is within range [0, size-1]
return idx;
}
return 0;
Expand Down
2 changes: 0 additions & 2 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ set(srcs
${CMAKE_BINARY_DIR}/generated/src/ecflow/core/ecflow_version.h
${CMAKE_BINARY_DIR}/generated/src/ecflow/core/ecflow_source_build_dir.h
core/src/ecflow/core/AssertTimer.hpp
core/src/ecflow/core/Cal.hpp
core/src/ecflow/core/Calendar.hpp
core/src/ecflow/core/CalendarUpdateParams.hpp
core/src/ecflow/core/CheckPt.hpp
Expand Down Expand Up @@ -279,7 +278,6 @@ set(srcs
core/src/ecflow/core/exceptions/Exceptions.hpp
# Core -- Sources
core/src/ecflow/core/AssertTimer.cpp
core/src/ecflow/core/Cal.cpp
core/src/ecflow/core/Calendar.cpp
core/src/ecflow/core/Child.cpp
core/src/ecflow/core/Chrono.cpp
Expand Down
51 changes: 17 additions & 34 deletions libs/attribute/src/ecflow/attribute/RepeatAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <boost/date_time.hpp>
#include <boost/date_time/posix_time/time_parsers.hpp>

#include "ecflow/core/Cal.hpp"
#include "ecflow/core/Calendar.hpp"
#include "ecflow/core/Converter.hpp"
#include "ecflow/core/Ecf.hpp"
#include "ecflow/core/Indentor.hpp"
Expand Down Expand Up @@ -260,8 +260,7 @@ void RepeatDate::update_repeat_genvar_value() const {
dow_.set_value(ecf::convert_to<std::string>(day_of_week));

long last_value = last_valid_value();
long julian = Cal::date_to_julian(last_value);
julian_.set_value(ecf::convert_to<std::string>(julian));
julian_.set_value(ecf::convert_to<std::string>(ecf::CalendarDate(last_value).as_julian_day().value()));
}
catch (std::exception& e) {
std::stringstream ss;
Expand Down Expand Up @@ -304,17 +303,13 @@ long RepeatDate::valid_value(long value) const {
}

long RepeatDate::last_valid_value_minus(int val) const {
long last_value = last_valid_value();
long julian = Cal::date_to_julian(last_value);
julian -= val;
return Cal::julian_to_date(julian);
auto result = ecf::CalendarDate(last_valid_value()) - val;
return result.value();
}

long RepeatDate::last_valid_value_plus(int val) const {
long last_value = last_valid_value();
long julian = Cal::date_to_julian(last_value);
julian += val;
return Cal::julian_to_date(julian);
auto result = ecf::CalendarDate(last_valid_value()) + val;
return result.value();
}

void RepeatDate::reset() {
Expand Down Expand Up @@ -384,11 +379,8 @@ std::string RepeatDate::value_as_string(int index) const {
}

std::string RepeatDate::next_value_as_string() const {
long val = last_valid_value();

long julian = Cal::date_to_julian(val);
julian += delta_;
val = Cal::julian_to_date(julian);
auto result = ecf::CalendarDate(last_valid_value()) + delta_;
long val = result.value();

try {
return ecf::convert_to<std::string>(valid_value(val));
Expand All @@ -399,11 +391,8 @@ std::string RepeatDate::next_value_as_string() const {
}

std::string RepeatDate::prev_value_as_string() const {
long val = last_valid_value();

long julian = Cal::date_to_julian(val);
julian -= delta_;
val = Cal::julian_to_date(julian);
auto result = ecf::CalendarDate(last_valid_value()) - delta_;
long val = result.value();

try {
return ecf::convert_to<std::string>(valid_value(val));
Expand All @@ -414,9 +403,8 @@ std::string RepeatDate::prev_value_as_string() const {
}

void RepeatDate::increment() {
long julian = Cal::date_to_julian(value_);
julian += delta_;
set_value(Cal::julian_to_date(julian));
auto result = ecf::CalendarDate(last_valid_value()) + delta_;
set_value(result.value());
}

void RepeatDate::change(const std::string& newdate) {
Expand Down Expand Up @@ -469,8 +457,8 @@ void RepeatDate::changeValue(long the_new_date) {
}

// Check new value is in step. ECFLOW-325 repeat date 7
long julian_new_date = Cal::date_to_julian(the_new_date);
long julian_start = Cal::date_to_julian(start_);
long julian_new_date = ecf::CalendarDate(the_new_date).as_julian_day().value();
long julian_start = ecf::CalendarDate(start_).as_julian_day().value();
long diff = julian_new_date - julian_start;
if (diff % delta_ != 0) {
std::stringstream ss;
Expand Down Expand Up @@ -913,8 +901,7 @@ void RepeatDateList::update_repeat_genvar_value() const {
dom_.set_value(ecf::convert_to<std::string>(day_of_month));
dow_.set_value(ecf::convert_to<std::string>(day_of_week));

long last_value = last_valid_value();
long julian = Cal::date_to_julian(last_value);
long julian = CalendarDate(last_valid_value()).as_julian_day().value();
julian_.set_value(ecf::convert_to<std::string>(julian));
}
catch (std::exception& e) {
Expand Down Expand Up @@ -1001,19 +988,15 @@ long RepeatDateList::last_valid_value_minus(int val) const {
if (last_value == 0)
return 0;

long julian = Cal::date_to_julian(last_value);
julian -= val;
return Cal::julian_to_date(julian);
return (CalendarDate(last_value) - val).value();
}

long RepeatDateList::last_valid_value_plus(int val) const {
long last_value = last_valid_value();
if (last_value == 0)
return 0;

long julian = Cal::date_to_julian(last_value);
julian += val;
return Cal::julian_to_date(julian);
return (CalendarDate(last_value) + val).value();
}

void RepeatDateList::setToLastValue() {
Expand Down
1 change: 0 additions & 1 deletion libs/attribute/src/ecflow/attribute/RepeatAttr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <vector>

#include "ecflow/attribute/Variable.hpp"
#include "ecflow/core/Cal.hpp"
#include "ecflow/core/Chrono.hpp"

/////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 7 additions & 6 deletions libs/attribute/src/ecflow/attribute/RepeatRange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define ecflow_attribute_RepeatRange_HPP

#include "ecflow/attribute/RepeatAttr.hpp"
#include "ecflow/core/Calendar.hpp"

namespace ecf {

Expand Down Expand Up @@ -54,25 +55,25 @@ struct Range<RepeatDate>

iterator begin() const { return 0; }
iterator end() const {
int i = Cal::date_to_julian(r_.start());
int j = Cal::date_to_julian(r_.end());
int i = ecf::CalendarDate(r_.start()).as_julian_day().value();
int j = ecf::CalendarDate(r_.end()).as_julian_day().value();
int s = r_.step();
int d = (j - i) + 1;
return (d / s) + ((d % s == 0) ? 0 : 1);
}
iterator current_index() const {
auto i = Cal::date_to_julian(r_.start());
auto i = ecf::CalendarDate(r_.start()).as_julian_day().value();
auto s = r_.step();
auto v = Cal::date_to_julian(r_.value());
auto v = ecf::CalendarDate(r_.value()).as_julian_day().value();
auto idx = (v - i) / s;
return idx;
}

value_type current_value() const { return r_.value(); }

value_type at(iterator i) const {
int j = Cal::date_to_julian(r_.start());
return Cal::julian_to_date(j + i * r_.step());
int j = ecf::CalendarDate(r_.start()).as_julian_day().value();
return ecf::JulianDay(j + i * r_.step()).as_calendar_date().value();
}

size_type size() const { return end() - begin(); }
Expand Down
18 changes: 9 additions & 9 deletions libs/attribute/test/TestRepeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <boost/test/unit_test.hpp>

#include "ecflow/attribute/RepeatAttr.hpp"
#include "ecflow/core/Cal.hpp"
#include "ecflow/core/Calendar.hpp"
#include "ecflow/core/Converter.hpp"
#include "ecflow/test/scaffold/Naming.hpp"

Expand Down Expand Up @@ -530,7 +530,7 @@ BOOST_AUTO_TEST_CASE(generated_variables) {
{
const Variable& var = rep.find_gen_variable("YMD_JULIAN");
BOOST_CHECK_MESSAGE(!var.empty(), "Did not find generated variable YMD_JULIAN");
std::string expected = ecf::convert_to<std::string>(Cal::date_to_julian(20090916));
std::string expected = ecf::convert_to<std::string>(ecf::CalendarDate(20090916).as_julian_day().value());
BOOST_CHECK_MESSAGE(var.theValue() == expected, "expected " << expected << " but found " << var.theValue());
}
}
Expand Down Expand Up @@ -597,13 +597,13 @@ BOOST_AUTO_TEST_CASE(more_generated_variables) {
expected_day_of_week.emplace_back("5");

std::vector<std::string> expected_julian;
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20161231)));
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170101)));
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170102)));
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170103)));
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170104)));
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170105)));
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170106)));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20161231).as_julian_day().value()));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20170101).as_julian_day().value()));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20170102).as_julian_day().value()));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20170103).as_julian_day().value()));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20170104).as_julian_day().value()));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20170105).as_julian_day().value()));
expected_julian.push_back(ecf::convert_to<std::string>(ecf::CalendarDate(20170106).as_julian_day().value()));

for (int i = 0; i < 7; i++) {

Expand Down
71 changes: 0 additions & 71 deletions libs/core/src/ecflow/core/Cal.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions libs/core/src/ecflow/core/Cal.hpp

This file was deleted.

Loading
Loading