push_and_pop.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009  ** Includes
00010  *****************************************************************************/
00011 
00012 #include <iostream>
00013 #include <gtest/gtest.h>
00014 #include "../../include/ecl/containers/array.hpp"
00015 #include "../../include/ecl/containers/push_and_pop.hpp"
00016 
00017 /*****************************************************************************
00018  ** Using
00019  *****************************************************************************/
00020 
00021 using ecl::Array;
00022 using ecl::StandardException;
00023 using ecl::ContainerConcept;
00024 using ecl::PushAndPop;
00025 
00026 /*****************************************************************************
00027  ** Tests
00028  *****************************************************************************/
00029 
00030 TEST(PushAndPopTests,constructors)
00031 {
00032   PushAndPop<int> pp_dynamic(4, 2);
00033   EXPECT_EQ(2, pp_dynamic[0]);
00034   EXPECT_EQ(2, pp_dynamic[1]);
00035   EXPECT_EQ(2, pp_dynamic[2]);
00036   EXPECT_EQ(2, pp_dynamic[3]);
00037 
00038   PushAndPop<int, 4> pp_fixed(2);
00039   EXPECT_EQ(2, pp_fixed[0]);
00040   EXPECT_EQ(2, pp_fixed[1]);
00041   EXPECT_EQ(2, pp_fixed[2]);
00042   EXPECT_EQ(2, pp_fixed[3]);
00043 }
00044 
00045 TEST(PushAndPopTests, pop_and_push )
00046 {
00047   PushAndPop<double> pp_dynamic(4);
00048   for (int i = 0; i < 4; i++)
00049   {
00050     pp_dynamic.push_back((double)i);
00051   }
00052 
00053   EXPECT_EQ(0.0, pp_dynamic[0]);
00054   EXPECT_EQ(1.0, pp_dynamic[1]);
00055   EXPECT_EQ(2.0, pp_dynamic[2]);
00056   EXPECT_EQ(3.0, pp_dynamic[3]);
00057 
00058   pp_dynamic.pop_front();
00059   pp_dynamic.pop_front();
00060   EXPECT_EQ(2, pp_dynamic.size());
00061 
00062   // [0] always returns first data from the buffer
00063   EXPECT_EQ(2.0, pp_dynamic[0]);
00064   EXPECT_EQ(3.0, pp_dynamic[1]);
00065 }
00066 
00067 TEST(PushAndPopTests, push_back_only )
00068 {
00069   PushAndPop<unsigned int, 3> pp;
00070   for (unsigned int i = 0; i < 4; i++)
00071   {
00072     pp.push_back(i);
00073   }
00074 
00075   EXPECT_EQ( 3, pp.size());
00076 
00077   for (unsigned int i = 4; i < 8; i++)
00078   {
00079     pp.push_back(i);
00080     EXPECT_EQ( 3, pp.size());
00081   }
00082 
00083   PushAndPop<unsigned int> pp_dynamic(3, 1);
00084   for (unsigned int i = 0; i < 4; i++)
00085   {
00086     pp_dynamic.push_back(i);
00087   }
00088 
00089   EXPECT_EQ( 3, pp_dynamic.size());
00090 
00091   for (unsigned int i = 4; i < 8; i++)
00092   {
00093     pp_dynamic.push_back(i);
00094     EXPECT_EQ( 3, pp_dynamic.size());
00095   }
00096 }
00097 
00098 TEST(PushAndPopTests, pop_front_only )
00099 {
00100   // fixed
00101   PushAndPop<unsigned int, 3> pp;
00102   for (unsigned int i = 0; i < 2; i++)
00103   {
00104     pp.push_back(i);
00105   }
00106 
00107   EXPECT_EQ( 2, pp.size());
00108 
00109   for (unsigned int i = 0; i < 2; i++)
00110   {
00111     pp.pop_front();
00112     EXPECT_EQ( (2-1-i), pp.size());
00113   }
00114 
00115   // when you want to check pop-front, please enable below code manually
00116 //      for( unsigned int i=0; i<2; i++ )
00117 //      {
00118 //              pp.pop_front();
00119 //              EXPECT_EQ( 0, pp.size() );
00120 //      }
00121 
00122 // dynamic
00123   PushAndPop<unsigned int> pp_dynamic(3, 1);
00124   for (unsigned int i = 0; i < 2; i++)
00125   {
00126     pp_dynamic.push_back(i);
00127   }
00128 
00129   EXPECT_EQ( 2, pp_dynamic.size());
00130 
00131   for (unsigned int i = 0; i < 2; i++)
00132   {
00133     pp_dynamic.pop_front();
00134     EXPECT_EQ( (2-1-i), pp_dynamic.size());
00135   }
00136 
00137   // when you want to check pop-front, please enable below code manually
00138 //      for( unsigned int i=0; i<2; i++ )
00139 //      {
00140 //              pp_dynamic.pop_front();
00141 //              EXPECT_EQ( 0, pp_dynamic.size() );
00142 //      }
00143 }
00144 
00145 TEST(PushAndPopTests,concepts)
00146 {
00147   typedef PushAndPop<unsigned char> UnsignedByteBuffer;
00148   ecl_compile_time_concept_check (ContainerConcept<UnsignedByteBuffer> );
00149   typedef PushAndPop<char> ByteBuffer;
00150   ecl_compile_time_concept_check (ContainerConcept<ByteBuffer> );
00151   SUCCEED();
00152   // ecl_compile_time_concept_check(ContainerConcept<Array<char,6>>); // The macro won't let you do this (macro function syntax problem, not a c++ problem)
00153 }
00154 
00155 
00156 /*****************************************************************************
00157  ** Main program
00158  *****************************************************************************/
00159 
00160 int main(int argc, char **argv)
00161 {
00162   testing::InitGoogleTest(&argc, argv);
00163   return RUN_ALL_TESTS();
00164 }


ecl_containers
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:42