test_math_utils.cpp
Go to the documentation of this file.
1 
27 #include <gtest/gtest.h>
28 
29 TEST(Pow, base2)
30 {
31  EXPECT_EQ(sr_math_utils::ipow(2, 0), 1);
32  EXPECT_EQ(sr_math_utils::ipow(2, 2), 4);
33  EXPECT_EQ(sr_math_utils::ipow(2, 10), 1024);
34 
35  EXPECT_EQ(sr_math_utils::ipow(2, 20), 1048576);
36 }
37 
38 TEST(Pow, base3)
39 {
40  EXPECT_EQ(sr_math_utils::ipow(3, 0), 1);
41  EXPECT_EQ(sr_math_utils::ipow(3, 2), 9);
42  EXPECT_EQ(sr_math_utils::ipow(3, 10), 59049);
43 }
44 
45 TEST(BitMasks, is_true__true_0)
46 {
47  // bit mask = 0b01
48  int bit_mask = 1;
49  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 0));
50 }
51 
52 TEST(BitMasks, is_true__false_1)
53 {
54  // bit mask = 0b01
55  int bit_mask = 1;
56  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 1));
57 }
58 
59 TEST(BitMasks, is_false__false_0)
60 {
61  // bit mask = 0b01
62  int bit_mask = 1;
63  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 0));
64 }
65 
66 TEST(BitMasks, is_false__true_1)
67 {
68  // bit mask = 0b01
69  int bit_mask = 1;
70  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 1));
71 }
72 
73 TEST(BitMasksGlobal, is_true__true)
74 {
75  // bit mask = 0b1010101
76  int bit_mask = 85;
77  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 0));
78  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 2));
79  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 4));
80  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 6));
81 }
82 
83 TEST(BitMasksGlobal, is_false__false)
84 {
85  // bit mask = 0b1010101
86  int bit_mask = 85;
87  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 0));
88  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 2));
89  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 4));
90  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 6));
91 }
92 
93 TEST(BitMasksGlobal, is_true__false)
94 {
95  // bit mask = 0b1010101
96  int bit_mask = 85;
97  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 1));
98  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 3));
99  EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 5));
100 }
101 
102 TEST(BitMasksGlobal, is_false__true)
103 {
104  // bit mask = 0b1010101
105  int bit_mask = 85;
106  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 1));
107  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 3));
108  EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 5));
109 }
110 
111 TEST(CounterWithOverflow, no_overflows)
112 {
113  int received_val, full_val = 0;
114 
115  received_val = 1000;
116  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
117  EXPECT_EQ(full_val, 1000);
118 
119  received_val = 65535;
120  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
121  EXPECT_EQ(full_val, 65535);
122 }
123 
124 TEST(CounterWithOverflow, with_overflows)
125 {
126  int received_val, full_val = 0;
127 
128  full_val = 65535;
129  received_val = 0;
130  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
131  EXPECT_EQ(full_val, 65536);
132 
133  received_val = 1000;
134  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
135  EXPECT_EQ(full_val, 66536);
136 
137  received_val = 0;
138  full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
139  EXPECT_EQ(full_val, 131072);
140 }
141 
142 // Run all the tests that were declared with TEST()
143 int main(int argc, char **argv)
144 {
145  testing::InitGoogleTest(&argc, argv);
146  return RUN_ALL_TESTS();
147 }
148 
149 /* For the emacs weenies in the crowd.
150 Local Variables:
151  c-basic-offset: 2
152 End:
153 */
TEST(Pow, base2)
static uint64_t counter_with_overflow(uint64_t full_value, uint16_t new_value)
static int ipow(int base, int exp)
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)
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 Tue Oct 13 2020 03:55:49