|
1 | 1 | #include "circular_buffer.h" |
2 | 2 | #include <algorithm> |
3 | | -#include <iostream> |
4 | | -#include <string.h> |
| 3 | +#include <string> |
5 | 4 | #include <utility> |
6 | 5 | #include "gtest/gtest.h" |
7 | 6 |
|
@@ -35,6 +34,23 @@ TEST_F(CircularBufferTest, IteratorBasedLoopTest){ |
35 | 34 | EXPECT_EQ(i, TEST_BUFFER_SIZE/2); |
36 | 35 | } |
37 | 36 |
|
| 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 | + |
38 | 54 | TEST_F(CircularBufferTest, RangeBasedLoopTest){ |
39 | 55 | //create full buffer |
40 | 56 | for(int i=0; i<TEST_BUFFER_SIZE; i++) |
@@ -79,7 +95,8 @@ TEST_F(CircularBufferTest, ForEachTest){ |
79 | 95 | //create full buffer |
80 | 96 | for(int i=0; i<TEST_BUFFER_SIZE; i++) |
81 | 97 | 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";}); |
83 | 100 | int i=0; |
84 | 101 | for(const auto& elem: test_str_buff) |
85 | 102 | EXPECT_EQ(elem, "string" + std::to_string(i++) + "modified"); |
|
0 commit comments