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  ** Tests
00027  *****************************************************************************/TEST(PushAndPopTests,constructors)
00028 {
00029   PushAndPop<int> pp_dynamic(4, 2);
00030   EXPECT_EQ(2, pp_dynamic[0]);
00031   EXPECT_EQ(2, pp_dynamic[1]);
00032   EXPECT_EQ(2, pp_dynamic[2]);
00033   EXPECT_EQ(2, pp_dynamic[3]);
00034 
00035   PushAndPop<int, 4> pp_fixed(2);
00036   EXPECT_EQ(2, pp_fixed[0]);
00037   EXPECT_EQ(2, pp_fixed[1]);
00038   EXPECT_EQ(2, pp_fixed[2]);
00039   EXPECT_EQ(2, pp_fixed[3]);
00040 }
00041 
00042 TEST(PushAndPopTests, pop_and_push )
00043 {
00044   PushAndPop<double> pp_dynamic(4);
00045   for (int i = 0; i < 4; i++)
00046   {
00047     pp_dynamic.push_back((double)i);
00048   }
00049 
00050   EXPECT_EQ(0.0, pp_dynamic[0]);
00051   EXPECT_EQ(1.0, pp_dynamic[1]);
00052   EXPECT_EQ(2.0, pp_dynamic[2]);
00053   EXPECT_EQ(3.0, pp_dynamic[3]);
00054 
00055   pp_dynamic.pop_front();
00056   pp_dynamic.pop_front();
00057   EXPECT_EQ(2, pp_dynamic.size());
00058 
00059   // [0] always returns first data from the buffer
00060   EXPECT_EQ(2.0, pp_dynamic[0]);
00061   EXPECT_EQ(3.0, pp_dynamic[1]);
00062 }
00063 
00064 TEST(PushAndPopTests, push_back_only )
00065 {
00066   PushAndPop<unsigned int, 3> pp;
00067   for (unsigned int i = 0; i < 4; i++)
00068   {
00069     pp.push_back(i);
00070   }
00071 
00072   EXPECT_EQ( 3, pp.size());
00073 
00074   for (unsigned int i = 4; i < 8; i++)
00075   {
00076     pp.push_back(i);
00077     EXPECT_EQ( 3, pp.size());
00078   }
00079 
00080   PushAndPop<unsigned int> pp_dynamic(3, 1);
00081   for (unsigned int i = 0; i < 4; i++)
00082   {
00083     pp_dynamic.push_back(i);
00084   }
00085 
00086   EXPECT_EQ( 3, pp_dynamic.size());
00087 
00088   for (unsigned int i = 4; i < 8; i++)
00089   {
00090     pp_dynamic.push_back(i);
00091     EXPECT_EQ( 3, pp_dynamic.size());
00092   }
00093 }
00094 
00095 TEST(PushAndPopTests, pop_front_only )
00096 {
00097   // fixed
00098   PushAndPop<unsigned int, 3> pp;
00099   for (unsigned int i = 0; i < 2; i++)
00100   {
00101     pp.push_back(i);
00102   }
00103 
00104   EXPECT_EQ( 2, pp.size());
00105 
00106   for (unsigned int i = 0; i < 2; i++)
00107   {
00108     pp.pop_front();
00109     EXPECT_EQ( (2-1-i), pp.size());
00110   }
00111 
00112   // when you want to check pop-front, please enable below code manually
00113 //      for( unsigned int i=0; i<2; i++ )
00114 //      {
00115 //              pp.pop_front();
00116 //              EXPECT_EQ( 0, pp.size() );
00117 //      }
00118 
00119 // dynamic
00120   PushAndPop<unsigned int> pp_dynamic(3, 1);
00121   for (unsigned int i = 0; i < 2; i++)
00122   {
00123     pp_dynamic.push_back(i);
00124   }
00125 
00126   EXPECT_EQ( 2, pp_dynamic.size());
00127 
00128   for (unsigned int i = 0; i < 2; i++)
00129   {
00130     pp_dynamic.pop_front();
00131     EXPECT_EQ( (2-1-i), pp_dynamic.size());
00132   }
00133 
00134   // when you want to check pop-front, please enable below code manually
00135 //      for( unsigned int i=0; i<2; i++ )
00136 //      {
00137 //              pp_dynamic.pop_front();
00138 //              EXPECT_EQ( 0, pp_dynamic.size() );
00139 //      }
00140 }
00141 
00142 TEST(PushAndPopTests,concepts)
00143 {
00144   typedef PushAndPop<unsigned char> UnsignedByteBuffer;
00145   ecl_compile_time_concept_check (ContainerConcept<UnsignedByteBuffer> );
00146   typedef PushAndPop<char> ByteBuffer;
00147   ecl_compile_time_concept_check (ContainerConcept<ByteBuffer> );
00148   SUCCEED();
00149   // 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)
00150 }
00151 
00152 /*****************************************************************************
00153  ** Main program
00154  *****************************************************************************/
00155 
00156 int main(int argc, char **argv)
00157 {
00158 
00159   testing::InitGoogleTest(&argc, argv);
00160   std::cout << "dude" << std::endl;
00161   return RUN_ALL_TESTS();
00162 }


ecl_containers
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:25