correct off-by-one error in range dimension calculation, closes #213

This commit is contained in:
Thomas Fussell 2017-09-08 20:47:10 -04:00
parent 0d125b1534
commit 7d0cf59286
3 changed files with 18 additions and 4 deletions

View File

@ -109,7 +109,7 @@ const cell cell_vector::back() const
std::size_t cell_vector::length() const
{
return order_ == major_order::row ? bounds_.width() + 1 : bounds_.height() + 1;
return order_ == major_order::row ? bounds_.width() : bounds_.height();
}
cell_vector::const_iterator cell_vector::begin() const

View File

@ -90,17 +90,17 @@ range_reference range_reference::make_offset(int column_offset, int row_offset)
std::size_t range_reference::height() const
{
return bottom_right_.row() - top_left_.row();
return 1 + bottom_right_.row() - top_left_.row();
}
std::size_t range_reference::width() const
{
return (bottom_right_.column() - top_left_.column()).index;
return 1 + (bottom_right_.column() - top_left_.column()).index;
}
bool range_reference::is_single_cell() const
{
return width() == 0 && height() == 0;
return width() == 1 && height() == 1;
}
std::string range_reference::to_string() const

View File

@ -93,6 +93,7 @@ public:
register_test(test_get_point_pos);
register_test(test_named_range_named_cell_reference);
register_test(test_iteration_skip_empty);
register_test(test_dimensions);
}
void test_new_worksheet()
@ -1088,4 +1089,17 @@ public:
xlnt_assert_equals(cells[1].value<std::string>(), "F6");
}
}
void test_dimensions()
{
xlnt::workbook workbook;
workbook.load(path_helper::test_file("4_every_style.xlsx"));
auto active_sheet = workbook.active_sheet();
auto sheet_range = active_sheet.calculate_dimension();
xlnt_assert(!sheet_range.is_single_cell());
xlnt_assert_equals(sheet_range.width(), 4);
xlnt_assert_equals(sheet_range.height(), 35);
}
};