stencil.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Macros
10 *****************************************************************************/
11 
12 // Make sure we enter debug mode.
13 #ifdef NDEBUG
14  #undef NDEBUG
15 #endif
16 #ifdef ECL_NDEBUG
17  #undef ECL_NDEBUG
18 #endif
19 
20 /*****************************************************************************
21 ** Includes
22 *****************************************************************************/
23 
24 #include <iostream>
25 #include <gtest/gtest.h>
26 //#include </ecl/config/ecl.hpp>
27 #include "../../include/ecl/containers/array.hpp"
28 #include "../../include/ecl/containers/stencil.hpp"
30 
31 /*****************************************************************************
32 ** Using
33 *****************************************************************************/
34 
36 using ecl::Array;
37 using ecl::Stencil;
39 
40 /*****************************************************************************
41 ** Globals
42 *****************************************************************************/
43 
46 
47 /*****************************************************************************
48 ** Tests
49 *****************************************************************************/
50 
51 TEST(StencilTests,construction) {
52 
53  Array<int,5> array;
54  Array<int> darray(5);
55  array << 1,2,3,4,5;
56  darray << 6,7,8,9,10;
57 
58  FixedStencil stencil = array.stencil(1,3); // 2,3.4
59  DynamicStencil dstencil(darray,darray.begin()+1,darray.begin()+4); // 7,8,9
60  EXPECT_EQ(2,stencil[0]);
61  EXPECT_EQ(3,stencil[1]);
62  EXPECT_EQ(4,stencil[2]);
63  EXPECT_EQ(7,dstencil[0]);
64  EXPECT_EQ(8,dstencil[1]);
65  EXPECT_EQ(9,dstencil[2]);
66 }
67 
68 TEST(StencilTests,badConstruction) {
69 
70  Array<int> darray(5);
71  darray << 6,7,8,9,10;
72 
73  bool result = false;
74  try {
75  DynamicStencil bad_stencil(darray,darray.begin()+1,darray.begin()+9);
76  } catch ( StandardException &e ) {
77  result = true;
78  }
79  EXPECT_TRUE(result);
80 }
81 
82 TEST(StencilTests,badIndexing) {
83 
84  Array<int> darray(5);
85  darray << 6,7,8,9,10;
86 
87  DynamicStencil dstencil(darray,darray.begin()+1,darray.begin()+4); // 7,8,9
88  darray.resize(3);
89  darray << 6,7,8;
90  bool result = false;
91  try {
92  dstencil[2]; // Even something that looks good will generally fail as the memory has moved.
93  dstencil[4];
94  } catch ( StandardException &e ) {
95  result = true;
96  }
97  EXPECT_TRUE(result);
98 }
99 TEST(StencilTests,modifying) {
100  Array<int,5> array;
101  Array<int> darray(5);
102  array << 1,2,3,4,5;
103  darray << 6,7,8,9,10;
104  FixedStencil stencil = array.stencil(1,3); // 2,3.4
105  stencil.resettle(0,2); // 1,2
106  EXPECT_EQ(1,stencil[0]);
107  EXPECT_EQ(2,stencil[1]);
108  stencil = array.stencil(1,4); // 2,3,4,5
109  EXPECT_EQ(2,stencil[0]);
110  EXPECT_EQ(3,stencil[1]);
111  EXPECT_EQ(4,stencil[2]);
112  EXPECT_EQ(5,stencil[3]);
113 }
114 
115 TEST(StencilTests,concepts) {
116 
119 
120  // ecl_compile_time_concept_check(ecl::concepts::ByteContainer<FixedStencil>); // this one fails
123  SUCCEED();
124 }
125 
126 TEST(StencilTests,byteStrings) {
127 
128  std::string str("dude");
129  Stencil<std::string> stencil( str, str.begin(), str.end() );
130  EXPECT_EQ(4,stencil.size());
131  EXPECT_EQ('d',stencil[0]);
132  EXPECT_EQ('u',stencil[1]);
133  EXPECT_EQ('d',stencil[2]);
134  EXPECT_EQ('e',stencil[3]);
135 // for ( unsigned int i = 0; i < stencil.size(); ++i ) {
136 // std::cout << i << ": " << stencil[i] << std::endl;
137 // }
138 
139  SUCCEED();
140 }
141 
142 TEST(StencilTests,unsignedCharArrays) {
143 
144  //unsigned char buffer[4] = { 0xff, 0x00, 0x01, 0x02 };
145  unsigned char buffer[4];
146  Stencil<unsigned char*> stencil( buffer, 4, buffer, buffer + 4);
147  stencil << 0xff, 0x00, 0x01, 0x02;
148  EXPECT_EQ(4,stencil.size());
149  EXPECT_EQ(255,stencil[0]);
150  EXPECT_EQ(0,stencil[1]);
151  EXPECT_EQ(1,stencil[2]);
152  EXPECT_EQ(2,stencil[3]);
153 // std::cout << std::hex;
154 // for ( unsigned int i = 0; i < stencil.size(); ++i ) {
155 // std::cout << i << ": " << static_cast<int>(stencil[i]) << std::endl;
156 // }
157 // std::cout << std::dec;
158 
159  SUCCEED();
160 }
161 
162 
163 /*****************************************************************************
164 ** Main program
165 *****************************************************************************/
166 
167 int main(int argc, char **argv) {
168  testing::InitGoogleTest(&argc,argv);
169  return RUN_ALL_TESTS();
170 }
171 
172 
Fixed size container with a few bells and whistles.
void resettle(const unsigned int &start_index, const unsigned int &n)
Resettle the stencil on a different range over the same underlying array.
Stencil< Array< int, 5 > > FixedStencil
Definition: stencil.cpp:44
Stencil< Array< char, 3 > > ByteStencil
Stencil< Array< Type, Size > > stencil(const unsigned int &start_index, const unsigned int &n)
Open a window (stencil) onto the array.
Array< char, 3 > ByteArray
int main(int argc, char **argv)
Definition: stencil.cpp:167
A safe windowing class that opens onto array-like containers.
#define ecl_compile_time_concept_check(Model)
Stencil< Array< int > > DynamicStencil
Definition: stencil.cpp:45
size_type size() const
TEST(StencilTests, construction)
Definition: stencil.cpp:51


ecl_containers
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:43