43#include <gtest/gtest.h>
52using namespace testing;
73 auto other = std::make_unique<Slinknc>();
85 auto other = std::make_unique<Slinknc>();
143 string str =
"Hello World";
163 EXPECT_EQ(n1.get_next()->get_next()->get_data(), 3);
216 delete list.remove_first();
229 delete list.remove_first();
239 EXPECT_EQ(list.get_first()->to_data<
int>(), 1);
240 EXPECT_EQ(list.get_last()->to_data<
int>(), 3);
243 list.remove_all_and_delete();
253 EXPECT_EQ(list.get_first()->to_data<
int>(), 1);
254 EXPECT_EQ(list.get_last()->to_data<
int>(), 3);
257 list.remove_all_and_delete();
272 for (
int i = 1; i <= 5; ++i)
294 Slinknc *first = list.get_first();
301 vector<int>
expected = {1, 10, 11, 12, 2, 3, 4, 5};
334 vector<int>
expected = {1, 2, 3, 20, 21, 4, 5};
354 Slinknc *last = list.get_last();
359 EXPECT_EQ(list.get_last()->to_data<
int>(), 31);
362 vector<int>
expected = {1, 2, 3, 4, 5, 30, 31};
376 Slinknc *first = list.get_first();
383 for (
int i = 1; i <= 5; ++i, it.
next())
458 for (
int i = 1; i <= 10; ++i)
478 for (
int i = 1; i <= 7; ++i)
519 for (
int i = 1; i <= 5; ++i)
545 for (
int i = 1; i <= 5; ++i)
551 vector<int>
expected = {2, 3, 4, 5, 1};
620 for (
int i = 0; i < 5; ++i)
623 for (
int i = 0; i < 5; ++i)
648 for (
int i = 1; i <= 10; ++i)
663 for (
auto it = list.get_it(); it.has_curr(); it.next())
679 {
return x == 10; });
689 list.remove([](
const int &x)
690 { return x == 100; }),
697 int result = list.remove_ne([](
const int &x)
698 {
return x == 100; });
716 for (
int i = 2; i <= 10; i += 2)
726 for (
auto it = list.get_it(); it.has_curr(); it.next())
737 for (
int i = 1; i <= 5; ++i)
745 auto it2 =
copy.get_it();
746 while (it1.has_curr())
748 EXPECT_EQ(it1.get_curr(), it2.get_curr());
757 for (
int i = 1; i <= 5; ++i)
769 for (
int i = 1; i <= 5; ++i)
784 for (
int i = 1; i <= 5; ++i)
797 for (
int i = 1; i <= 5; ++i)
813 for (
int i = 1; i <= 3; ++i)
815 for (
int i = 4; i <= 6; ++i)
818 list1.
append(std::move(list2));
824 for (
auto it = list1.
get_it(); it.has_curr(); it.next(), ++
expected)
832 for (
int i = 1; i <= 3; ++i)
834 for (
int i = 4; i <= 6; ++i)
847 for (
int i = 4; i <= 6; ++i)
849 for (
int i = 1; i <= 3; ++i)
852 list1.
insert(std::move(list2));
866 for (
int i = 1; i <= 5; ++i)
872 for (
auto it = list.
get_it(); it.has_curr(); it.next(), --
expected)
879 for (
int i = 1; i <= 5; ++i)
887 for (
auto it = list.
get_it(); it.has_curr(); it.next(), ++
expected)
907 for (
int i = 1; i <= 5; ++i)
915 for (
auto it = list.get_it(); it.has_curr(); it.next(), ++
expected)
924 int deleted = it.
del();
936 int deleted = it.
del();
1007 constexpr size_t N = 100000;
1010 for (
size_t i = 0; i <
N; ++i)
1011 list.
append(
static_cast<int>(i));
1025 constexpr size_t OPS = 10000;
1028 std::mt19937
rng(42);
1029 std::uniform_int_distribution<int>
opDist(0, 3);
1030 std::uniform_int_distribution<int>
valDist(0, 1000);
1032 for (
size_t i = 0; i <
OPS; ++i)
1057 for (
auto it = list.
get_it(); it.has_curr(); it.next())
1095 for (
int i = 1; i <= 10; ++i)
Iterator on the items of list.
T & get_curr() const
Return the current item.
T del()
Remove the current item of the iterator.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
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.
T remove_ne() noexcept
Remove the first item of the list without exception.
T remove()
Remove the first item of the list.
DynList & reverse() noexcept
long get_pos() const noexcept
Return the current position.
void reset_last()
It has O(n) of performance.
bool is_last() const noexcept
void next()
Move the iterator one item forward.
Slinknc * get_curr() const
Return the current node on which the iterator is positioned.
bool has_curr() const noexcept
Return true if iterator has current item.
void end() noexcept
Set the iterator to its end position, which has not current item.
void reset() noexcept
Reset the iterator at the first item.
Single linked list of nodes.
Slinknc * get_first() const noexcept
Return list first element.
void push(Slinknc *link) noexcept
Insert link as first element.
void put(Slinknc *link) noexcept
Insert link as last element.
size_t reverse_list() noexcept
void remove_all_and_delete() noexcept
Remove and free memory for all the items of list.
size_t reverse() noexcept
It inverts all list elements.
void cut_list(Slinknc *link, HTList &list) noexcept
constexpr bool is_empty() const noexcept
Return true if list is empty.
void rotate_left(size_t n)
Rotate to left the list n positions.
void concat_list(HTList &l) noexcept
void append(Slinknc *link) noexcept
Insert link as last element.
size_t split_list(HTList &l, HTList &r) noexcept
It divides 'this' into two equal lists without modifying elements order.
size_t split(HTList &l, HTList &r) noexcept
size_t size() const noexcept
Count the number of elements of the list.
bool remove(Slinknc *link)
Remove from the list the item pointed by link
bool is_unitarian() const noexcept
Return true if the list contains exactly just one element.
Slinknc * get_last() const noexcept
Return the last item of the list (nullptr if the list is empty)
size_t split_list_ne(HTList &l, HTList &r) noexcept
void concat(HTList &l) noexcept
Concat to 'this' all 'l' list; 'l' becomes empty.
Iterator on single links.
void next()
Move the iterator one position forward.
bool has_curr() const noexcept
Return true if the iterator is positioned on a valid link.
Slinknc * get_curr() const
Return the current link on which the iterator is positioned.
Link of a single linked list non-circular and without header node.
Slinknc *& get_next() noexcept
getter
constexpr bool is_empty() const noexcept
Return true if this is empty.
Snodenc< T > * to_snodenc() noexcept
Convert this to a Snodenc<T>.
void insert(Slinknc *p) noexcept
Insert p after this
Node belonging to a single non-circular linked list without header node.
T & get_data() noexcept
Return a modifiable reference to the data.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Singly linked list implementations with head-tail access.
TEST_F(SlinkcTest, DefaultConstructor)
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.
bool operator==(const TestStruct &other) const