[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 9cab906 2/3: Assert all documented preconditi
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 9cab906 2/3: Assert all documented preconditions; unit-test those assertions |
Date: |
Mon, 12 Feb 2018 19:54:22 -0500 (EST) |
branch: master
commit 9cab906839ebef8023e34e4d4e83bbd4f8c14839
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Assert all documented preconditions; unit-test those assertions
---
miscellany.cpp | 7 +++----
miscellany_test.cpp | 21 ++++++++++++++-------
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/miscellany.cpp b/miscellany.cpp
index a0825af..54a4343 100644
--- a/miscellany.cpp
+++ b/miscellany.cpp
@@ -219,10 +219,9 @@ int page_count
,int rows_per_page
)
{
- // The caller must check for this precondition because this function is too
- // low-level to be able to handle it correctly, e.g. it can't even use the
- // appropriate error message.
- 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);
// 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 7008ebc..8c483e5 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -170,18 +170,25 @@ void test_page_count()
// Test preconditions.
- // No data rows--doesn't actually throw.
-// BOOST_TEST_THROW
-// (page_count(0, 1, 1)
-// ,std::runtime_error
-// ,""
-// );
+ // No data rows.
+ BOOST_TEST_THROW
+ (page_count(0, 1, 1)
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Assertion.*failed")
+ );
+
+ // Zero rows per group.
+ BOOST_TEST_THROW
+ (page_count(1, 0, 1)
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Assertion.*failed")
+ );
// Insufficient room to print even one group.
BOOST_TEST_THROW
(page_count(1, 7, 3)
,std::runtime_error
- ,""
+ ,lmi_test::what_regex("^Assertion.*failed")
);
// A single row of data.