lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 212d81a 3/6: Pass the bulky argument of set_c


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 212d81a 3/6: Pass the bulky argument of set_column_widths() by const reference
Date: Thu, 23 Aug 2018 19:59:30 -0400 (EDT)

branch: master
commit 212d81a7a16a7e32fba574e7ade7e66e9d1b8cce
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Pass the bulky argument of set_column_widths() by const reference
    
    Removed internal tests that had depended on modifying that argument.
---
 report_table.cpp       | 15 +++++----------
 report_table.hpp       |  8 ++++----
 report_table_test.cpp  | 31 -------------------------------
 wx_table_generator.cpp |  2 --
 4 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/report_table.cpp b/report_table.cpp
index 84ff8f0..308cc19 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -104,10 +104,10 @@ std::vector<int> apportion(std::vector<int> const& votes, 
int total_seats)
 ///   minimum_margin: minimum margin for every column
 
 std::vector<int> set_column_widths
-    (std::vector<table_column_info>& all_columns
-    ,int                             max_table_width
-    ,int                             desired_margin
-    ,int                             minimum_margin
+    (std::vector<table_column_info> const& all_columns
+    ,int                                   max_table_width
+    ,int                                   desired_margin
+    ,int                                   minimum_margin
     )
 {
     LMI_ASSERT(minimum_margin <= desired_margin);
@@ -170,11 +170,6 @@ std::vector<int> set_column_widths
             << std::flush
             ;
         }
-    // Soon the all_columns argument will be passed by const reference,
-    // and w will be returned by value; until then...
-    for(int j = 0; j < cardinality; ++j)
-        {
-        all_columns[j].col_width_ = w[j];
-        }
+
     return w;
 }
diff --git a/report_table.hpp b/report_table.hpp
index 8d11c47..f650fe4 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -106,10 +106,10 @@ class LMI_SO table_column_info
 std::vector<int> LMI_SO apportion(std::vector<int> const& votes, int seats);
 
 std::vector<int> LMI_SO set_column_widths
-    (std::vector<table_column_info>& all_columns
-    ,int                             max_table_width
-    ,int                             desired_margin
-    ,int                             minimum_margin
+    (std::vector<table_column_info> const& all_columns
+    ,int                                   max_table_width
+    ,int                                   desired_margin
+    ,int                                   minimum_margin
     );
 
 #endif // report_table_hpp
diff --git a/report_table_test.cpp b/report_table_test.cpp
index 0768925..4a5f1e9 100644
--- a/report_table_test.cpp
+++ b/report_table_test.cpp
@@ -71,16 +71,6 @@ int sum(std::vector<int> z)
 {
     return std::accumulate(z.begin(), z.end(), 0);
 }
-
-std::vector<int> widths(std::vector<table_column_info> const& z)
-{
-    std::vector<int> v;
-    for(auto const& j : z)
-        {
-        v.push_back(j.col_width());
-        }
-    return v;
-}
 } // Unnamed namespace.
 
 class report_table_test
@@ -192,13 +182,11 @@ void report_table_test::test_generally()
     observed = set_column_widths(v, 12, 2, 1);
     expected = {3, 4, 5};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Same columns: same layout, even if page is much wider.
     v = bloat({1, 2, 3}, {0, 0, 0});
     observed = set_column_widths(v, 99, 2, 1);
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Same columns, but inadequate page width.
 
@@ -210,14 +198,12 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v, 11, 2, 1);
     expected = {3, 4, 4};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Just enough room for all data with minimum margins.
     v = bloat({1, 2, 3}, {0, 0, 0});
     observed = set_column_widths(v,  9, 2, 1);
     expected = {2, 3, 4};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Not enough room for all data with minimum margins.
     v = bloat({1, 2, 3}, {0, 0, 0});
@@ -225,7 +211,6 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v,  8, 2, 1);
     expected = {3, 4, 0};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Not enough room for all data, even with no margins at all.
     v = bloat({1, 2, 3}, {0, 0, 0});
@@ -233,7 +218,6 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v,  5, 2, 1);
     expected = {2, 3, 0};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Not enough room for even the first column.
     BOOST_TEST_THROW
@@ -247,7 +231,6 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v, 16, 5, 3);
     expected = {5, 5, 6};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // An elastic column occupies all available space not claimed by
     // inelastic columns...
@@ -255,7 +238,6 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v, 99, 2, 1);
     expected = {3, 4, (99-12), 5};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
     // ...though its width might happen to be zero (PDF !! but see
     //   https://lists.nongnu.org/archive/html/lmi/2018-07/msg00049.html
     // which questions whether zero should be allowed):
@@ -263,7 +245,6 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v, 12, 2, 1);
     expected = {3, 4, 0, 5};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Multiple elastic columns apportion all unclaimed space among
     // themselves.
@@ -271,28 +252,24 @@ BOOST_TEST(widths(v) == expected);
     observed = set_column_widths(v, 99, 2, 1);
     expected = {45, 4, 45, 5};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Same, but with nonzero width specified for one elastic column.
     v = bloat({1, 2, 0, 3}, {1, 0, 1, 0});
     observed = set_column_widths(v, 99, 2, 1);
     expected = {46, 4, 44, 5};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Elastic columns only.
     v = bloat({10, 20, 30}, {1, 1, 1});
     observed = set_column_widths(v, 99, 2, 1);
     expected = {23, 33, 43};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 
     // Same columns, but all inelastic.
     v = bloat({10, 20, 30}, {0, 0, 0});
     observed = set_column_widths(v, 99, 2, 1);
     expected = {12, 22, 32};
     BOOST_TEST(observed == expected);
-BOOST_TEST(widths(v) == expected);
 }
 
 /// Test data for an actual group quote.
@@ -321,11 +298,9 @@ void report_table_test::test_group_quote()
 
     std::vector<int> const observed = set_column_widths(v, total_width, 
default_margin, 1);
 
-std::vector<int> const observed2 = widths(v);
     std::vector<int> const expected = {36, 129, 52, 62, 78, 81, 78, 81, 78, 
81};
     BOOST_TEST(total_width == sum(expected));
     BOOST_TEST(observed == expected);
-BOOST_TEST(observed2 == expected);
 }
 
 /// Test data for actual illustrations.
@@ -355,11 +330,9 @@ void report_table_test::test_illustration()
 
     std::vector<int> const observed = set_column_widths(v, total_width, 
default_margin, 1);
 
-std::vector<int> const observed2 = widths(v);
     std::vector<int> const expected = {38, 52, 67, 66, 45, 62, 62, 67};
     BOOST_TEST(sum(expected) < total_width);
     BOOST_TEST(observed == expected);
-BOOST_TEST(observed2 == expected);
     }
 
     // Fits with reduced margin.
@@ -382,11 +355,9 @@ BOOST_TEST(observed2 == expected);
 
     std::vector<int> const observed = set_column_widths(v, total_width, 
default_margin, 1);
 
-std::vector<int> const observed2 = widths(v);
     std::vector<int> const expected = {30, 28, 54, 36, 54, 54, 54, 54, 53, 53, 
53, 53};
     BOOST_TEST(total_width == sum(expected));
     BOOST_TEST(observed == expected);
-BOOST_TEST(observed2 == expected);
     }
 
     // Cannot fit.
@@ -412,11 +383,9 @@ BOOST_TEST(observed2 == expected);
 
     // Today, two times the default margin is added to each column,
     // even though the data cannot fit.
-std::vector<int> const observed2 = widths(v);
     std::vector<int> const expected = {53, 53, 53, 53, 52, 52, 52, 52, 52, 52, 
52, 0};
     BOOST_TEST(total_width == sum(expected));
     BOOST_TEST(observed == expected);
-BOOST_TEST(observed2 == expected);
 
 #if 0 // Doesn't throw today, but might someday.
     BOOST_TEST_THROW
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index 55c8d94..65da983 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -66,7 +66,6 @@ wx_table_generator::wx_table_generator
         );
     for(int j = 0; j < lmi::ssize(all_columns()); ++j)
         {
-LMI_ASSERT(w[j] == all_columns_[j].col_width_);
         all_columns_[j].col_width_ = w[j];
         }
 
@@ -110,7 +109,6 @@ wx_table_generator::wx_table_generator
         );
     for(int j = 0; j < lmi::ssize(all_columns()); ++j)
         {
-LMI_ASSERT(w[j] == all_columns_[j].col_width_);
         all_columns_[j].col_width_ = w[j];
         }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]