All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
rounding_test.cc File Reference

Unit test for utilities from rounding.h. More...

#include <boost/test/unit_test.hpp>
#include "icarusalg/Utilities/rounding.h"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   RoundingTest
 

Functions

void roundupTest ()
 
void rounddownTest ()
 
 BOOST_AUTO_TEST_CASE (RoundUpTestCase)
 
 BOOST_AUTO_TEST_CASE (RoundDownTestCase)
 

Detailed Description

Unit test for utilities from rounding.h.

Date
April 17, 2020
Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
See Also
icarusalg/Utilities/rounding.h

Definition in file rounding_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   RoundingTest

Definition at line 10 of file rounding_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( RoundUpTestCase  )

Definition at line 52 of file rounding_test.cc.

52  {
53 
54  roundupTest();
55 
56 } // BOOST_AUTO_TEST_CASE( RoundUpTestCase )
void roundupTest()
BOOST_AUTO_TEST_CASE ( RoundDownTestCase  )

Definition at line 59 of file rounding_test.cc.

59  {
60 
61  rounddownTest();
62 
63 } // BOOST_AUTO_TEST_CASE( RoundDownTestCase )
void rounddownTest()
void rounddownTest ( )

Definition at line 34 of file rounding_test.cc.

34  {
35 
36  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(23.0, 2.5), 22.5);
37  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(23.0, 2.5, 1.0), 21.0); // 21.0 + 1.0 => 20.0 + 1.0
38  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(23.0, 2.5, 1.0), 21.0); // 22.0 + 1.0 => 20.0 + 1.0
39  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(24.0, 2.5, 1.0), 23.5); // 23.0 + 1.0 => 22.5 + 1.0
40 
41  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(23, 5), 20);
42  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(22, 5, 3), 18); // 19 + 3 => 15 + 3
43  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(23, 5, 3), 23); // 20 + 3 => 20 + 3
44  BOOST_CHECK_EQUAL(icarus::ns::util::rounddown(24, 5, 3), 23); // 21 + 3 => 20 + 3
45 
46 } // rounddownTest()
constexpr T rounddown(T const value, U const quantum, T const offset=T{})
Returns the value, rounded down.
Definition: rounding.h:68
void roundupTest ( )

Definition at line 18 of file rounding_test.cc.

18  {
19 
20  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(23.0, 2.5), 25.0);
21  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(22.0, 2.5, 1.0), 23.5); // 21.0 + 1.0 => 22.5 + 1.0
22  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(23.0, 2.5, 1.0), 23.5); // 22.0 + 1.0 => 22.5 + 1.0
23  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(24.0, 2.5, 1.0), 26.0); // 23.0 + 1.0 => 25.0 + 1.0
24 
25  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(23, 5), 25);
26  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(22, 5, 3), 23); // 19 + 3 => 20 + 3
27  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(23, 5, 3), 23); // 20 + 3 => 20 + 3
28  BOOST_CHECK_EQUAL(icarus::ns::util::roundup(24, 5, 3), 28); // 21 + 3 => 25 + 3
29 
30 } // roundupTest()
constexpr T roundup(T const value, U const quantum, T const offset=T{})
Returns the value, rounded up.
Definition: rounding.h:112