stencil.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Macros
00010 *****************************************************************************/
00011 
00012 // Make sure we enter debug mode.
00013 #ifdef NDEBUG
00014   #undef NDEBUG
00015 #endif
00016 #ifdef ECL_NDEBUG
00017   #undef ECL_NDEBUG
00018 #endif
00019 
00020 /*****************************************************************************
00021 ** Includes
00022 *****************************************************************************/
00023 
00024 #include <iostream>
00025 #include <gtest/gtest.h>
00026 //#include </ecl/config/ecl.hpp>
00027 #include "../../include/ecl/containers/array.hpp"
00028 #include <ecl/concepts/containers.hpp>
00029 
00030 /*****************************************************************************
00031 ** Using
00032 *****************************************************************************/
00033 
00034 using ecl::StandardException;
00035 using ecl::Array;
00036 using ecl::Stencil;
00037 using ecl::UnsignedByteContainerConcept;
00038 
00039 /*****************************************************************************
00040 ** Globals
00041 *****************************************************************************/
00042 
00043 typedef Stencil< Array<int,5> > FixedStencil;
00044 typedef Stencil< Array<int> > DynamicStencil;
00045 
00046 /*****************************************************************************
00047 ** Tests
00048 *****************************************************************************/
00049 
00050 TEST(StencilTests,construction) {
00051 
00052         Array<int,5> array;
00053         Array<int> darray(5);
00054         array << 1,2,3,4,5;
00055         darray << 6,7,8,9,10;
00056 
00057         FixedStencil stencil = array.stencil(1,3); // 2,3.4
00058         DynamicStencil dstencil(darray,darray.begin()+1,darray.begin()+4); // 7,8,9
00059         EXPECT_EQ(2,stencil[0]);
00060         EXPECT_EQ(3,stencil[1]);
00061         EXPECT_EQ(4,stencil[2]);
00062         EXPECT_EQ(7,dstencil[0]);
00063         EXPECT_EQ(8,dstencil[1]);
00064         EXPECT_EQ(9,dstencil[2]);
00065 }
00066 
00067 TEST(StencilTests,badConstruction) {
00068 
00069         Array<int> darray(5);
00070         darray << 6,7,8,9,10;
00071 
00072         bool result = false;
00073     try {
00074         DynamicStencil bad_stencil(darray,darray.begin()+1,darray.begin()+9);
00075     } catch ( StandardException &e ) {
00076         result = true;
00077     }
00078     EXPECT_TRUE(result);
00079 }
00080 
00081 TEST(StencilTests,badIndexing) {
00082 
00083         Array<int> darray(5);
00084         darray << 6,7,8,9,10;
00085 
00086         DynamicStencil dstencil(darray,darray.begin()+1,darray.begin()+4); // 7,8,9
00087         darray.resize(3);
00088         darray << 6,7,8;
00089         bool result = false;
00090     try {
00091         dstencil[2]; // Even something that looks good will generally fail as the memory has moved.
00092         dstencil[4];
00093     } catch ( StandardException &e ) {
00094         result = true;
00095     }
00096     EXPECT_TRUE(result);
00097 }
00098 TEST(StencilTests,modifying) {
00099         Array<int,5> array;
00100         Array<int> darray(5);
00101         array << 1,2,3,4,5;
00102         darray << 6,7,8,9,10;
00103         FixedStencil stencil = array.stencil(1,3); // 2,3.4
00104         stencil.resettle(0,2); // 1,2
00105         EXPECT_EQ(1,stencil[0]);
00106         EXPECT_EQ(2,stencil[1]);
00107         stencil = array.stencil(1,4); // 2,3,4,5
00108         EXPECT_EQ(2,stencil[0]);
00109         EXPECT_EQ(3,stencil[1]);
00110         EXPECT_EQ(4,stencil[2]);
00111         EXPECT_EQ(5,stencil[3]);
00112 }
00113 
00114 TEST(StencilTests,concepts) {
00115 
00116         typedef Array<unsigned char,6> ByteArray;
00117     typedef Stencil<ByteArray> ByteStencil;
00118 
00119     // ecl_compile_time_concept_check(ecl::concepts::ByteContainer<FixedStencil>); // this one fails
00120     ecl_compile_time_concept_check(UnsignedByteContainerConcept<ByteArray>);
00121     ecl_compile_time_concept_check(UnsignedByteContainerConcept<ByteStencil>);
00122     SUCCEED();
00123 }
00124 
00125 TEST(StencilTests,byteStrings) {
00126 
00127         std::string str("dude");
00128     Stencil<std::string> stencil( str, str.begin(), str.end() );
00129         EXPECT_EQ(4,stencil.size());
00130         EXPECT_EQ('d',stencil[0]);
00131         EXPECT_EQ('u',stencil[1]);
00132         EXPECT_EQ('d',stencil[2]);
00133         EXPECT_EQ('e',stencil[3]);
00134 //    for ( unsigned int i = 0; i < stencil.size(); ++i ) {
00135 //      std::cout << i << ": " << stencil[i] << std::endl;
00136 //    }
00137 
00138     SUCCEED();
00139 }
00140 
00141 
00142 /*****************************************************************************
00143 ** Main program
00144 *****************************************************************************/
00145 
00146 int main(int argc, char **argv) {
00147         testing::InitGoogleTest(&argc,argv);
00148     return RUN_ALL_TESTS();
00149 }
00150 
00151 


ecl_containers
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:29