[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 0fcb08d 1/2: Require any report table to cont
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 0fcb08d 1/2: Require any report table to contain at least one column |
Date: |
Sun, 2 Jun 2019 18:32:14 -0400 (EDT) |
branch: master
commit 0fcb08d5b5d215e5a482602fb41c778a682c64e0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Require any report table to contain at least one column
Asserted a precondition; unit-tested the assertion. The reproducible
test case here:
https://lists.nongnu.org/archive/html/lmi/2019-05/msg00010.html
now results in this improved diagnostic:
Report table would contain no columns.
---
report_table.cpp | 7 +++++++
report_table_test.cpp | 8 ++++++++
2 files changed, 15 insertions(+)
diff --git a/report_table.cpp b/report_table.cpp
index 29e30ef..06c681f 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -95,6 +95,8 @@ std::vector<int> apportion(std::vector<int> const& votes, int
total_seats)
/// First, allocate adequate width to each inelastic column; then
/// distribute any excess width left over among elastic columns.
///
+/// Asserted precondition: the number of columns passed is not zero.
+///
/// Notes on arguments:
/// all_columns: the width of each inelastic column reflects:
/// - the header width, and
@@ -114,6 +116,11 @@ std::vector<int> set_column_widths
{
LMI_ASSERT(minimum_margin <= desired_margin);
int const cardinality = lmi::ssize(all_columns);
+ if(0 == cardinality)
+ {
+ alarum() << "Report table would contain no columns." << LMI_FLUSH;
+ }
+
int data_width = 0;
int n_columns_to_show = 0;
for(int j = 0, cum_min_width = 0; j < cardinality; ++j)
diff --git a/report_table_test.cpp b/report_table_test.cpp
index a33d4c6..ba94798 100644
--- a/report_table_test.cpp
+++ b/report_table_test.cpp
@@ -230,6 +230,14 @@ void report_table_test::test_column_widths_generally()
,"Not enough room for even the first column."
);
+ // Report with zero columns.
+ v = bloat({}, {});
+ BOOST_TEST_THROW
+ (set_column_widths(v, 1, 2, 1)
+ ,std::runtime_error
+ ,"Report table would contain no columns."
+ );
+
// Minimum margin greater than one.
v = bloat({1, 2, 3}, {0, 0, 0});
observed = set_column_widths(v, 16, 5, 3);