test_math_utils.cpp
Go to the documentation of this file.
00001 
00026 #include "sr_utilities/sr_math_utils.hpp"
00027 #include <gtest/gtest.h>
00028 
00029 TEST(Pow, base2)
00030 {
00031   EXPECT_EQ(sr_math_utils::ipow(2, 0), 1);
00032   EXPECT_EQ(sr_math_utils::ipow(2, 2), 4);
00033   EXPECT_EQ(sr_math_utils::ipow(2, 10), 1024);
00034 
00035   EXPECT_EQ(sr_math_utils::ipow(2, 20), 1048576);
00036 }
00037 
00038 TEST(Pow, base3)
00039 {
00040   EXPECT_EQ(sr_math_utils::ipow(3, 0), 1);
00041   EXPECT_EQ(sr_math_utils::ipow(3, 2), 9);
00042   EXPECT_EQ(sr_math_utils::ipow(3, 10), 59049);
00043 }
00044 
00045 TEST(BitMasks, is_true__true_0)
00046 {
00047   //bit mask = 0b01
00048   int bit_mask = 1;
00049   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 0));
00050 }
00051 
00052 TEST(BitMasks, is_true__false_1)
00053 {
00054   //bit mask = 0b01
00055   int bit_mask = 1;
00056   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 1));
00057 }
00058 
00059 TEST(BitMasks, is_false__false_0)
00060 {
00061   //bit mask = 0b01
00062   int bit_mask = 1;
00063   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 0));
00064 }
00065 
00066 TEST(BitMasks, is_false__true_1)
00067 {
00068   //bit mask = 0b01
00069   int bit_mask = 1;
00070   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 1));
00071 }
00072 
00073 TEST(BitMasksGlobal, is_true__true)
00074 {
00075   //bit mask = 0b1010101
00076   int bit_mask = 85;
00077   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 0));
00078   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 2));
00079   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 4));
00080   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_true(bit_mask, 6));
00081 }
00082 
00083 TEST(BitMasksGlobal, is_false__false)
00084 {
00085   //bit mask = 0b1010101
00086   int bit_mask = 85;
00087   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 0));
00088   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 2));
00089   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 4));
00090   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_false(bit_mask, 6));
00091 }
00092 
00093 TEST(BitMasksGlobal, is_true__false)
00094 {
00095   //bit mask = 0b1010101
00096   int bit_mask = 85;
00097   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 1));
00098   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 3));
00099   EXPECT_FALSE(sr_math_utils::is_bit_mask_index_true(bit_mask, 5));
00100 }
00101 
00102 TEST(BitMasksGlobal, is_false__true)
00103 {
00104   //bit mask = 0b1010101
00105   int bit_mask = 85;
00106   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 1));
00107   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 3));
00108   EXPECT_TRUE(sr_math_utils::is_bit_mask_index_false(bit_mask, 5));
00109 }
00110 
00111 TEST(CounterWithOverflow, no_overflows)
00112 {
00113   int received_val, full_val = 0;
00114 
00115   received_val = 1000;
00116   full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
00117   EXPECT_EQ(full_val, 1000);
00118 
00119   received_val = 65535;
00120   full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
00121   EXPECT_EQ(full_val, 65535);
00122 }
00123 
00124 TEST(CounterWithOverflow, with_overflows)
00125 {
00126   int received_val, full_val = 0;
00127 
00128   full_val = 65535;
00129   received_val = 0;
00130   full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
00131   EXPECT_EQ(full_val, 65536);
00132 
00133   received_val = 1000;
00134   full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
00135   EXPECT_EQ(full_val, 66536);
00136 
00137   received_val = 0;
00138   full_val = sr_math_utils::counter_with_overflow(full_val, received_val);
00139   EXPECT_EQ(full_val, 131072);
00140 }
00141 
00142 // Run all the tests that were declared with TEST()
00143 int main(int argc, char **argv)
00144 {
00145   testing::InitGoogleTest(&argc, argv);
00146   return RUN_ALL_TESTS();
00147 }
00148 
00149 /* For the emacs weenies in the crowd.
00150 Local Variables:
00151    c-basic-offset: 2
00152 End:
00153 */


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Fri Aug 28 2015 13:08:44