41#include <gtest/gtest.h>
48using namespace testing;
121 FAIL() <<
"Expected underflow_error";
123 catch (
const std::underflow_error &e)
125 std::string msg = e.what();
126 EXPECT_NE(msg.find(
"empty"), std::string::npos)
127 <<
"Error message should mention 'empty': " << msg;
128 EXPECT_EQ(msg.find(
"not empty"), std::string::npos)
129 <<
"Error message should NOT say 'not empty': " << msg;
140 FAIL() <<
"Expected underflow_error";
142 catch (
const std::underflow_error &e)
144 std::string msg = e.what();
145 EXPECT_NE(msg.find(
"empty"), std::string::npos)
146 <<
"Error message should mention 'empty': " << msg;
147 EXPECT_EQ(msg.find(
"not empty"), std::string::npos)
148 <<
"Error message should NOT say 'not empty': " << msg;
210 list.insert(&
nodes[0]);
219 list.append(&
nodes[0]);
230 for (
size_t i = 0; i < 5; ++i)
231 list.insert(&
nodes[i]);
234 for (
int i = 4; i >= 0; --i, it.
next())
242 for (
size_t i = 0; i < 5; ++i)
243 list.append(&
nodes[i]);
246 for (
size_t i = 0; i < 5; ++i, it.
next())
252 list.append(&
nodes[2]);
253 list.insert(&
nodes[1]);
254 list.append(&
nodes[3]);
255 list.insert(&
nodes[0]);
358 for (
size_t i = start; i < start +
count; ++i)
365 list.concat_list(&aux);
372 populateList(aux, 0, 3);
374 list.concat_list(&aux);
384 populateList(list, 0, 3);
386 list.concat_list(&aux);
396 populateList(list, 0, 3);
397 populateList(aux, 3, 3);
399 list.concat_list(&aux);
407 for (
size_t i = 0; i < 6; ++i, it.
next())
413 populateList(list, 0, 3);
415 nodes[1].insert_list(&aux);
424 populateList(list, 0, 3);
425 populateList(aux, 10, 2);
427 nodes[0].insert_list(&aux);
448 populateList(list, 0, 3);
450 nodes[1].append_list(&aux);
469 list.append(&
nodes[0]);
482 populateList(list, 0, 6);
495 populateList(list, 0, 5);
506 populateList(list, 0, 5);
517 populateList(list, 0, 5);
530 populateList(list, 0, 5);
558 size_t count = list.reverse_list();
565 list.append(&
nodes[0]);
566 size_t count = list.reverse_list();
573 list.append(&
nodes[0]);
574 list.append(&
nodes[1]);
584 for (
size_t i = 0; i < 5; ++i)
585 list.append(&
nodes[i]);
587 size_t count = list.reverse_list();
595 for (
int i = 4; i >= 0; --i, it.
next())
601 for (
size_t i = 0; i < 5; ++i)
602 list.append(&
nodes[i]);
608 for (
size_t i = 0; i < 5; ++i, it.
next())
625 for (
size_t i = 0; i < 5; ++i)
635 for (
size_t i = 0; i < 5; ++i, it.
next())
660 for (
size_t i = 0; i < 5; ++i, it.
next())
666 list.rotate_right(1);
710 for (
size_t i = 0; i < 5; ++i)
711 list.append(&
nodes[i]);
722 for (
size_t i = 0; i < 5; ++i)
723 list.append(&
nodes[i]);
740 for (
size_t i = 0; i < 5; ++i)
741 list.append(&
nodes[i]);
752 for (
size_t i = 0; i < 5; ++i)
753 list.append(&
nodes[i]);
769 for (
size_t i = 0; i < 3; ++i)
770 list.append(&
nodes[i]);
787 for (
size_t i = 0; i < 3; ++i)
788 list.append(&
nodes[i]);
816 for (
size_t i = 0; i < 10; ++i)
839 constexpr size_t N = 10000;
844 for (
size_t i = 0; i <
N; ++i)
868 constexpr size_t N = 1000;
869 constexpr size_t OPS = 5000;
875 std::mt19937
rng(42);
876 std::uniform_int_distribution<size_t>
nodeDist(0,
N - 1);
877 std::uniform_int_distribution<int>
opDist(0, 3);
879 for (
size_t op = 0; op <
OPS; ++op)
904 for (
size_t i = 0; i <
N; ++i)
918 for (
size_t i = 0; i <
N; ++i)
962 list2 = std::move(list1);
1024 constexpr size_t N = 50000;
1029 for (
size_t i = 0; i <
N; ++i)
1043 for (
int i = 0; i < 5; ++i)
1058 constexpr size_t N = 1000;
1064 for (
size_t i = 0; i <
N; ++i)
1067 std::mt19937
rng(54321);
1096 constexpr size_t N = 2000;
1097 constexpr size_t OPS = 10000;
1101 vector<bool>
inList(
N,
false);
1104 std::mt19937
rng(12345);
1105 std::uniform_int_distribution<size_t>
nodeDist(0,
N - 1);
1106 std::uniform_int_distribution<int>
opDist(0, 4);
1108 for (
size_t op = 0; op <
OPS; ++op)
1135 for (
size_t i = 0; i <
N; ++i)
1150 for (
size_t i = 0; i <
N; ++i)
1183 constexpr size_t N = 1000;
1188 for (
size_t i = 0; i <
N; ++i)
1192 for (
size_t i = 0; i < 100; ++i)
1208 constexpr size_t N = 500;
1213 for (
size_t i = 0; i <
N; ++i)
1231 size_t remaining = 0;
constexpr bool is_in_first() const noexcept
Return true if the iterator is positiones on the first item.
bool has_curr() const noexcept
Return true if the iterator has current item.
Dlink * get_curr() const
Return the current node of iterator.
void next()
Move the iterator one position forward.
Dlink * del()
Remove from the list the current node and move the iterator one position forward.
void prev()
Move the iterator one position backward.
void reset_last() noexcept
Reset the iterator to the last item of list.
bool is_last() const noexcept
Doubly linked circular list node.
Dlink *& get_next() const noexcept
Return the link that is after this
void concat_list(Dlink *head) noexcept
Concatenate list head to list this
constexpr Dlink *& get_last() const noexcept
If this is a header node, it return the last node of this
Dlink * remove_first() noexcept
constexpr Dlink *& get_first() const noexcept
If this is a header node, it return the first node of this
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
size_t reverse_list() noexcept
Reverse the list.
void reset() noexcept
Reset this
void rotate_right(size_t n)
Analogous to rotate_left() but to right.
void append(Dlink *node) noexcept
Insert node before this.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
constexpr bool is_unitarian() const noexcept
Return true if this (as header node) has exactly one element.
Dlink * remove_last() noexcept
void rotate_left(size_t n)
Rotate to left the list n positions.
bool check()
Return true if the list is consistent.
size_t split_list(Dlink &l, Dlink &r) noexcept
Dlink *& get_prev() const noexcept
Return the link that is before this
Dlink cut_list(Dlink *link) noexcept
Cut this from link.
void insert(Dlink *node) noexcept
Insert node after this.
T & append(const T &item)
Append a new item by copy.
T & get_last() const
Return the last item of the list.
T & get_first() const
Return the first item of the list.
constexpr bool is_empty() const noexcept
Return true if list is empty.
void concat_list(HTList &l) noexcept
size_t split_list(HTList &l, HTList &r) noexcept
It divides 'this' into two equal lists without modifying elements order.
void populateList(Dlink &l, size_t start, size_t count)
Doubly linked circular list implementation.
TEST_F(DlinkBasicTest, DefaultConstructorCreatesEmptyList)
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.