Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah_stdc_utils_test.cc
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
44#include <gtest/gtest.h>
45
46#include <ah_stdc++_utils.H>
47
48#include <stdexcept>
49
50using namespace Aleph;
51
52// ============================================================================
53// Mock Container and Iterator for testing
54// ============================================================================
55
56namespace
57{
58
59// Simple mock container
60class MockContainer
61{
62 int id_;
63
64public:
65 explicit MockContainer(int id) : id_(id) {}
66 int id() const { return id_; }
67};
68
69// Mock iterator that tracks which container it belongs to
70class MockIterator
71{
72 const MockContainer* container_;
73
74public:
75 explicit MockIterator(const MockContainer* c = nullptr) : container_(c) {}
76
77 // Verify this iterator belongs to the given container
78 bool verify(const MockContainer& c) const
79 {
80 return container_ == &c;
81 }
82
83 // Verify this iterator and another belong to the same container
84 bool verify(const MockIterator& other) const
85 {
86 return container_ == other.container_;
87 }
88
89 const MockContainer* container() const { return container_; }
90};
91
92} // namespace
93
94// ============================================================================
95// verify_container_and_iterator Tests
96// ============================================================================
97
99{
100 MockContainer container(1);
101 MockIterator iter(&container);
102
104}
105
114
116{
117 MockContainer container(1);
118 MockIterator iter(nullptr);
119
120 EXPECT_THROW(verify_container_and_iterator(container, iter), std::domain_error);
121}
122
124{
127 MockIterator iter(&container1);
128
129 try
130 {
132 FAIL() << "Expected exception was not thrown";
133 }
134 catch (const std::domain_error& e)
135 {
136 std::string msg = e.what();
137 EXPECT_TRUE(msg.find("Iterator") != std::string::npos ||
138 msg.find("iterator") != std::string::npos);
139 }
140}
141
142// ============================================================================
143// verify_iterators Tests
144// ============================================================================
145
147{
148 MockContainer container(1);
149 MockIterator iter1(&container);
150 MockIterator iter2(&container);
151
153}
154
156{
159 MockIterator iter1(&container1);
160 MockIterator iter2(&container2);
161
162 EXPECT_THROW(verify_iterators(iter1, iter2), std::domain_error);
163}
164
166{
167 MockContainer container(1);
168 MockIterator iter(&container);
169
170 // Same iterator compared to itself should pass
172}
173
175{
176 MockIterator iter1(nullptr);
177 MockIterator iter2(nullptr);
178
179 // Both null - same "container" (none)
181}
182
184{
185 MockContainer container(1);
186 MockIterator iter1(&container);
187 MockIterator iter2(nullptr);
188
189 EXPECT_THROW(verify_iterators(iter1, iter2), std::domain_error);
190}
191
192// ============================================================================
193// verify_container_and_iterators (2-iterator overload) Tests
194// ============================================================================
195
197{
198 MockContainer container(1);
199 MockIterator iter1(&container);
200 MockIterator iter2(&container);
201
203}
204
206{
209 MockIterator iter1(&container2); // Wrong container
210 MockIterator iter2(&container1);
211
213 std::domain_error);
214}
215
217{
220 MockIterator iter1(&container1);
221 MockIterator iter2(&container2); // Wrong container
222
224 std::domain_error);
225}
226
237
238// ============================================================================
239// verify_container_and_iterators (3-iterator overload) Tests
240// ============================================================================
241
254
268
282
284{
285 MockContainer container(1);
286
287 MockIterator dest_iter(&container);
288 MockIterator src_iter1(&container); // Same as dest!
289 MockIterator src_iter2(&container);
290
291 // This should throw because dest and source are the same container
293 container, dest_iter, src_iter1, src_iter2), std::domain_error);
294}
295
296// ============================================================================
297// Integration with real Aleph containers (if available)
298// ============================================================================
299
300// Note: Additional tests with real DynList/DynArray iterators could be added
301// here to verify integration with actual Aleph container types.
302
303int main(int argc, char** argv)
304{
305 ::testing::InitGoogleTest(&argc, argv);
306 return RUN_ALL_TESTS();
307}
int main()
Iterator and container validation utilities.
#define FAIL(msg)
#define TEST(name)
void verify()
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
void verify_container_and_iterators(const Container &container, const Iterator &itor_container, const Iterator &itor1, const Iterator &itor2)
Verifies container-iterator relationships with distinctness check.
void verify_iterators(const Iterator &itor1, const Iterator &itor2)
Verifies that two iterators belong to the same container.
void verify_container_and_iterator(const Container &container, const Iterator &itor)
Verifies that an iterator belongs to a specific container.
DynList< T > maps(const C &c, Op op)
Classic map operation.