Main MRPT website > C++ reference for MRPT 1.9.9
bits_math_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/bits_math.h>
11 #include <gtest/gtest.h>
12 
13 TEST(bits_math, sign)
14 {
15 
16  EXPECT_EQ(mrpt::sign(-8), -1);
17  EXPECT_EQ(mrpt::sign(8), 1);
18  EXPECT_EQ(mrpt::sign(0), 1);
19  EXPECT_EQ(mrpt::sign(8.0), 1);
20  EXPECT_EQ(mrpt::sign(-8.0), -1);
21  EXPECT_EQ(mrpt::sign(0.0), 1);
22 }
23 
24 TEST(bits_math, keep_min)
25 {
26  int min = 40;
27  mrpt::keep_min(min, 30);
28  EXPECT_EQ(min, 30);
29  mrpt::keep_min(min, 80);
30  EXPECT_EQ(min, 30);
31  mrpt::keep_min(min, -80);
32  EXPECT_EQ(min, -80);
33 }
34 
35 TEST(bits_math, round2up)
36 {
37  EXPECT_EQ(mrpt::round2up(4), 4);
38  EXPECT_EQ(mrpt::round2up(5), 8);
39  EXPECT_EQ(mrpt::round2up(200), 256);
40 }
mrpt::keep_min
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value.
Definition: core/include/mrpt/core/bits_math.h:124
TEST
TEST(bits_math, sign)
Definition: bits_math_unittest.cpp:13
mrpt::round2up
T round2up(T val)
Round up to the nearest power of two of a given number.
Definition: core/include/mrpt/core/bits_math.h:156
bits_math.h
min
#define min(a, b)
Definition: rplidar_driver.cpp:42
mrpt::sign
int sign(T x)
Returns the sign of X as "1" or "-1".
Definition: core/include/mrpt/core/bits_math.h:68



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST