Skip to content

Commit c0362ad

Browse files
committed
added reverse iterator loop tests
1 parent 6a8b604 commit c0362ad

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/iterator_test.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "circular_buffer.h"
22
#include <algorithm>
3-
#include <iostream>
4-
#include <string.h>
3+
#include <string>
54
#include <utility>
65
#include "gtest/gtest.h"
76

@@ -35,6 +34,23 @@ TEST_F(CircularBufferTest, IteratorBasedLoopTest){
3534
EXPECT_EQ(i, TEST_BUFFER_SIZE/2);
3635
}
3736

37+
TEST_F(CircularBufferTest, ReverseIteratorBasedLoopTest){
38+
//create full buffer
39+
for(int i=0; i<TEST_BUFFER_SIZE; i++)
40+
test_str_buff.push_back("string" + std::to_string(i));
41+
int i = 99;
42+
for(auto it = test_str_buff.rbegin(); it!=test_str_buff.rend(); it++)
43+
EXPECT_EQ(*it, "string" + std::to_string(i--));
44+
//partially fill buffers
45+
test_str_buff.clear();
46+
for(int i=0; i<TEST_BUFFER_SIZE/2; i++)
47+
test_str_buff.push_back("string" + std::to_string(i));
48+
//test begin and end on partially full buffer
49+
i = TEST_BUFFER_SIZE/2 - 1;
50+
for(auto it = test_str_buff.rbegin(); it!=test_str_buff.rend(); it++)
51+
EXPECT_EQ(*it, "string" + std::to_string(i--));
52+
}
53+
3854
TEST_F(CircularBufferTest, RangeBasedLoopTest){
3955
//create full buffer
4056
for(int i=0; i<TEST_BUFFER_SIZE; i++)
@@ -79,7 +95,8 @@ TEST_F(CircularBufferTest, ForEachTest){
7995
//create full buffer
8096
for(int i=0; i<TEST_BUFFER_SIZE; i++)
8197
test_str_buff.push_back("string" + std::to_string(i));
82-
std::for_each(test_str_buff.begin(), test_str_buff.end(), [](std::string& elem){ elem = elem + "modified";});
98+
std::for_each(test_str_buff.begin(), test_str_buff.end(), [](std::string& elem){
99+
elem = elem + "modified";});
83100
int i=0;
84101
for(const auto& elem: test_str_buff)
85102
EXPECT_EQ(elem, "string" + std::to_string(i++) + "modified");

0 commit comments

Comments
 (0)