CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
test_boolofvoid.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_UTILITY_TEST_BOOLOFVOID_HPP
2 # define CPPAD_UTILITY_TEST_BOOLOFVOID_HPP
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
5 
6 CppAD is distributed under multiple licenses. This distribution is under
7 the terms of the
8  Eclipse Public License Version 1.0.
9 
10 A copy of this license is included in the COPYING file of this distribution.
11 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
12 -------------------------------------------------------------------------- */
13 /*
14 $begin test_boolofvoid$$
15 $spell
16  boolofvoid
17  const
18  std
19  bool
20  ipopt
21  cpp
22 $$
23 
24 $section Object that Runs a Group of Tests$$
25 
26 $head Syntax$$
27 $codei%test_boolofvoid %Run%(%group%, %width%)
28 %$$
29 $icode%Run%(%test%, %name%)
30 %$$
31 $icode%ok% = %Run%.summary(%memory_ok%)%$$
32 
33 $head Purpose$$
34 The object $icode Run$$ is used to run a group of tests functions
35 and report the results on standard output.
36 
37 $head group$$
38 The argument has prototype
39 $codei%
40  const std::string& %group%
41 %$$
42 It is the name for this group of tests.
43 
44 $head width$$
45 The argument has prototype
46 $codei%
47  size_t %width%
48 %$$
49 It is the number of columns used to display the name of each test.
50 It must be greater than the maximum number of characters in a test name.
51 
52 $head test$$
53 The argument has prototype
54 $codei%
55  bool %test%(void)
56 %$$
57 It is a function that returns true (when the test passes) and false
58 otherwise.
59 
60 $head name$$
61 The argument has prototype
62 $codei%
63  const std::string& %name%
64 %$$
65 It is the name for the corresponding $icode test$$.
66 
67 $head memory_ok$$
68 The argument has prototype
69 $codei%
70  bool %memory_ok%
71 %$$
72 It is false if a memory leak is detected (and true otherwise).
73 
74 $head ok$$
75 This is true if all of the tests pass (including the memory leak test),
76 otherwise it is false.
77 
78 $head Example$$
79 See any of the main programs in the example directory; e.g.,
80 $code example/ipopt_solve.cpp$$.
81 
82 $end
83 */
84 
86 # include <string>
87 
88 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
89 
90 /// One class object is used to run a group of tests
92 private:
93  /// name for the group of test this object will run
94  const std::string group_;
95  /// number of characters used to display the name for each indiviual test
96  /// (must be larger than the number of characters in name for each test)
97  const size_t width_;
98  /// number of tests that have passed
99  size_t n_ok_;
100  /// number of tests that have failed
101  size_t n_error_;
102 
103 public:
104  /// ctor
105  test_boolofvoid(const std::string& group, size_t width) :
106  group_(group) ,
107  width_(width) ,
108  n_ok_(0) ,
109  n_error_(0)
110  { std::cout << "Begin test group " << group_ << std::endl; }
111  /// destructor
113  { std::cout << "End test group " << group_ << std::endl; }
114  /// run one test
115  bool operator()(bool test(void), const std::string& name)
117  name.size() < width_ ,
118  "test_boolofvoid: name does not have less characters than width"
119  );
120  std::cout.width( width_ );
121  std::cout.setf( std::ios_base::left );
122  std::cout << name;
123  //
124  bool ok = test();
125  if( ok )
126  { std::cout << "OK" << std::endl;
127  n_ok_++;
128  }
129  else
130  { std::cout << "Error" << std::endl;
131  n_error_++;
132  }
133  return ok;
134  }
135  /// nuber of tests that passed
136  size_t n_ok(void) const
137  { return n_ok_; }
138  /// nuber of tests that failed
139  size_t n_error(void) const
140  { return n_error_; }
141  /// summary
142  bool summary(bool memory_ok )
143  {
144  std::cout.width( width_ );
145  std::cout.setf( std::ios_base::left );
146  std::cout << "memory_leak";
147  //
148  if( memory_ok )
149  { std::cout << "OK" << std::endl;
150  n_ok_++;
151  }
152  else
153  { std::cout << "Error" << std::endl;
154  n_error_++;
155  }
156  if( n_error_ == 0 )
157  std::cout << "All " << n_ok_ << " tests passed." << std::endl;
158  else
159  std::cout << n_error_ << " tests failed." << std::endl;
160  //
161  return n_error_ == 0;
162  }
163 };
164 
165 } // END_CPPAD_NAMESPACE
166 
167 # endif
#define CPPAD_ASSERT_KNOWN(exp, msg)
Check that exp is true, if not print msg and terminate execution.
One class object is used to run a group of tests.
~test_boolofvoid(void)
destructor
const std::string group_
name for the group of test this object will run
bool summary(bool memory_ok)
summary
Define the CppAD error checking macros (all of which begin with CPPAD_ASSERT_)
size_t n_error(void) const
nuber of tests that failed
size_t n_error_
number of tests that have failed
bool operator()(bool test(void), const std::string &name)
run one test
size_t n_ok(void) const
nuber of tests that passed
size_t n_ok_
number of tests that have passed
test_boolofvoid(const std::string &group, size_t width)
ctor
const size_t width_
number of characters used to display the name for each indiviual test (must be larger than the number...