push_and_pop.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9  ** Includes
10  *****************************************************************************/
11 
12 #include <iostream>
13 #include <gtest/gtest.h>
14 #include "../../include/ecl/containers/array.hpp"
15 #include "../../include/ecl/containers/push_and_pop.hpp"
16 
17 /*****************************************************************************
18  ** Using
19  *****************************************************************************/
20 
21 using ecl::Array;
24 using ecl::PushAndPop;
25 
26 /*****************************************************************************
27  ** Tests
28  *****************************************************************************/
29 
30 TEST(PushAndPopTests,constructors)
31 {
32  PushAndPop<int> pp_dynamic(4, 2);
33  EXPECT_EQ(2, pp_dynamic[0]);
34  EXPECT_EQ(2, pp_dynamic[1]);
35  EXPECT_EQ(2, pp_dynamic[2]);
36  EXPECT_EQ(2, pp_dynamic[3]);
37 
38  PushAndPop<int, 4> pp_fixed(2);
39  EXPECT_EQ(2, pp_fixed[0]);
40  EXPECT_EQ(2, pp_fixed[1]);
41  EXPECT_EQ(2, pp_fixed[2]);
42  EXPECT_EQ(2, pp_fixed[3]);
43 }
44 
45 TEST(PushAndPopTests, pop_and_push )
46 {
47  PushAndPop<double> pp_dynamic(4);
48  for (int i = 0; i < 4; i++)
49  {
50  pp_dynamic.push_back((double)i);
51  }
52 
53  EXPECT_EQ(0.0, pp_dynamic[0]);
54  EXPECT_EQ(1.0, pp_dynamic[1]);
55  EXPECT_EQ(2.0, pp_dynamic[2]);
56  EXPECT_EQ(3.0, pp_dynamic[3]);
57 
58  pp_dynamic.pop_front();
59  pp_dynamic.pop_front();
60  EXPECT_EQ(2, pp_dynamic.size());
61 
62  // [0] always returns first data from the buffer
63  EXPECT_EQ(2.0, pp_dynamic[0]);
64  EXPECT_EQ(3.0, pp_dynamic[1]);
65 }
66 
67 TEST(PushAndPopTests, push_back_only )
68 {
70  for (unsigned int i = 0; i < 4; i++)
71  {
72  pp.push_back(i);
73  }
74 
75  EXPECT_EQ( 3, pp.size());
76 
77  for (unsigned int i = 4; i < 8; i++)
78  {
79  pp.push_back(i);
80  EXPECT_EQ( 3, pp.size());
81  }
82 
83  PushAndPop<unsigned int> pp_dynamic(3, 1);
84  for (unsigned int i = 0; i < 4; i++)
85  {
86  pp_dynamic.push_back(i);
87  }
88 
89  EXPECT_EQ( 3, pp_dynamic.size());
90 
91  for (unsigned int i = 4; i < 8; i++)
92  {
93  pp_dynamic.push_back(i);
94  EXPECT_EQ( 3, pp_dynamic.size());
95  }
96 }
97 
98 TEST(PushAndPopTests, pop_front_only )
99 {
100  // fixed
102  for (unsigned int i = 0; i < 2; i++)
103  {
104  pp.push_back(i);
105  }
106 
107  EXPECT_EQ( 2, pp.size());
108 
109  for (unsigned int i = 0; i < 2; i++)
110  {
111  pp.pop_front();
112  EXPECT_EQ( (2-1-i), pp.size());
113  }
114 
115  // when you want to check pop-front, please enable below code manually
116 // for( unsigned int i=0; i<2; i++ )
117 // {
118 // pp.pop_front();
119 // EXPECT_EQ( 0, pp.size() );
120 // }
121 
122 // dynamic
123  PushAndPop<unsigned int> pp_dynamic(3, 1);
124  for (unsigned int i = 0; i < 2; i++)
125  {
126  pp_dynamic.push_back(i);
127  }
128 
129  EXPECT_EQ( 2, pp_dynamic.size());
130 
131  for (unsigned int i = 0; i < 2; i++)
132  {
133  pp_dynamic.pop_front();
134  EXPECT_EQ( (2-1-i), pp_dynamic.size());
135  }
136 
137  // when you want to check pop-front, please enable below code manually
138 // for( unsigned int i=0; i<2; i++ )
139 // {
140 // pp_dynamic.pop_front();
141 // EXPECT_EQ( 0, pp_dynamic.size() );
142 // }
143 }
144 
145 TEST(PushAndPopTests,concepts)
146 {
147  typedef PushAndPop<unsigned char> UnsignedByteBuffer;
149  typedef PushAndPop<char> ByteBuffer;
151  SUCCEED();
152  // 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)
153 }
154 
155 
156 /*****************************************************************************
157  ** Main program
158  *****************************************************************************/
159 
160 int main(int argc, char **argv)
161 {
162  testing::InitGoogleTest(&argc, argv);
163  return RUN_ALL_TESTS();
164 }
ecl_compile_time_concept_check
#define ecl_compile_time_concept_check(Model)
ecl::PushAndPop::push_back
void push_back(const Type &datum)
Pushes an element onto the back of the container.
Definition: push_and_pop_fixed.hpp:135
ecl::StandardException
TEST
TEST(PushAndPopTests, constructors)
Definition: push_and_pop.cpp:30
ecl::PushAndPop::pop_front
Type pop_front()
Definition: push_and_pop_fixed.hpp:147
ecl::PushAndPop
Surpport push and pack operation.
Definition: push_and_pop_fixed.hpp:82
main
int main(int argc, char **argv)
Definition: push_and_pop.cpp:160
ecl::ContainerConcept
ecl::Array
Fixed size container with a few bells and whistles.
Definition: array_no_mem_check.hpp:112
ecl::PushAndPop::size
unsigned int size() const
Definition: push_and_pop_fixed.hpp:170


ecl_containers
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:34