lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 6335e9a 1/4: Render comprehensible


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 6335e9a 1/4: Render comprehensible
Date: Thu, 26 Jan 2017 01:17:21 +0000 (UTC)

branch: master
commit 6335e9afadf5c5a4e6e9e98521a9653f2a9c67fe
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Render comprehensible
---
 input_seq_test.cpp |  173 ++++++++++++++++++++++++++++------------------------
 1 file changed, 94 insertions(+), 79 deletions(-)

diff --git a/input_seq_test.cpp b/input_seq_test.cpp
index 4cf4945..6d1aae0 100644
--- a/input_seq_test.cpp
+++ b/input_seq_test.cpp
@@ -29,58 +29,7 @@
 #include <cassert>
 #include <iterator>                     // std::ostream_iterator
 
-// Macros don't offer default arguments, so we need one macro
-// for each number of arguments.
-
-#ifdef CHECK0
-#   error CHECK0 already defined.
-#else //  CHECK0
-#   define CHECK0(D, N, E) \
-        { \
-        InputSequence seq((E), (N), 90, 95, 0, 2002, 0); \
-        std::vector<double> v(seq.linear_number_representation()); \
-        bool b = std::equal((D), (D) + (N), v.begin()); \
-        (b) \
-            ? static_cast<void>(0) \
-            : check((D), (N), (E)); BOOST_TEST(b); \
-        }
-#endif // CHECK0
-
-#ifdef CHECK1
-#   error CHECK1 already defined.
-#else //  CHECK1
-#   define CHECK1(D, N, E, K, C) \
-        { \
-        InputSequence seq((E), (N), 90, 95, 0, 2002, 0, (K)); \
-        std::vector<double> v(seq.linear_number_representation()); \
-        std::vector<std::string> s(seq.linear_keyword_representation()); \
-        bool b = \
-               std::equal((D), (D) + (N), v.begin()) \
-            && std::equal((C), (C) + (N), s.begin()) \
-            ; \
-        (b) \
-            ? static_cast<void>(0) \
-            : check((D), (N), (E), (K), (C)); BOOST_TEST(b); \
-        }
-#endif // CHECK1
-
-#ifdef CHECK2
-#   error CHECK2 already defined.
-#else //  CHECK2
-#   define CHECK2(D, N, E, K, C, W) \
-        { \
-        InputSequence seq((E), (N), 90, 95, 0, 2002, 0, (K), (W)); \
-        std::vector<double> v(seq.linear_number_representation()); \
-        std::vector<std::string> s(seq.linear_keyword_representation()); \
-        bool b = \
-               std::equal((D), (D) + (N), v.begin()) \
-            && std::equal((C), (C) + (N), s.begin()) \
-            ; \
-        (b) \
-            ? static_cast<void>(0) \
-            : check((D), (N), (E), (K), (C), (W)); BOOST_TEST(b); \
-        }
-#endif // CHECK2
+// Called by check[0-9]() to analyze errors.
 
 template<typename T>
 void check
@@ -127,14 +76,84 @@ void check
         }
 }
 
+// One check[0-9]() function for each number of ctor arguments.
+
+template<typename T>
+void check0
+    (T const* d
+    ,int n
+    ,std::string const& e
+    ,char const* file
+    ,int line
+    )
+{
+    InputSequence seq(e, n, 90, 95, 0, 2002, 0);
+    std::vector<double> v(seq.linear_number_representation());
+    bool b = std::equal(d, d + n, v.begin());
+    if(!b) check(d, n, e);
+    INVOKE_BOOST_TEST(b, file, line);
+}
+
+template<typename T>
+void check1
+    (T const* d
+    ,int n
+    ,std::string const& e
+    ,std::vector<std::string> const& k
+    ,char const* const* c
+    ,char const* file
+    ,int line
+    )
+{
+    InputSequence seq(e, n, 90, 95, 0, 2002, 0, k);
+    std::vector<double> v(seq.linear_number_representation());
+    std::vector<std::string> s(seq.linear_keyword_representation());
+    bool b =
+           std::equal(d, d + n, v.begin())
+        && std::equal(c, c + n, s.begin())
+        ;
+    if(!b) check(d, n, e, k, c);
+    INVOKE_BOOST_TEST(b, file, line);
+}
+
+template<typename T>
+void check2
+    (T const* d
+    ,int n
+    ,std::string const& e
+    ,std::vector<std::string> const& k
+    ,char const* const* c
+    ,std::string const& w
+    ,char const* file
+    ,int line
+    )
+{
+    InputSequence seq(e, n, 90, 95, 0, 2002, 0, k, w);
+    std::vector<double> v(seq.linear_number_representation());
+    std::vector<std::string> s(seq.linear_keyword_representation());
+    bool b =
+           std::equal(d, d + n, v.begin())
+        && std::equal(c, c + n, s.begin())
+        ;
+    if(!b) check(d, n, e, k, c, w);
+    INVOKE_BOOST_TEST(b, file, line);
+}
+
 int test_main(int, char*[])
 {
+    // General test pattern:
+    //   e: expected result
+    // and the rest are ctor arguments:
+    //   d: numeric data
+    //   n: number of data
+    //   k,c,w: extra arguments
+
     // An all-blank string is treated as zero.
     {
     int const n = 9;
     double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
     std::string e(" ");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Make sure example in comment at top works.
@@ -143,7 +162,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {1, 1, 1, 7, 7, 0, 0, 0, 0};
     std::string e("1 3; 7 5;0");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Numbers separated by semicolons mean values; the last is
@@ -152,7 +171,7 @@ int test_main(int, char*[])
     int const n = 5;
     double const d[n] = {1, 2, 3, 3, 3};
     std::string e("1; 2; 3");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Number-pairs separated by semicolons mean {value, end-duration}.
@@ -160,7 +179,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
     std::string e("1 3; 3 6; 5 9; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // {value, @ attained_age}
@@ -168,7 +187,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
     std::string e("1 @93; 3 @96; 5 @99; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // {value, # number_of_years_since_last_interval_endpoint}
@@ -176,7 +195,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
     std::string e("1 #3; 3 #3; 5 #3; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // {value [|( begin-duration, end-duration ]|) }
@@ -186,7 +205,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {1, 1, 3, 3, 3, 5, 7, 7, 7};
     std::string e("1 [0, 2); 3 [2, 5); 5 [5, 6); 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test (x,y].
@@ -194,7 +213,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {1, 1, 1, 3, 3, 3, 5, 7, 7};
     std::string e("1; 1 (0, 2]; 3 (2, 5]; 5 (5, 6]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test a mixture of all five ways of specifying duration.
@@ -202,7 +221,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {1, 1, 1, 1, 2, 3, 4, 5, 5};
     std::string e("1 [0, 4); 2 5; 3 #1; 4 @97; 5");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test intervals of length one.
@@ -210,7 +229,7 @@ int test_main(int, char*[])
     int const n = 5;
     double const d[n] = {1, 3, 5, 7, 7};
     std::string e("1 [0, 1); 3 [1, 2); 5 (1, 2]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test empty intervals.
@@ -218,7 +237,7 @@ int test_main(int, char*[])
     int const n = 5;
     double const d[n] = {1, 3, 5, 7, 7};
     std::string e("1 [0, 1); 3 [1, 1]; 5 (1, 2]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test subtly improper intervals.
@@ -226,7 +245,7 @@ int test_main(int, char*[])
     int const n = 5;
     double const d[n] = {0, 0, 0, 0, 0};
     std::string e("1 [0, 0); 3 (1, 2); 5 (2, 2]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test grossly improper intervals.
@@ -234,7 +253,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
     std::string e("1; 9 (2, 0]; 3 [7, 3); 5 (5, 5); 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test intervals with 'holes'. Since the last element is replicated,
@@ -243,7 +262,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {0, 1, 0, 3, 0, 5, 7, 7, 7};
     std::string e("1 [1, 2); 3 [3, 3]; 5 (4, 5]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test overlapping intervals.
@@ -252,7 +271,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {1, 1, 1, 3, 3, 5, 5, 7, 7};
     std::string e("1; 1 (0, 8]; 3 (2, 7]; 5 (4, 6]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test intervals with decreasing begin-points.
@@ -261,7 +280,7 @@ int test_main(int, char*[])
     int const n = 9;
     double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
     std::string e("5 [5, 6); 3 [2, 5); 1 [0, 2); 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Durations with '@' prefix mean attained age.
@@ -269,7 +288,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {0, 12, 0, 27, 0, 1, 7, 7, 7, 7};
     std::string e("12 [1, @92); 27 address@hidden, @93]; 1 (@94, 5]; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // Test floating-point values; we choose values that we know
@@ -279,7 +298,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {0, 12.25, 0, 27.875, 0, 1.0625, 7.5, 7.5, 7.5, 7.5};
     std::string e("12.25 [1, @92); 27.875 address@hidden, @93]; 1.0625 (@94, 
5]; 7.5");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
     // {value, @ age} means {value, to-attained-age}
@@ -287,7 +306,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
     std::string e("1 @93; 3 @96; 5 @99; 7");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     }
 
 // TODO ?? Also support and test:
@@ -316,7 +335,7 @@ int test_main(int, char*[])
     k.push_back("c");
     k.push_back("cc");
     k.push_back("ccc");
-    CHECK1(d, n, e, k, c);
+    check1(d, n, e, k, c, __FILE__, __LINE__);
     }
 
     // Test numbers mixed with (enumerative) extra keywords.
@@ -327,7 +346,7 @@ int test_main(int, char*[])
     std::string e("1 [0, 2); keyword_00 [2, 4); 5 [4, 6); 7");
     std::vector<std::string> k;
     k.push_back("keyword_00");
-    CHECK1(d, n, e, k, c);
+    check1(d, n, e, k, c, __FILE__, __LINE__);
     }
 
     // Test numbers mixed with (enumerative) extra keywords, with
@@ -342,7 +361,7 @@ int test_main(int, char*[])
     k.push_back("b");
     k.push_back("x");
     std::string w("x");
-    CHECK2(d, n, e, k, c, w);
+    check2(d, n, e, k, c, w, __FILE__, __LINE__);
     }
 
 // TODO ?? Also test keyword as scalar duration.
@@ -352,7 +371,7 @@ int test_main(int, char*[])
     int const n = 10;
     double const d[n] = {7, 7, 7, 7, 7, 4, 4, 4, 4, 4};
     std::string e("7, retirement; 4");
-    CHECK0(d, n, e);
+    check0(d, n, e, __FILE__, __LINE__);
     InputSequence seq("7, retirement; 4", 10, 90, 95, 0, 2002, 0);
     std::vector<ValueInterval> const& i(seq.interval_representation());
     BOOST_TEST(e_inception  == i[0].begin_mode);
@@ -368,7 +387,3 @@ int test_main(int, char*[])
     return 0;
 }
 
-#undef CHECK0
-#undef CHECK1
-#undef CHECK2
-



reply via email to

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