From 0502e1e2d43d6a8ac78110313c7fb90f79080f7a Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sat, 16 Jul 2016 19:40:20 -0400 Subject: [PATCH] test test test --- include/xlnt/worksheet/range.hpp | 6 ---- source/utils/date.cpp | 2 ++ source/utils/tests/test_datetime.hpp | 40 +++++++++++++++++++++++ source/utils/tests/test_timedelta.hpp | 19 +++++++++++ source/utils/timedelta.cpp | 6 ++++ source/worksheet/range.cpp | 20 ------------ source/worksheet/tests/test_worksheet.hpp | 15 +++++++-- 7 files changed, 80 insertions(+), 28 deletions(-) diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index 2fb6d2a1..f70878eb 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -77,12 +77,6 @@ public: bool contains(const cell_reference &ref); - cell_vector front(); - const cell_vector front() const; - - cell_vector back(); - const cell_vector back() const; - iterator begin(); iterator end(); diff --git a/source/utils/date.cpp b/source/utils/date.cpp index 0aa09097..c85fa77d 100644 --- a/source/utils/date.cpp +++ b/source/utils/date.cpp @@ -61,6 +61,8 @@ date date::from_number(int days_since_base_year, calendar base_date) result.day = 29; result.month = 2; result.year = 1900; + + return result; } else if (days_since_base_year < 60) { diff --git a/source/utils/tests/test_datetime.hpp b/source/utils/tests/test_datetime.hpp index fd7dc488..6ef17c89 100644 --- a/source/utils/tests/test_datetime.hpp +++ b/source/utils/tests/test_datetime.hpp @@ -39,4 +39,44 @@ public: TS_ASSERT_EQUALS(rollover.second, 00); TS_ASSERT_EQUALS(rollover.microsecond, 00); } + + void test_leap_year_bug() + { + xlnt::datetime dt(1900, 2, 29, 0, 0, 0, 0); + auto number = dt.to_number(xlnt::calendar::windows_1900); + TS_ASSERT_EQUALS(static_cast(number), 60); + auto converted = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900); + TS_ASSERT_EQUALS(dt, converted); + } + + void test_early_date() + { + xlnt::date d(1900, 1, 29); + auto number = d.to_number(xlnt::calendar::windows_1900); + TS_ASSERT_EQUALS(number, 29); + auto converted = xlnt::date::from_number(number, xlnt::calendar::windows_1900); + TS_ASSERT_EQUALS(d, converted); + } + + void test_mac_calendar() + { + xlnt::date d(2016, 7, 16); + auto number_1900 = d.to_number(xlnt::calendar::windows_1900); + auto number_1904 = d.to_number(xlnt::calendar::mac_1904); + TS_ASSERT_EQUALS(number_1900, 42567); + TS_ASSERT_EQUALS(number_1904, 41105); + auto converted_1900 = xlnt::date::from_number(number_1900, xlnt::calendar::windows_1900); + auto converted_1904 = xlnt::date::from_number(number_1904, xlnt::calendar::mac_1904); + TS_ASSERT_EQUALS(converted_1900, d); + TS_ASSERT_EQUALS(converted_1904, d); + } + + void test_operators() + { + xlnt::date d1(2016, 7, 16); + xlnt::date d2(2016, 7, 16); + xlnt::date d3(2016, 7, 15); + TS_ASSERT_EQUALS(d1, d2); + TS_ASSERT_DIFFERS(d1, d3); + } }; diff --git a/source/utils/tests/test_timedelta.hpp b/source/utils/tests/test_timedelta.hpp index fc214f64..ed0206be 100644 --- a/source/utils/tests/test_timedelta.hpp +++ b/source/utils/tests/test_timedelta.hpp @@ -30,4 +30,23 @@ public: xlnt::timedelta td(1, 1, 1, 1, 1); TS_ASSERT_EQUALS(td.to_number(), 1.0423726852L); } + + void test_carry() + { + // We want a time that rolls over to the next second, minute, and hour + // Start off with a time 1 microsecond before the next hour + xlnt::timedelta td(1, 23, 59, 59, 999999); + auto number = td.to_number(); + + // Add 600 nanoseconds to the raw number which represents time as a fraction of a day + // In other words, 6 tenths of a millionth of a sixtieth of a sixtieth of a twenty-fourth of a day + number += (0.6 / 1000000) / 60 / 60 / 24; + auto rollover = xlnt::timedelta::from_number(number); + + TS_ASSERT_EQUALS(rollover.days, 2); + TS_ASSERT_EQUALS(rollover.hours, 0); + TS_ASSERT_EQUALS(rollover.minutes, 0); + TS_ASSERT_EQUALS(rollover.seconds, 0); + TS_ASSERT_EQUALS(rollover.microseconds, 0); + } }; diff --git a/source/utils/timedelta.cpp b/source/utils/timedelta.cpp index b1bf191f..33a3de6e 100644 --- a/source/utils/timedelta.cpp +++ b/source/utils/timedelta.cpp @@ -88,6 +88,12 @@ timedelta timedelta::from_number(long double raw_time) { result.minutes = 0; result.hours += 1; + + if (result.hours == 24) + { + result.hours = 0; + result.days += 1; + } } } } diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index d3daa415..90d8ea65 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -97,26 +97,6 @@ cell range::get_cell(const cell_reference &ref) return (*this)[ref.get_row() - 1][ref.get_column().index - 1]; } -cell_vector range::front() -{ - return *begin(); -} - -const cell_vector range::front() const -{ - return *cbegin(); -} - -cell_vector range::back() -{ - return *(--end()); -} - -const cell_vector range::back() const -{ - return *(--cend()); -} - range::iterator range::begin() { if (order_ == major_order::row) diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 53c5f8fb..5181023d 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -1061,8 +1061,19 @@ public: ws.get_cell("B3").set_value(false); auto range = ws.get_range("A2:B3"); - TS_ASSERT_EQUALS((*(*range.begin()).begin()).get_value(), 3.14); - TS_ASSERT_EQUALS((*(--(*(--range.end())).end())).get_value(), false); + auto range_iter = range.begin(); + auto row = *range_iter; + auto row_iter = row.begin(); + auto cell = *row_iter; + TS_ASSERT_EQUALS(cell.get_value(), 3.14); + + range_iter = range.end(); + range_iter--; + row = *range_iter; + row_iter = row.end(); + row_iter--; + cell = *row_iter; + TS_ASSERT_EQUALS(cell.get_value(), false); } void test_get_squared_range()