test_math_utils.cpp
Go to the documentation of this file.
1 /*
2 * Copyright 2011 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
28 #include <gtest/gtest.h>
29 
30 TEST(Pow, base2)
31 {
34  EXPECT_EQ(sr_math_utils::ipow(2, 10), 1024);
35 
36  EXPECT_EQ(sr_math_utils::ipow(2, 20), 1048576);
37 }
38 
39 TEST(Pow, base3)
40 {
43  EXPECT_EQ(sr_math_utils::ipow(3, 10), 59049);
44 }
45 
46 TEST(BitMasks, is_true__true_0)
47 {
48  // bit mask = 0b01
49  int bit_mask = 1;
51 }
52 
53 TEST(BitMasks, is_true__false_1)
54 {
55  // bit mask = 0b01
56  int bit_mask = 1;
58 }
59 
60 TEST(BitMasks, is_false__false_0)
61 {
62  // bit mask = 0b01
63  int bit_mask = 1;
65 }
66 
67 TEST(BitMasks, is_false__true_1)
68 {
69  // bit mask = 0b01
70  int bit_mask = 1;
72 }
73 
74 TEST(BitMasksGlobal, is_true__true)
75 {
76  // bit mask = 0b1010101
77  int bit_mask = 85;
82 }
83 
84 TEST(BitMasksGlobal, is_false__false)
85 {
86  // bit mask = 0b1010101
87  int bit_mask = 85;
92 }
93 
94 TEST(BitMasksGlobal, is_true__false)
95 {
96  // bit mask = 0b1010101
97  int bit_mask = 85;
101 }
102 
103 TEST(BitMasksGlobal, is_false__true)
104 {
105  // bit mask = 0b1010101
106  int bit_mask = 85;
110 }
111 
112 TEST(CounterWithOverflow, no_overflows)
113 {
114  int received_val, full_val = 0;
115 
116  received_val = 1000;
117  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
118  EXPECT_EQ(full_val, 1000);
119 
120  received_val = 65535;
121  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
122  EXPECT_EQ(full_val, 65535);
123 }
124 
125 TEST(CounterWithOverflow, with_overflows)
126 {
127  int received_val, full_val = 0;
128 
129  full_val = 65535;
130  received_val = 0;
131  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
132  EXPECT_EQ(full_val, 65536);
133 
134  received_val = 1000;
135  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
136  EXPECT_EQ(full_val, 66536);
137 
138  received_val = 0;
139  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
140  EXPECT_EQ(full_val, 131072);
141 }
142 
143 // Run all the tests that were declared with TEST()
144 int main(int argc, char **argv)
145 {
146  testing::InitGoogleTest(&argc, argv);
147  return RUN_ALL_TESTS();
148 }
149 
150 /* For the emacs weenies in the crowd.
151 Local Variables:
152  c-basic-offset: 2
153 End:
154 */
TEST(Pow, base2)
static uint64_t counter_with_overflow(uint64_t full_value, uint16_t new_value)
static int ipow(int base, int exp)
#define EXPECT_FALSE(args)
#define EXPECT_EQ(a, b)
int main(int argc, char **argv)
static bool is_bit_mask_index_true(int64_t bit_mask, int index)
static bool is_bit_mask_index_false(int64_t bit_mask, int index)
#define EXPECT_TRUE(args)
This is a header library used to implement some useful math functions. It is used in our different pa...


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:19