MRPT  1.9.9
bits_math_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
11 #include <mrpt/core/bits_math.h>
12 
13 TEST(bits_math, sign)
14 {
15  EXPECT_EQ(mrpt::sign(-8), -1);
16  EXPECT_EQ(mrpt::sign(8), 1);
17  EXPECT_EQ(mrpt::sign(0), 1);
18  EXPECT_EQ(mrpt::sign(8.0), 1);
19  EXPECT_EQ(mrpt::sign(-8.0), -1);
20  EXPECT_EQ(mrpt::sign(0.0), 1);
21 }
22 
23 TEST(bits_math, keep_min)
24 {
25  int min = 40;
26  mrpt::keep_min(min, 30);
27  EXPECT_EQ(min, 30);
28  mrpt::keep_min(min, 80);
29  EXPECT_EQ(min, 30);
30  mrpt::keep_min(min, -80);
31  EXPECT_EQ(min, -80);
32 }
33 
34 TEST(bits_math, round2up)
35 {
36  EXPECT_EQ(mrpt::round2up(4), 4);
37  EXPECT_EQ(mrpt::round2up(5), 8);
38  EXPECT_EQ(mrpt::round2up(200), 256);
39 }
#define min(a, b)
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...
TEST(bits_math, sign)
T round2up(T val)
Round up to the nearest power of two of a given number.
int sign(T x)
Returns the sign of X as "1" or "-1".



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019