@@ -316,6 +316,38 @@ TEST_F(CircularBufferTest, BeginIteratorTest){
316
316
}
317
317
}
318
318
319
+ TEST_F (CircularBufferTest, RbeginIteratorTest){
320
+ // create full buffer
321
+ for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
322
+ test_buff.push_back (" string" + std::to_string (i));
323
+ // test first element with iterator
324
+ CircularBuffer<std::string>::iterator it = test_buff.rbegin ();
325
+ // access with rbegin iterator
326
+ for (int i=TEST_BUFFER_SIZE-1 ; i>=0 ; i--)
327
+ EXPECT_EQ (*(it++), " string" + std::to_string (i));
328
+
329
+ // access with const begin iterator
330
+ CircularBuffer<std::string>::const_iterator const_it = test_buff.rbegin ();
331
+ for (int i=TEST_BUFFER_SIZE - 1 ; i>=0 ; i--)
332
+ EXPECT_EQ (*(const_it++), " string" + std::to_string (i));
333
+ // test out of bounds
334
+ try {
335
+ *it = " test_string" ;
336
+ FAIL () << " Expected std::out_of_range error" ;
337
+ }
338
+ catch (const std::out_of_range& err){
339
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
340
+ }
341
+
342
+ try {
343
+ std::string out_of_bound = *(const_it);
344
+ FAIL () << " Expected std::out_of_range error" ;
345
+ }
346
+ catch (const std::out_of_range& err){
347
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
348
+ }
349
+ }
350
+
319
351
TEST_F (CircularBufferTest, CbeginIteratorTest){
320
352
// create full buffer
321
353
for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
@@ -334,7 +366,8 @@ TEST_F(CircularBufferTest, CbeginIteratorTest){
334
366
catch (const std::out_of_range& err){
335
367
EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
336
368
}
337
- }
369
+ }
370
+
338
371
339
372
TEST_F (CircularBufferTest, EndIteratorTest){
340
373
// create full buffer
@@ -369,6 +402,39 @@ TEST_F(CircularBufferTest, EndIteratorTest){
369
402
}
370
403
}
371
404
405
+ TEST_F (CircularBufferTest, RendIteratorTest){
406
+ // create full buffer
407
+ for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
408
+ test_buff.push_back (" string" + std::to_string (i));
409
+ // test first element with iterator
410
+ CircularBuffer<std::string>::iterator it = test_buff.rend () - 1 ;
411
+ // access with rbegin iterator
412
+ for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
413
+ EXPECT_EQ (*(it--), " string" + std::to_string (i));
414
+
415
+ // access with const begin iterator
416
+ CircularBuffer<std::string>::const_iterator const_it = test_buff.rend () - 1 ;
417
+ for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
418
+ EXPECT_EQ (*(const_it--), " string" + std::to_string (i));
419
+ // test out of bounds
420
+ try {
421
+ *it = " test_string" ;
422
+ FAIL () << " Expected std::out_of_range error" ;
423
+ }
424
+ catch (const std::out_of_range& err){
425
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
426
+ }
427
+
428
+ try {
429
+ std::string out_of_bound = *(const_it);
430
+ FAIL () << " Expected std::out_of_range error" ;
431
+ }
432
+ catch (const std::out_of_range& err){
433
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
434
+ }
435
+ }
436
+
437
+
372
438
TEST_F (CircularBufferTest, CendIteratorTest){
373
439
// create full buffer
374
440
for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
0 commit comments