Skip to content

Commit

Permalink
test hpe ok
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthospap committed Oct 22, 2024
1 parent f8a6c00 commit 43baf90
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/datetime_interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class datetime_interval {
m_secs = S(s);
m_days = core::copysign(days, 1);
#ifdef DEBUG
assert(m_days >= 0 && (m_secs >= 0 && m_secs < S::max_in_day));
assert(m_days >= 0 && (m_secs >= S(0) && m_secs < S(S::max_in_day)));
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions include/hms_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#define __DSO_DATETIME_HMSTIME_HPP__

#include "time_int2flt.hpp"
#ifdef DEBUG
#include <cassert>
#endif

namespace dso {

Expand Down
8 changes: 4 additions & 4 deletions test/sofa/epj_date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ int main() {
TwoPartDate di = epj2tpd(je);
assert(d.imjd() - di.imjd() == 0);
#ifdef DEBUG
if (std::abs(d.seconds() - di.seconds()) > maxdiffs[0])
maxdiffs[0] = std::abs(d.seconds() - di.seconds());
avediffs[0] += std::abs(d.seconds() - di.seconds());
if (std::abs(d.seconds().seconds() - di.seconds().seconds()) > maxdiffs[0])
maxdiffs[0] = std::abs(d.seconds().seconds() - di.seconds().seconds());
avediffs[0] += std::abs(d.seconds().seconds() - di.seconds().seconds());
#endif
epj_lib = je;

/* compare initial to resulting dates */
assert(fequal(d.seconds(), di.seconds(), 1e-5));
assert(fequal(d.seconds().seconds(), di.seconds().seconds(), 1e-5));
}

/* do the same with SOFA */
Expand Down
22 changes: 14 additions & 8 deletions test/unit_tests/dread3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ template <typename T> /* T is either TwoPartDate or TwoPartDateUTC */
inline bool fequal(const T &a, const T &b, double seceps = EPSILON) noexcept {
if (a.imjd() != b.imjd())
return false;
if (std::abs(a.seconds() - b.seconds()) <= seceps)
if (std::abs(a.seconds().seconds() - b.seconds().seconds()) <= seceps)
return true;
return std::abs(a.seconds() - b.seconds()) <=
(seceps * std::max(std::abs(a.seconds()), std::abs(b.seconds())));
return std::abs(a.seconds().seconds() - b.seconds().seconds()) <=
(seceps * std::max(std::abs(a.seconds().seconds()),
std::abs(b.seconds().seconds())));
}
/* see https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon */
template <class T>
Expand Down Expand Up @@ -141,15 +142,17 @@ int main() {
std::strcat(buf1, s_2359599);
d1 = from_char<YMDFormat::YYYYMMDD, HMSFormat::HHMMSSF>(buf1);
assert(fequal(d1, tai));
assert(equal_within_ulps(d1.seconds(), tai.seconds(), 1));
assert(equal_within_ulps(d1.seconds().seconds(), tai.seconds().seconds(),
1));

/* one more nanosec will take to the next day */
tai.add_seconds(FractionalSeconds(1e-9), err);
assert(tai.imjd() == d1.imjd() + 1);
d1 = TwoPartDate(modified_julian_day(d).as_underlying_type() + 1,
FractionalSeconds(0e0));
assert(fequal(d1, tai));
assert(equal_within_ulps(d1.seconds(), tai.seconds(), 1));
assert(equal_within_ulps(d1.seconds().seconds(), tai.seconds().seconds(),
1));
}

TwoPartDateUTC utc(modified_julian_day(d).as_underlying_type(),
Expand All @@ -175,7 +178,8 @@ int main() {
std::strcat(buf1, s_2359599);
d1 = from_utc_char<YMDFormat::YYYYMMDD, HMSFormat::HHMMSSF>(buf1);
assert(fequal(d1, utc));
assert(equal_within_ulps(d1.seconds(), utc.seconds(), 1));
assert(equal_within_ulps(d1.seconds().seconds(), utc.seconds().seconds(),
1));

/* one more nanosec will take to next second, NOT the next day */
utc.add_seconds(FractionalSeconds(1e-9), err);
Expand All @@ -185,13 +189,15 @@ int main() {
std::strcat(buf1, s_235960);
d1 = from_utc_char<YMDFormat::YYYYMMDD, HMSFormat::HHMMSSF>(buf1);
assert(fequal(d1, utc));
assert(equal_within_ulps(d1.seconds(), utc.seconds(), 1));
assert(equal_within_ulps(d1.seconds().seconds(), utc.seconds().seconds(),
1));
/* equal to YYYY-MM-DD 23:59:60.000000000 */
std::strcat(reset_buffer(buf1), leap_insertion_dates_str[it]);
std::strcat(buf1, s_2359600);
d1 = from_utc_char<YMDFormat::YYYYMMDD, HMSFormat::HHMMSSF>(buf1);
assert(fequal(d1, utc));
assert(equal_within_ulps(d1.seconds(), utc.seconds(), 1));
assert(equal_within_ulps(d1.seconds().seconds(), utc.seconds().seconds(),
1));
}

/* augment string index */
Expand Down

0 comments on commit 43baf90

Please sign in to comment.