Skip to content

Commit e3eb951

Browse files
authored
Merge pull request #16 from vinitjames/feature/tests
Feature/tests
2 parents c4c5c50 + 0a0189d commit e3eb951

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

circular_buffer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#ifndef CIRCULAR_BUFFER_H
22
#define CIRCULAR_BUFFER_H
33

4-
#include <iostream>
4+
#include <algorithm>
5+
#include <iterator>
56
#include <mutex>
67
#include <memory>
7-
#include <iterator>
8-
#include <algorithm>
8+
#include <stdexcept>
99
#include <utility>
1010

11+
1112
template<typename T>
1213
class CircularBuffer {
1314
private:

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");

tests/member_func_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "circular_buffer.h"
2-
#include <iostream>
32
#include <string.h>
43
#include <utility>
54
#include "gtest/gtest.h"

0 commit comments

Comments
 (0)