4 #include <UnitTest++.h>
10 struct LongIntFixtureBlank
13 LongIntFixtureBlank() {}
14 ~LongIntFixtureBlank() {}
18 struct LongIntFixtureGeneric
21 LongIntFixtureGeneric()
24 for(
int i=5; i < 10; ++i )
27 ~LongIntFixtureGeneric() {}
30 typedef LongIntFixtureGeneric<false> LongIntFixture;
31 typedef LongIntFixtureGeneric<true> LongIntFixtureBC;
33 struct LongIntFixtureFill
39 for(
int i=5; i < 10; ++i )
42 ~LongIntFixtureFill() {}
47 for( p=arr.begin(); p != arr.end(); ++p )
58 for(
int i=5; i < 10; ++i )
70 for(
int i=5; i < 10; ++i )
76 struct StructWithConstructorFixture
85 StructWithConstructorFixture()
89 ~StructWithConstructorFixture() {}
92 struct TestAllocFixture
95 ~TestAllocFixture() {}
105 for (
int i=2; i<20; ++i)
115 TEST_FIXTURE(LongIntFixture,TestZero)
118 for(
int i=5; i < 10; ++i )
119 CHECK_EQUAL(0,arr[i]);
124 TEST_FIXTURE(LongIntFixture,TestInvalidate1)
127 for(
int i=5; i < 10; ++i )
128 CHECK_EQUAL(-1,arr[i]);
133 TEST_FIXTURE(RealNumFixture,TestInvalidate2)
136 for(
int i=5; i < 10; ++i )
137 CHECK(
isnan(arr[i]));
142 TEST_FIXTURE(DoubleFixture,TestInvalidate3)
145 for(
int i=5; i < 10; ++i )
146 CHECK(
isnan(arr[i]));
151 TEST_FIXTURE(LongIntFixtureBC,TestAccess1)
153 for(
int i=5; i < 10; ++i )
154 CHECK_EQUAL(i,arr[i]);
155 CHECK_THROW(arr[4],out_of_range);
156 CHECK_THROW(arr[10],out_of_range);
158 for(
int i=5; i < 10; ++i )
159 CHECK_EQUAL(i,(*carr)[i]);
160 CHECK_THROW((*carr)[4],out_of_range);
161 CHECK_THROW((*carr)[10],out_of_range);
164 TEST_FIXTURE(LongIntFixtureBC,TestAccess2)
166 for(
int i=5; i < 10; ++i )
167 CHECK_EQUAL(i,arr[i]);
168 CHECK_THROW(arr[4],out_of_range);
169 CHECK_THROW(arr[10],out_of_range);
171 for(
int i=5; i < 10; ++i )
172 CHECK_EQUAL(i,(*carr)[i]);
173 CHECK_THROW((*carr)[4],out_of_range);
174 CHECK_THROW((*carr)[10],out_of_range);
177 TEST_FIXTURE(LongIntFixture,TestAccess3)
179 for(
int i=5; i < 10; ++i )
180 CHECK_EQUAL(i,*arr.ptr(i));
182 for(
int i=5; i < 10; ++i )
183 CHECK_EQUAL(i,*carr->
ptr(i));
186 TEST_FIXTURE(LongIntFixtureBC,TestAccess4)
188 for(
int i=5; i < 10; ++i )
189 CHECK_EQUAL(i,*arr.ptr(i));
190 CHECK_THROW(*arr.ptr(4),out_of_range);
191 CHECK_THROW(*arr.ptr(10),out_of_range);
193 for(
int i=5; i < 10; ++i )
194 CHECK_EQUAL(i,*carr->ptr(i));
195 CHECK_THROW(*carr->ptr(4),out_of_range);
196 CHECK_THROW(*carr->ptr(10),out_of_range);
199 TEST_FIXTURE(LongIntFixture,TestAccess5)
201 for(
int i=5; i < 10; ++i )
202 CHECK_EQUAL(i,arr.at(i));
203 CHECK_THROW(arr.at(4),out_of_range);
204 CHECK_THROW(arr.at(10),out_of_range);
206 for(
int i=5; i < 10; ++i )
207 CHECK_EQUAL(i,carr->at(i));
208 CHECK_THROW(carr->at(4),out_of_range);
209 CHECK_THROW(carr->at(10),out_of_range);
213 TEST_FIXTURE(LongIntFixture,TestStateDo)
215 const char *fnam =
"tfa.872GqS";
218 arr.state_do( io,
false );
223 arr.state_do( io,
true );
226 CHECK_EQUAL(7,arr[7]);
229 TEST_FIXTURE(LongIntFixtureBC,TestBoundaries)
231 CHECK( arr.begin() == arr.ptr(5) );
232 CHECK( arr.end() == arr.ptr(10) );
233 CHECK( &arr.front() == &arr[5] );
234 CHECK( &arr.back() == &arr[9] );
235 CHECK( arr.data() == &arr[5] );
236 CHECK( arr.ptr0() == &arr[5]-5 );
238 CHECK( carr->begin() == arr.ptr(5) );
239 CHECK( carr->end() == arr.ptr(10) );
240 CHECK( &carr->front() == &arr[5] );
241 CHECK( &carr->back() == &arr[9] );
242 CHECK( carr->data() == &arr[5] );
243 CHECK( carr->ptr0() == &arr[5]-5 );
246 TEST_FIXTURE(LongIntFixtureFill,TestRealloc)
249 for(
int i=5; i < 10; ++i )
250 CHECK_EQUAL( i-4, arr[i] );
251 long *pold = arr.data();
253 long *pnew = arr.data();
254 CHECK( pold != pnew );
255 for(
int i=5; i < 10; ++i )
256 CHECK_EQUAL( i-4, arr[i] );
259 TEST_FIXTURE(LongIntFixtureBlank,TestAllocationWithoutReservation)
261 CHECK_EQUAL(0L,arr.size());
262 CHECK_EQUAL(0L,arr.capacity());
263 CHECK( arr.empty() );
265 CHECK_EQUAL(5L,arr.size());
266 CHECK_EQUAL(5L,arr.capacity());
267 CHECK( !arr.empty() );
269 CHECK_EQUAL(25L,arr.size());
270 CHECK_EQUAL(25L,arr.capacity());
271 CHECK( !arr.empty() );
273 CHECK_EQUAL(5L,arr.size());
274 CHECK_EQUAL(25L,arr.capacity());
275 CHECK( !arr.empty() );
277 CHECK_EQUAL(0L,arr.size());
278 CHECK_EQUAL(25L,arr.capacity());
279 CHECK( arr.empty() );
281 CHECK_EQUAL(0L,arr.size());
282 CHECK_EQUAL(0L,arr.capacity());
283 CHECK( arr.empty() );
285 CHECK_EQUAL(17L,arr.size());
286 CHECK_EQUAL(17L,arr.capacity());
287 CHECK( !arr.empty() );
289 CHECK_EQUAL(0L,arr.size());
290 CHECK_EQUAL(0L,arr.capacity());
291 CHECK( arr.empty() );
293 CHECK_EQUAL(0L,arr.size());
294 CHECK_EQUAL(0L,arr.capacity());
295 CHECK( arr.empty() );
297 CHECK_EQUAL(35L,arr.size());
298 CHECK_EQUAL(35L,arr.capacity());
299 CHECK( !arr.empty() );
302 TEST_FIXTURE(LongIntFixtureBlank,TestAllocationWithReservation)
305 CHECK_EQUAL(0L,arr.size());
306 CHECK_EQUAL(100L,arr.capacity());
307 CHECK( arr.empty() );
309 CHECK_EQUAL(5L,arr.size());
310 CHECK_EQUAL(100L,arr.capacity());
311 CHECK( !arr.empty() );
313 CHECK_EQUAL(25L,arr.size());
314 CHECK_EQUAL(100L,arr.capacity());
315 CHECK( !arr.empty() );
317 CHECK_EQUAL(195L,arr.size());
318 CHECK_EQUAL(195L,arr.capacity());
319 CHECK( !arr.empty() );
321 CHECK_EQUAL(0L,arr.size());
322 CHECK_EQUAL(5L,arr.capacity());
323 CHECK( arr.empty() );
325 CHECK_EQUAL(0L,arr.size());
326 CHECK_EQUAL(5L,arr.capacity());
327 CHECK( arr.empty() );
329 CHECK_EQUAL(0L,arr.size());
330 CHECK_EQUAL(0L,arr.capacity());
331 CHECK( arr.empty() );
333 CHECK_EQUAL(0L,arr.size());
334 CHECK_EQUAL(10L,arr.capacity());
335 CHECK( arr.empty() );
337 CHECK_EQUAL(20L,arr.size());
338 CHECK_EQUAL(20L,arr.capacity());
339 CHECK( !arr.empty() );
342 TEST_FIXTURE(StructWithConstructorFixture,TestAllocationWithConstructor)
344 for(
int i=7; i < 12; ++i )
345 CHECK_EQUAL(23,arr[i].n);
350 TEST_FIXTURE(TestAllocFixture,TestVariantAlloc)
352 CHECK_EQUAL(0,mytest());
355 TEST_FIXTURE(LongIntFixtureBC,TestCopyOperator)
358 CHECK( arr.size() != arr2.size() );
360 CHECK_EQUAL(0,arr2[114]);
362 CHECK( arr.size() == arr2.size() );
364 CHECK( &arr[5] != &arr2[5] );
365 for (
int i=5; i<10; ++i)
366 CHECK_EQUAL(i,arr2[i]);
368 CHECK_THROW(arr2[4],out_of_range);
369 CHECK_THROW(arr2[10],out_of_range);
375 CHECK_EQUAL(9,arr2[9]);
379 CHECK( arr.size() == arr3.
size() );
381 CHECK( &arr[5] != &arr3[5] );
382 for (
int i=5; i<10; ++i)
383 CHECK_EQUAL(i,arr3[i]);
387 CHECK_EQUAL(0L,arr2.size());
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
pntr - interface class to replace normal pointers
void alloc(size_type begin, size_type end)
iterator ptr(size_type i)