mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
test test test
This commit is contained in:
parent
f614c737f5
commit
0502e1e2d4
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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<int>(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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<double>(), 3.14);
|
||||
TS_ASSERT_EQUALS((*(--(*(--range.end())).end())).get_value<bool>(), 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<double>(), 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<bool>(), false);
|
||||
}
|
||||
|
||||
void test_get_squared_range()
|
||||
|
|
Loading…
Reference in New Issue
Block a user