@@ -316,6 +316,38 @@ TEST_F(CircularBufferTest, BeginIteratorTest){
316316 }
317317}
318318
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+
319351TEST_F (CircularBufferTest, CbeginIteratorTest){
320352 // create full buffer
321353 for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
@@ -334,7 +366,8 @@ TEST_F(CircularBufferTest, CbeginIteratorTest){
334366 catch (const std::out_of_range& err){
335367 EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
336368 }
337- }
369+ }
370+
338371
339372TEST_F (CircularBufferTest, EndIteratorTest){
340373 // create full buffer
@@ -369,6 +402,39 @@ TEST_F(CircularBufferTest, EndIteratorTest){
369402 }
370403}
371404
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+
372438TEST_F (CircularBufferTest, CendIteratorTest){
373439 // create full buffer
374440 for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
0 commit comments