Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
advanced_structures_test.cpp
Go to the documentation of this file.
2#include "gtest/gtest.h"
3#include <algorithm>
4#include <iostream>
5#include <random>
6#include <vector>
7
8using namespace advanced_structures;
9
10/**
11 * @brief Helper function to print a vector
12 * @tparam T The type of elements in the vector
13 * @param vec The vector to print
14 */
15template <typename T>
16void printVector(const std::vector<T>& vec) {
17 std::cout << "[";
18 for (size_t i = 0; i < vec.size(); ++i) {
19 std::cout << vec[i];
20 if (i < vec.size() - 1) {
21 std::cout << ", ";
22 }
23 }
24 std::cout << "]";
25}
26
27/**
28 * @brief Test fixture for ChunkSkipList tests
29 */
30class ChunkSkipListTest : public ::testing::Test {
31protected:
32 void SetUp() override {
33 test_data = {1, 2, 3, 4, 5};
34 }
35 std::vector<int> test_data;
36};
37
38/**
39 * @brief Test fixture for ChunkBPlusTree tests
40 */
41class ChunkBPlusTreeTest : public ::testing::Test {
42protected:
43 void SetUp() override {
44 test_data = {1, 2, 3, 4, 5};
45 }
46 std::vector<int> test_data;
47};
48
49/**
50 * @brief Tests basic operations of ChunkSkipList
51 */
52TEST_F(ChunkSkipListTest, BasicOperations) {
53 ChunkSkipList<int> skip_list;
54
55 // Test insertion
56 skip_list.insert(5);
57 skip_list.insert(10);
58 skip_list.insert(7);
59
60 // Test search
61 EXPECT_TRUE(skip_list.search(5));
62 EXPECT_TRUE(skip_list.search(7));
63 EXPECT_TRUE(skip_list.search(10));
64 EXPECT_FALSE(skip_list.search(6));
65
66 // Test with random data
67 std::vector<int> numbers(100);
68 std::iota(numbers.begin(), numbers.end(), 1);
69 std::random_device rd;
70 std::mt19937 gen(rd());
71 std::shuffle(numbers.begin(), numbers.end(), gen);
72
73 ChunkSkipList<int> large_list;
74 for (int num : numbers) {
75 large_list.insert(num);
76 }
77
78 // Verify all numbers can be found
79 for (int num : numbers) {
80 EXPECT_TRUE(large_list.search(num));
81 }
82}
83
84/**
85 * @brief Tests basic operations of ChunkBPlusTree
86 */
87TEST_F(ChunkBPlusTreeTest, BasicOperations) {
89
90 // Test insertion
91 std::vector<int> values = {3, 7, 1, 5, 9, 2, 8, 4, 6};
92 for (int val : values) {
93 tree.insert(val);
94 }
95
96 // Test if values exist in tree
97 for (int val : values) {
98 EXPECT_TRUE(tree.search(val));
99 }
100
101 // Test non-existent values
102 EXPECT_FALSE(tree.search(0));
103 EXPECT_FALSE(tree.search(10));
104}
105
106/**
107 * @brief Stress test for ChunkSkipList
108 */
110 ChunkSkipList<int> skip_list;
111 const int NUM_ELEMENTS = 10000;
112
113 // Insert many elements
114 for (int i = 0; i < NUM_ELEMENTS; i++) {
115 skip_list.insert(i);
116 }
117
118 // Verify all elements can be found
119 for (int i = 0; i < NUM_ELEMENTS; i++) {
120 EXPECT_TRUE(skip_list.search(i));
121 }
122
123 // Verify non-existent elements are not found
124 for (int i = NUM_ELEMENTS; i < NUM_ELEMENTS + 100; i++) {
125 EXPECT_FALSE(skip_list.search(i));
126 }
127}
128
129/**
130 * @brief Tests empty operations of ChunkSkipList
131 */
132TEST_F(ChunkSkipListTest, EmptyOperations) {
134 EXPECT_TRUE(list.search(1) == false);
135 EXPECT_TRUE(list.search(0) == false);
136}
137
138/**
139 * @brief Tests edge cases for ChunkBPlusTree
140 */
143 tree.insert(1);
144 tree.insert(2);
145
146 // Verify insertions using find
147 EXPECT_TRUE(tree.search(1));
148 EXPECT_TRUE(tree.search(2));
149 EXPECT_FALSE(tree.search(3));
150}
151
152/**
153 * @brief Tests basic operations of ChunkDeque
154 */
155TEST(ChunkDequeTest, BasicOperations) {
156 ChunkDeque<int> deque;
157 EXPECT_TRUE(deque.empty());
158
159 deque.push_back(1);
160 deque.push_front(0);
161 EXPECT_EQ(deque.size(), 2);
162
163 EXPECT_EQ(deque.pop_back(), 1);
164 EXPECT_EQ(deque.pop_front(), 0);
165 EXPECT_TRUE(deque.empty());
166}
167
168/**
169 * @brief Tests basic operations of ChunkStack
170 */
171TEST(ChunkStackTest, BasicOperations) {
172 ChunkStack<int> stack;
173 EXPECT_TRUE(stack.empty());
174
175 stack.push(1);
176 stack.push(2);
177 EXPECT_EQ(stack.size(), 2);
178
179 EXPECT_EQ(stack.pop(), 2);
180 EXPECT_EQ(stack.pop(), 1);
181 EXPECT_TRUE(stack.empty());
182}
183
184/**
185 * @brief Tests basic operations of ChunkTreap
186 */
187TEST(ChunkTreapTest, BasicOperations) {
188 ChunkTreap<int> treap;
189 EXPECT_FALSE(treap.search(5));
190
191 treap.insert(5);
192 treap.insert(3);
193 treap.insert(8);
194
195 EXPECT_TRUE(treap.search(5));
196 EXPECT_TRUE(treap.search(3));
197 EXPECT_TRUE(treap.search(8));
198 EXPECT_FALSE(treap.search(10));
199}
200
201/**
202 * @brief Tests basic operations of SemanticBoundariesChunk
203 */
204TEST(SemanticBoundariesChunkTest, BasicOperations) {
206 std::vector<std::string> data = {"This", "is", "a", "test", "sentence"};
207 auto result = chunk.chunk(data);
208 EXPECT_GT(result.size(), 0);
209}
210
211/**
212 * @brief Tests basic operations of FractalPatternsChunk
213 */
214TEST(FractalPatternsChunkTest, BasicOperations) {
216 std::vector<int> data = {1, 2, 3, 4, 5, 1, 2, 3};
217 auto result = chunk.chunk(data);
218 EXPECT_GT(result.size(), 0);
219}
220
221/**
222 * @brief Tests basic operations of BloomFilterChunk
223 */
224TEST(BloomFilterChunkTest, BasicOperations) {
226 std::vector<int> data = {1, 2, 3, 4, 5};
227 auto result = chunk.chunk(data);
228 EXPECT_GT(result.size(), 0);
229}
230
231/**
232 * @brief Tests basic operations of GraphBasedChunk
233 */
234TEST(GraphBasedChunkTest, BasicOperations) {
236 std::vector<int> data = {1, 2, 3, 4, 5};
237 auto result = chunk.chunk(data);
238 EXPECT_GT(result.size(), 0);
239}
void printVector(const std::vector< T > &vec)
Helper function to print a vector.
TEST_F(ChunkSkipListTest, BasicOperations)
Tests basic operations of ChunkSkipList.
TEST(ChunkDequeTest, BasicOperations)
Tests basic operations of ChunkDeque.
Test fixture for ChunkBPlusTree tests.
Test fixture for ChunkSkipList tests.
Bloom filter-based chunking implementation.
std::vector< std::vector< T > > chunk(const std::vector< T > &data)
A B+ tree implementation for chunk indexing.
void insert(const T &key)
Inserts a key into the B+ tree.
bool search(const T &key) const
Searches for a key in the B+ tree.
A deque-based chunk structure for double-ended operations.
A skip list implementation for efficient chunk searching.
void insert(const T &value)
Inserts a value into the skip list.
bool search(const T &value) const
Searches for a value in the skip list.
A stack-based chunk structure for LIFO operations.
A treap implementation for efficient chunk searching and manipulation.
std::shared_ptr< Node > insert(std::shared_ptr< Node > node, T value, int priority)
bool search(const std::shared_ptr< Node > &node, T value) const
Fractal pattern-based chunking implementation.
std::vector< std::vector< T > > chunk(const std::vector< T > &data)
Graph-based chunking implementation.
std::vector< std::vector< T > > chunk(const std::vector< T > &data)
Semantic boundaries-based chunking implementation.
std::vector< std::vector< T > > chunk(const std::vector< T > &data)