[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 327cb78 1/2: Allow printing illustrations tha
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 327cb78 1/2: Allow printing illustrations that lapse in first year |
Date: |
Sun, 2 Sep 2018 05:15:13 -0400 (EDT) |
branch: master
commit 327cb7857de3c1ab08694e140ff212effbe35bdf
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Allow printing illustrations that lapse in first year
If this threw an exception, and every 1000th cell in a 10000-cell group
lapsed in the first year, then the end user would have to run the case
ten times, producing 999, 1999, ... 9999, 10000 PDFs on successive time-
consuming runs and editing the census by hand after each failure.
---
miscellany.cpp | 12 ++++++++----
miscellany_test.cpp | 7 ++++---
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/miscellany.cpp b/miscellany.cpp
index 1125b13..e21af0d 100644
--- a/miscellany.cpp
+++ b/miscellany.cpp
@@ -295,7 +295,7 @@ std::string iso_8601_datestamp_terse()
/// Compute the number of pages needed to display the given number of non-blank
/// rows in groups of the specified size separated by blank rows.
///
-/// Preconditions: 0 < total_rows && 0 < rows_per_group <= rows_per_page
+/// Preconditions: 0 <= total_rows && 0 < rows_per_group <= rows_per_page
int page_count
(int total_rows
@@ -303,9 +303,13 @@ int page_count
,int rows_per_page
)
{
- LMI_ASSERT(0 < total_rows);
- LMI_ASSERT(0 < rows_per_group );
- LMI_ASSERT( rows_per_group <= rows_per_page);
+ LMI_ASSERT(0 <= total_rows);
+ LMI_ASSERT(0 < rows_per_group );
+ LMI_ASSERT( rows_per_group <= rows_per_page);
+
+ // If there are zero rows of data, then one empty page is wanted.
+ if(0 == total_rows)
+ return 1;
// Each group actually takes rows_per_group+1 rows because of the
// separator row between groups, hence the second +1, but there is no
diff --git a/miscellany_test.cpp b/miscellany_test.cpp
index 8f04677..eaafa73 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -156,7 +156,8 @@ void test_page_count()
{
// Original tests: vary only the number of data rows.
- // Edge case (0 rows is not allowed).
+ // Edge cases.
+ BOOST_TEST_EQUAL(1, page_count( 0, 5, 28));
BOOST_TEST_EQUAL(1, page_count( 1, 5, 28));
// Just a trivial sanity test.
BOOST_TEST_EQUAL(1, page_count(17, 5, 28));
@@ -171,9 +172,9 @@ void test_page_count()
// Test preconditions.
- // No data rows.
+ // Negative number of data rows.
BOOST_TEST_THROW
- (page_count(0, 1, 1)
+ (page_count(-1, 1, 1)
,std::runtime_error
,lmi_test::what_regex("^Assertion.*failed")
);