test_doc
test_util.cpp
浏览该文件的文档.
1 /*
2  * test_util.cpp
3  *
4  * Created on: 2013-4-19
5  * Author: fasiondog
6  */
7 
8 #ifdef TEST_ALL_IN_ONE
9  #include <boost/test/unit_test.hpp>
10 #else
11  #define BOOST_TEST_MODULE test_hikyuu_utilities
12  #include <boost/test/unit_test.hpp>
13 #endif
14 
15 #include <hikyuu/Log.h>
16 #include <hikyuu/utilities/util.h>
17 
18 using namespace hku;
19 
27 BOOST_AUTO_TEST_CASE( test_round ) {
28  double x;
29 
30  x = 10.11;
31  BOOST_CHECK(roundEx(x) == 10.0);
32  BOOST_CHECK(roundDown(x) == 10.0);
33  BOOST_CHECK(roundUp(x) == 11.0);
34  BOOST_CHECK(roundEx(x, 1) == 10.1);
35  BOOST_CHECK(roundDown(x, 1) == 10.1);
36  BOOST_CHECK(roundUp(x, 1) == 10.2);
37 
38  x = 10.55;
39  BOOST_CHECK(roundEx(x) == 11);
40  BOOST_CHECK(roundDown(x) == 10);
41  BOOST_CHECK(roundUp(x) == 11.0);
42  BOOST_CHECK(roundEx(x, 1) == 10.6);
43  BOOST_CHECK(roundDown(x, 1) == 10.5);
44  BOOST_CHECK(roundUp(x, 1) == 10.6);
45 
46  x = -10.11;
47  BOOST_CHECK(roundEx(x) == -10);
48  BOOST_CHECK(roundDown(x) == -10);
49  BOOST_CHECK(roundUp(x) == -11.0);
50  BOOST_CHECK(roundEx(x, 1) == -10.1);
51  BOOST_CHECK(roundDown(x, 1) == -10.1);
52  BOOST_CHECK(roundUp(x, 1) == -10.2);
53 
54  x = -10.55;
55  BOOST_CHECK(roundEx(x) == -11);
56  BOOST_CHECK(roundDown(x) == -10);
57  BOOST_CHECK(roundUp(x) == -11.0);
58  BOOST_CHECK(roundEx(x, 1) == -10.6);
59  BOOST_CHECK(roundDown(x, 1) == -10.5);
60  BOOST_CHECK(roundUp(x, 1) == -10.6);
61 }
62 
BOOST_AUTO_TEST_CASE(test_round)
Definition: test_util.cpp:27