Update tz validation test with more checking

This commit is contained in:
Howard Hinnant 2016-04-17 21:51:30 -04:00
parent 70f7d52f88
commit d8426940d7
2 changed files with 80 additions and 0 deletions

Binary file not shown.

View File

@ -1,6 +1,83 @@
#include "tz.h" #include "tz.h"
#include <iostream> #include <iostream>
void
test_info(const date::Zone* zone, const date::Info& info)
{
using namespace date;
using namespace std::chrono;
auto begin = info.begin;
auto end = info.end - microseconds{1};
auto mid = begin + (end - begin) /2 ;
if (begin > day_point{jan/1/1700})
{
auto local = zone->to_local(begin).first;
auto prev_local = zone->to_local(begin - seconds{1}).first;
if (prev_local < local - seconds{1})
{
assert(zone->to_sys(local) == begin);
auto imaginary = prev_local + (local - seconds{1} - prev_local) / 2;
try
{
zone->to_sys(imaginary);
assert(false);
}
catch (const nonexistent_local_time&)
{
}
}
else if (prev_local > local - seconds{1})
{
auto ambiguous = local - seconds{1} +
(prev_local - (local - seconds{1})) / 2;
try
{
zone->to_sys(ambiguous);
assert(false);
}
catch (const ambiguous_local_time&)
{
}
}
}
auto local = zone->to_local(mid).first;
assert(zone->to_sys(local) == mid);
if (end < day_point{jan/1/3000})
{
auto local = zone->to_local(end).first;
auto next_local = zone->to_local(info.end).first;
if (next_local < local + microseconds{1})
{
auto ambiguous = next_local + (local + microseconds{1} - next_local) / 2;
try
{
zone->to_sys(ambiguous);
assert(false);
}
catch (const ambiguous_local_time&)
{
}
}
else if (next_local > local + microseconds{1})
{
assert(zone->to_sys(local) == end);
auto imaginary = local + microseconds{1} +
(next_local - (local + microseconds{1})) / 2;
try
{
zone->to_sys(imaginary);
assert(false);
}
catch (const nonexistent_local_time&)
{
}
}
}
}
int int
main() main()
{ {
@ -14,6 +91,7 @@ main()
for (auto& link : db.links) for (auto& link : db.links)
names.push_back(link.name()); names.push_back(link.name());
std::sort(names.begin(), names.end()); std::sort(names.begin(), names.end());
std::cout << db.version << "\n\n";
for (auto const& name : names) for (auto const& name : names)
{ {
std::cout << name << '\n'; std::cout << name << '\n';
@ -30,12 +108,14 @@ main()
else else
std::cout << " daylight "; std::cout << " daylight ";
std::cout << info.abbrev << '\n'; std::cout << info.abbrev << '\n';
test_info(z, info);
auto prev_offset = info.offset; auto prev_offset = info.offset;
auto prev_abbrev = info.abbrev; auto prev_abbrev = info.abbrev;
auto prev_save = info.save; auto prev_save = info.save;
for (begin = info.end; begin < end; begin = info.end) for (begin = info.end; begin < end; begin = info.end)
{ {
info = z->get_info(begin, tz::utc); info = z->get_info(begin, tz::utc);
test_info(z, info);
if (info.offset == prev_offset && info.abbrev == prev_abbrev && if (info.offset == prev_offset && info.abbrev == prev_abbrev &&
info.save == prev_save) info.save == prev_save)
continue; continue;