Macros | Functions
RealComparisons_test.cc File Reference

Unit test for RealComparisons class. More...

#include <boost/test/unit_test.hpp>
#include "larcorealg/CoreUtils/RealComparisons.h"
#include <ostream>
#include <cmath>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( RealComparisons_test )
 

Functions

 BOOST_AUTO_TEST_CASE (test_RealComparisons)
 

Detailed Description

Unit test for RealComparisons class.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
November 4th, 2016
See also
larcorealg/CoreUtils/RealComparisons.h

Definition in file RealComparisons_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( RealComparisons_test )

Definition at line 10 of file RealComparisons_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( test_RealComparisons  )

Definition at line 21 of file RealComparisons_test.cc.

21  {
22 
23  // instantiate a RealComparisons with two classes
25 
26  double const sqrt2 = std::sqrt(2);
27 
28  // check zero()
29  double const epsilon = 2.0 - (sqrt2 * sqrt2);
30  BOOST_TEST( check.zero(epsilon));
31  BOOST_TEST( check.zero(0.0));
32  BOOST_TEST( check.zero(1e-5));
33  BOOST_TEST( check.zero(-1e-5));
34  BOOST_TEST(!check.zero(1.01e-5));
35  BOOST_TEST(!check.zero(-1.01e-5 * 1.01));
36 
37  // check nonZero()
38  BOOST_TEST(!check.nonZero(epsilon));
39  BOOST_TEST(!check.nonZero(0.0));
40  BOOST_TEST(!check.nonZero(1e-5));
41  BOOST_TEST(!check.nonZero(-1e-5));
42  BOOST_TEST( check.nonZero(1.01e-5));
43  BOOST_TEST( check.nonZero(-1.01e-5 * 1.01));
44 
45  // check equal()
46  BOOST_TEST(!check.equal(sqrt2, 1.4142));
47  BOOST_TEST( check.nonEqual(sqrt2, 1.4142));
48  BOOST_TEST( check.equal(sqrt2, 1.414213));
49  BOOST_TEST(!check.nonEqual(sqrt2, 1.414213));
50 
51  // check strictlyNegative()
52  BOOST_TEST(!check.strictlyNegative(+1e-5 + 1e-7)); // outside tolerance
53  BOOST_TEST(!check.strictlyNegative(+1e-5 - 1e-7)); // within tolerance
54  BOOST_TEST(!check.strictlyNegative(0.0)); // zero
55  BOOST_TEST(!check.strictlyNegative(-1e-5 + 1e-7)); // within tolerance
56  BOOST_TEST( check.strictlyNegative(-1e-5 - 1e-7)); // outside tolerance
57 
58  // check strictlyPositive()
59  BOOST_TEST( check.strictlyPositive(+1e-5 + 1e-7)); // outside tolerance
60  BOOST_TEST(!check.strictlyPositive(+1e-5 - 1e-7)); // within tolerance
61  BOOST_TEST(!check.strictlyPositive(0.0)); // zero
62  BOOST_TEST(!check.strictlyPositive(-1e-5 + 1e-7)); // within tolerance
63  BOOST_TEST(!check.strictlyPositive(-1e-5 - 1e-7)); // outside tolerance
64 
65  // check nonNegative()
66  BOOST_TEST( check.nonNegative(+1e-5 + 1e-7)); // outside tolerance
67  BOOST_TEST( check.nonNegative(+1e-5 - 1e-7)); // within tolerance
68  BOOST_TEST( check.nonNegative(0.0)); // zero
69  BOOST_TEST( check.nonNegative(-1e-5 + 1e-7)); // within tolerance
70  BOOST_TEST(!check.nonNegative(-1e-5 - 1e-7)); // outside tolerance
71 
72  // check nonPositive()
73  BOOST_TEST(!check.nonPositive(+1e-5 + 1e-7)); // outside tolerance
74  BOOST_TEST( check.nonPositive(+1e-5 - 1e-7)); // within tolerance
75  BOOST_TEST( check.nonPositive(0.0)); // zero
76  BOOST_TEST( check.nonPositive(-1e-5 + 1e-7)); // within tolerance
77  BOOST_TEST( check.nonPositive(-1e-5 - 1e-7)); // outside tolerance
78 
79  // check strictlySmaller()
80  BOOST_TEST(!check.strictlySmaller(1.0, 1.0 - 1e-4)); // outside tolerance
81  BOOST_TEST(!check.strictlySmaller(1.0, 1.0 - 1e-7)); // within tolerance
82  BOOST_TEST(!check.strictlySmaller(1.0, 1.0)); // equal
83  BOOST_TEST(!check.strictlySmaller(1.0, 1.0 + 1e-7)); // within tolerance
84  BOOST_TEST( check.strictlySmaller(1.0, 1.0 + 1e-4)); // outside tolerance
85 
86  // check nonSmaller()
87  BOOST_TEST( check.nonSmaller(1.0, 1.0 - 1e-4)); // outside tolerance
88  BOOST_TEST( check.nonSmaller(1.0, 1.0 - 1e-7)); // within tolerance
89  BOOST_TEST( check.nonSmaller(1.0, 1.0)); // equal
90  BOOST_TEST( check.nonSmaller(1.0, 1.0 + 1e-7)); // within tolerance
91  BOOST_TEST(!check.nonSmaller(1.0, 1.0 + 1e-4)); // outside tolerance
92 
93  // check strictlyGreater()
94  BOOST_TEST( check.strictlyGreater(1.0, 1.0 - 1e-4)); // outside tolerance
95  BOOST_TEST(!check.strictlyGreater(1.0, 1.0 - 1e-7)); // within tolerance
96  BOOST_TEST(!check.strictlyGreater(1.0, 1.0)); // equal
97  BOOST_TEST(!check.strictlyGreater(1.0, 1.0 + 1e-7)); // within tolerance
98  BOOST_TEST(!check.strictlyGreater(1.0, 1.0 + 1e-4)); // outside tolerance
99 
100  // check nonGreater()
101  BOOST_TEST(!check.nonGreater(1.0, 1.0 - 1e-4)); // outside tolerance
102  BOOST_TEST( check.nonGreater(1.0, 1.0 - 1e-7)); // within tolerance
103  BOOST_TEST( check.nonGreater(1.0, 1.0)); // equal
104  BOOST_TEST( check.nonGreater(1.0, 1.0 + 1e-7)); // within tolerance
105  BOOST_TEST( check.nonGreater(1.0, 1.0 + 1e-4)); // outside tolerance
106 
107  // check within()
108  BOOST_TEST(!check.within(sqrt2, 0., 1.41420));
109  BOOST_TEST( check.within(sqrt2, 0., 1.41421));
110  BOOST_TEST( check.within(sqrt2, 1.41422, 2.));
111  BOOST_TEST(!check.within(sqrt2, 1.41423, 2.));
112 
113  // check inverted limits
114  BOOST_TEST(!check.within(sqrt2, 1.41421, 0.));
115  BOOST_TEST(check.withinSorted(sqrt2, 1.41421, 0.));
116 
117 } // BOOST_AUTO_TEST_CASE(test_RealComparisons)
Provides simple real number checks.
bool check(const std::vector< std::vector< float > > &outputs)
const double e