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 }
#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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020