-
Notifications
You must be signed in to change notification settings - Fork 2
/
InsertionBufferTest.cpp
63 lines (48 loc) · 1.24 KB
/
InsertionBufferTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "InsertionBuffer.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace dyden {
TEST(InsertionBufferTest, ctor) {
InsertionBuffer<int> a;
}
TEST(InsertionBufferTest, addValue) {
InsertionBuffer<int> uut;
for (int i = 0; i < 20; i++) {
uut.addValue(i);
}
}
TEST(InsertionBufferTest, flush) {
InsertionBuffer<int> uut(25);
int total_flushed = 0;
int next_val = 1;
for (int i = 0; i < 20; i++) {
uut.addValue(next_val++);
}
for (auto it = uut.lockedIterator(); it; ++it) {
total_flushed += *it;
}
for (int i = 0; i < 10; i++) {
uut.addValue(next_val++);
}
for (auto it = uut.lockedIterator(); it; ++it) {
total_flushed += *it;
}
EXPECT_EQ(total_flushed, next_val * (next_val - 1) / 2);
}
TEST(InsertionBufferTest, overflow) {
InsertionBuffer<int> uut(/*buffer_size=*/10);
for (int i = 0; i < 20; i++) {
uut.addValue(i);
}
int num_flushed = 0;
int total_flushed = 0;
for (auto it = uut.lockedIterator(); it; ++it) {
num_flushed++;
total_flushed += *it;
}
EXPECT_EQ(num_flushed, 9);
// Only the last 9 values should be in the total, so subtract the first 11
// from the sum.
EXPECT_EQ(total_flushed, 20 * 19 / 2 - 11 * 10 / 2);
}
} // namespace dhist