├── .gitignore └── lab_02 ├── lab ├── baselist.cpp ├── baselist.h ├── constiterator.h ├── constiterator.hpp ├── errors.h ├── iterator.h ├── iterator.hpp ├── list.h ├── list.hpp ├── main.cpp ├── node.h └── node.hpp └── tests ├── main.cpp ├── testing_constructors.h ├── testing_iterators.h ├── testing_operators.h ├── testing_pop.h └── testing_push.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.pro 3 | *.pro.user 4 | *.pri 5 | *.o 6 | *.Debug 7 | *.Release 8 | *.stach -------------------------------------------------------------------------------- /lab_02/lab/baselist.cpp: -------------------------------------------------------------------------------- 1 | #include "baselist.h" 2 | #include 3 | 4 | BaseList::BaseList() noexcept 5 | { 6 | count = 0; 7 | } 8 | 9 | 10 | BaseList::BaseList(const BaseList &baselist) noexcept 11 | { 12 | count = baselist.count; 13 | } 14 | 15 | 16 | BaseList::~BaseList() {} 17 | 18 | 19 | bool BaseList::is_empty() const noexcept 20 | { 21 | return count == 0; 22 | } 23 | 24 | 25 | int BaseList::get_length() const noexcept 26 | { 27 | return count; 28 | } 29 | -------------------------------------------------------------------------------- /lab_02/lab/baselist.h: -------------------------------------------------------------------------------- 1 | #ifndef BASELIST_H 2 | #define BASELIST_H 3 | 4 | class BaseList 5 | { 6 | public: 7 | BaseList() noexcept; 8 | explicit BaseList(const BaseList &baselist) noexcept; 9 | virtual ~BaseList() = 0; 10 | 11 | bool is_empty() const noexcept; 12 | int get_length() const noexcept; 13 | 14 | private: 15 | int count; 16 | }; 17 | 18 | #endif // BASELIST_H 19 | -------------------------------------------------------------------------------- /lab_02/lab/constiterator.h: -------------------------------------------------------------------------------- 1 | #ifndef ConstIterator_H 2 | #define ConstIterator_H 3 | 4 | #include 5 | #include "list.h" 6 | 7 | using namespace std; 8 | 9 | 10 | template 11 | class ConstIterator : public std::iterator 12 | { 13 | friend class List; 14 | 15 | public: 16 | ConstIterator(const ConstIterator &it) = default; 17 | 18 | Type current_info(); 19 | Type next_info(); 20 | 21 | bool operator!=(ConstIterator const& other) const noexcept; 22 | bool operator==(ConstIterator const& other) const noexcept; 23 | 24 | const Type& operator*() const; 25 | const Type* operator->() const; 26 | 27 | ConstIterator& operator++(); 28 | ConstIterator operator++(int) noexcept; 29 | 30 | operator bool() const noexcept; 31 | 32 | private: 33 | ConstIterator(const shared_ptr> &list) : containter_obj(list) {} 34 | 35 | weak_ptr> containter_obj; 36 | }; 37 | 38 | #endif // ConstIterator_H 39 | -------------------------------------------------------------------------------- /lab_02/lab/constiterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CONSTITERATOR_HPP 2 | #define CONSTITERATOR_HPP 3 | 4 | #include "constiterator.h" 5 | #include "errors.h" 6 | #include 7 | 8 | 9 | template 10 | Type ConstIterator::current_info() 11 | { 12 | try 13 | { 14 | shared_ptr> current(containter_obj); 15 | return containter_obj.lock()->getData(); 16 | } 17 | catch (const bad_weak_ptr &exc) 18 | { 19 | time_t t = time(NULL); 20 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 21 | } 22 | } 23 | 24 | 25 | template 26 | Type ConstIterator::next_info() 27 | { 28 | try 29 | { 30 | shared_ptr> current(containter_obj); 31 | return containter_obj.lock()->getNext->getData(); 32 | } 33 | catch (const bad_weak_ptr &exc) 34 | { 35 | time_t t = time(NULL); 36 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 37 | } 38 | } 39 | 40 | 41 | template 42 | bool ConstIterator::operator!=(ConstIterator const& other) const noexcept 43 | { 44 | return containter_obj.lock() != other.containter_obj.lock(); 45 | } 46 | 47 | 48 | template 49 | bool ConstIterator::operator==(ConstIterator const& other) const noexcept 50 | { 51 | return containter_obj.lock() == other.containter_obj.lock(); 52 | } 53 | 54 | 55 | template 56 | const Type& ConstIterator::operator*() const 57 | { 58 | try 59 | { 60 | shared_ptr> current(containter_obj); 61 | return containter_obj.lock()->getData(); 62 | } 63 | catch (const bad_weak_ptr &exc) 64 | { 65 | time_t t = time(NULL); 66 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 67 | } 68 | } 69 | 70 | 71 | template 72 | const Type* ConstIterator::operator->() const 73 | { 74 | try 75 | { 76 | shared_ptr> current(containter_obj); 77 | return &(containter_obj.lock()->getData()); 78 | } 79 | catch (const bad_weak_ptr &exc) 80 | { 81 | time_t t = time(NULL); 82 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 83 | } 84 | } 85 | 86 | 87 | template 88 | ConstIterator& ConstIterator::operator++() 89 | { 90 | try 91 | { 92 | shared_ptr> current(containter_obj); 93 | containter_obj = current->getNext(); 94 | return *this; 95 | } 96 | catch (const bad_weak_ptr &exc) 97 | { 98 | time_t t = time(NULL); 99 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 100 | } 101 | } 102 | 103 | 104 | template 105 | ConstIterator ConstIterator::operator++(int) noexcept 106 | { 107 | ConstIterator it(*this); 108 | ++(*this); 109 | return it; 110 | } 111 | 112 | 113 | template 114 | ConstIterator::operator bool() const noexcept 115 | { 116 | return !containter_obj.expired(); 117 | } 118 | 119 | // expiried - true, если объект удален, иначе false 120 | // bool() - true, если объект существует, иначе false 121 | 122 | #endif // CONSTITERATOR_HPP 123 | -------------------------------------------------------------------------------- /lab_02/lab/errors.h: -------------------------------------------------------------------------------- 1 | #ifndef ERRORS_H 2 | #define ERRORS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | 12 | class ExceptionList : public exception 13 | { 14 | protected: 15 | string errormsg; 16 | 17 | public: 18 | ExceptionList(const string &filename, 19 | const int line, 20 | const string &time) 21 | { 22 | errormsg = "In: " + filename + 23 | "\nat line: " + to_string(line) + 24 | "\nat: " + time; 25 | } 26 | virtual const char* what() const noexcept override 27 | { 28 | return errormsg.c_str(); 29 | } 30 | }; 31 | 32 | 33 | class ErrorProdigalAlias : public ExceptionList 34 | { 35 | public: 36 | ErrorProdigalAlias( 37 | const char* file_name, 38 | const int index, 39 | const char* time) 40 | : ExceptionList(file_name, index, time) {} 41 | virtual ~ErrorProdigalAlias() {} 42 | }; 43 | 44 | 45 | class ErrorBadAlloc : public ExceptionList 46 | { 47 | public: 48 | ErrorBadAlloc( 49 | const char* file_name, 50 | const int index, 51 | const char* time) 52 | : ExceptionList(file_name, index, time) {} 53 | virtual ~ErrorBadAlloc() {} 54 | }; 55 | 56 | 57 | 58 | class ErrorIndex : public ExceptionList 59 | { 60 | public: 61 | ErrorIndex( 62 | const char* file_name, 63 | const int index, 64 | const char* time) 65 | : ExceptionList(file_name, index, time) {} 66 | virtual ~ ErrorIndex() {} 67 | }; 68 | 69 | 70 | class ConstructorBadArguments : public ExceptionList 71 | { 72 | public: 73 | ConstructorBadArguments( 74 | const char* file_name, 75 | const int index, 76 | const char* time) 77 | : ExceptionList(file_name, index, time) {} 78 | }; 79 | 80 | 81 | class BadObjectPtr : public ExceptionList 82 | { 83 | public: 84 | BadObjectPtr( 85 | const char* file_name, 86 | const int index, 87 | const char* time) 88 | : ExceptionList(file_name, index, time) {} 89 | }; 90 | 91 | 92 | class EmptyList : public ExceptionList 93 | { 94 | public: 95 | EmptyList( 96 | const char* file_name, 97 | const int index, 98 | const char* time) 99 | : ExceptionList(file_name, index, time) {} 100 | }; 101 | 102 | #endif // ERRORS_H 103 | -------------------------------------------------------------------------------- /lab_02/lab/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef Iterator_H 2 | #define Iterator_H 3 | 4 | #include 5 | #include "list.h" 6 | 7 | using namespace std; 8 | 9 | 10 | template 11 | class Iterator : public std::iterator 12 | { 13 | friend class List; 14 | 15 | public: 16 | Iterator(const Iterator &it) = default; 17 | 18 | Type current_info(); 19 | Type next_info(); 20 | 21 | bool operator!=(Iterator const& other) const; 22 | bool operator==(Iterator const& other) const; 23 | 24 | Type& operator*(); 25 | const Type& operator*() const; 26 | Type* operator->(); 27 | const Type* operator->() const; 28 | 29 | Iterator& operator++(); 30 | Iterator operator++(int); 31 | 32 | operator bool() const; 33 | 34 | private: 35 | Iterator(const shared_ptr> &list) : containter_obj(list) {} 36 | 37 | weak_ptr> containter_obj; 38 | }; 39 | 40 | #endif // Iterator_H 41 | -------------------------------------------------------------------------------- /lab_02/lab/iterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITERATOR_HPP 2 | #define ITERATOR_HPP 3 | 4 | #include "iterator.h" 5 | #include "errors.h" 6 | #include 7 | 8 | 9 | template 10 | Type Iterator::current_info() 11 | { 12 | try 13 | { 14 | shared_ptr> current(containter_obj); 15 | return containter_obj.lock()->getData(); 16 | } 17 | catch (const bad_weak_ptr &exc) 18 | { 19 | time_t t = time(NULL); 20 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 21 | } 22 | } 23 | 24 | 25 | template 26 | Type Iterator::next_info() 27 | { 28 | try 29 | { 30 | shared_ptr> current(containter_obj); 31 | return containter_obj.lock()->getNext->getData(); 32 | } 33 | catch (const bad_weak_ptr &exc) 34 | { 35 | time_t t = time(NULL); 36 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 37 | } 38 | } 39 | 40 | 41 | template 42 | bool Iterator::operator!=(Iterator const& other) const 43 | { 44 | return containter_obj.lock() != other.containter_obj.lock(); 45 | } 46 | 47 | 48 | template 49 | bool Iterator::operator==(Iterator const& other) const 50 | { 51 | return containter_obj.lock() == other.containter_obj.lock(); 52 | } 53 | 54 | 55 | template 56 | Type& Iterator::operator*() 57 | { 58 | try 59 | { 60 | shared_ptr> current(containter_obj); 61 | return containter_obj.lock()->getData(); 62 | } 63 | catch (const bad_weak_ptr &exc) 64 | { 65 | time_t t = time(NULL); 66 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 67 | } 68 | } 69 | 70 | 71 | template 72 | const Type& Iterator::operator*() const 73 | { 74 | try 75 | { 76 | shared_ptr> current(containter_obj); 77 | return containter_obj.lock()->getData(); 78 | } 79 | catch (const bad_weak_ptr &exc) 80 | { 81 | time_t t = time(NULL); 82 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 83 | } 84 | } 85 | 86 | 87 | template 88 | Type* Iterator::operator->() 89 | { 90 | try 91 | { 92 | shared_ptr> current(containter_obj); 93 | return &(containter_obj.lock()->getData()); 94 | } 95 | catch (const bad_weak_ptr &exc) 96 | { 97 | time_t t = time(NULL); 98 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 99 | } 100 | } 101 | 102 | 103 | template 104 | const Type* Iterator::operator->() const 105 | { 106 | try 107 | { 108 | shared_ptr> current(containter_obj); 109 | return &(containter_obj.lock()->getData()); 110 | } 111 | catch (const bad_weak_ptr &exc) 112 | { 113 | time_t t = time(NULL); 114 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 115 | } 116 | } 117 | 118 | 119 | template 120 | Iterator& Iterator::operator++() 121 | { 122 | try 123 | { 124 | shared_ptr> current(containter_obj); 125 | containter_obj = current->getNext(); 126 | return *this; 127 | } 128 | catch (const bad_weak_ptr &exc) 129 | { 130 | time_t t = time(NULL); 131 | throw BadObjectPtr(__FILE__, __LINE__, ctime(&t)); 132 | } 133 | } 134 | 135 | 136 | template 137 | Iterator Iterator::operator++(int) 138 | { 139 | Iterator it(*this); 140 | ++(*this); 141 | return it; 142 | } 143 | 144 | 145 | template 146 | Iterator::operator bool() const 147 | { 148 | return !containter_obj.expired(); 149 | } 150 | 151 | // expiried - true, если объект удален, иначе false 152 | // bool() - true, если объект существует, иначе false 153 | 154 | #endif // ITERATOR_HPP 155 | -------------------------------------------------------------------------------- /lab_02/lab/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "baselist.h" 9 | #include "node.hpp" 10 | 11 | using namespace std; 12 | 13 | template class Iterator; 14 | template class ConstIterator; 15 | 16 | template 17 | class List : public BaseList 18 | { 19 | public: 20 | List(); 21 | explicit List(const List& list); 22 | List(initializer_list list); 23 | List(Type* array, int size); 24 | List(List&& list) noexcept; 25 | template List(const I &it); 26 | 27 | ~List() = default; 28 | 29 | Type& get_front() const; 30 | Type& get_back() const; 31 | 32 | bool is_empty() const noexcept; 33 | int get_length() const noexcept; 34 | void clear() noexcept; 35 | 36 | void push_back(const Type& value); 37 | void push_back(const List &list) noexcept; 38 | 39 | void push_front(const Type& value); 40 | void push_front(const List &list) noexcept; 41 | 42 | void pop_back(); 43 | void pop_front(); 44 | 45 | List& combine(const List& list) noexcept; 46 | 47 | Type* to_array(); 48 | 49 | Iterator begin() noexcept; 50 | Iterator end() noexcept; 51 | 52 | Iterator begin() const noexcept; 53 | Iterator end() const noexcept; 54 | 55 | ConstIterator cbegin() const noexcept; 56 | ConstIterator cend() const noexcept; 57 | 58 | List& operator=(const List& list); 59 | List& operator=(List&& list); 60 | List& operator=(const initializer_list &init_list); 61 | 62 | List& operator+(const List& list); 63 | 64 | List& operator+=(const List& list); 65 | List& operator+=(const initializer_list &init_list); 66 | 67 | private: 68 | shared_ptr> head; 69 | shared_ptr> tail; 70 | int count; 71 | }; 72 | 73 | #endif // LIST_H 74 | -------------------------------------------------------------------------------- /lab_02/lab/list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LIST_HPP 2 | #define LIST_HPP 3 | 4 | #include "list.h" 5 | #include "errors.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | 13 | template 14 | List::List() : BaseList() 15 | { 16 | head = nullptr; 17 | tail = nullptr; 18 | count = 0; 19 | } 20 | 21 | 22 | template 23 | List::List(const List& list) 24 | { 25 | if (list.is_empty()) 26 | { 27 | time_t t = time(NULL); 28 | throw ConstructorBadArguments(__FILE__, __LINE__, ctime(&t)); 29 | } 30 | 31 | try 32 | { 33 | head.reset(new Node(list.get_front())); 34 | 35 | shared_ptr> new_node, current_node = head; 36 | auto it = list.begin(); 37 | 38 | it++; 39 | for (; it != list.end(); it++) 40 | { 41 | new_node.reset(new Node(*it)); 42 | current_node->setNext(new_node); 43 | current_node = current_node->getNext(); 44 | } 45 | tail = current_node;; 46 | count = list.count; 47 | } 48 | catch (const bad_alloc &exc) 49 | { 50 | time_t t = time(NULL); 51 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 52 | } 53 | } 54 | 55 | 56 | template 57 | List::List(initializer_list list) 58 | { 59 | if (!list.size()) 60 | { 61 | time_t t = time(NULL); 62 | throw ConstructorBadArguments(__FILE__, __LINE__, ctime(&t)); 63 | } 64 | 65 | try 66 | { 67 | head.reset(new Node(*list.begin())); 68 | 69 | shared_ptr> new_node, current_node = head; 70 | auto it = list.begin(); 71 | 72 | it++; 73 | for(; it != list.end(); it++) 74 | { 75 | new_node.reset(new Node(*it)); 76 | current_node->setNext(new_node); 77 | current_node = current_node->getNext(); 78 | } 79 | tail = current_node; 80 | count = list.size(); 81 | } 82 | catch (const bad_alloc &exc) 83 | { 84 | time_t t = time(NULL); 85 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 86 | } 87 | } 88 | 89 | 90 | template 91 | List::List(Type* array, int size) : List() 92 | { 93 | if (size < 1) 94 | { 95 | time_t t = time(NULL); 96 | throw ConstructorBadArguments(__FILE__, __LINE__, ctime(&t)); 97 | } 98 | 99 | try 100 | { 101 | head.reset(new Node(array[0])); 102 | 103 | shared_ptr> new_node, current_node = head; 104 | for (int i = 1; i < size; i++) 105 | { 106 | new_node.reset(new Node(array[i])); 107 | current_node->setNext(new_node); 108 | current_node = current_node->getNext(); 109 | } 110 | tail = current_node; 111 | count = size; 112 | } 113 | catch (const bad_alloc &exc) 114 | { 115 | time_t t = time(NULL); 116 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 117 | } 118 | } 119 | 120 | 121 | template 122 | List::List(List&& list) noexcept 123 | { 124 | head = list.head; 125 | tail = list.tail; 126 | count = list.count; 127 | 128 | list.head.reset(); 129 | list.tail.reset(); 130 | } 131 | 132 | 133 | template 134 | template 135 | List::List(const I &it) 136 | { 137 | if (!it) 138 | { 139 | time_t t = time(NULL); 140 | throw ConstructorBadArguments(__FILE__, __LINE__, ctime(&t)); 141 | } 142 | 143 | try 144 | { 145 | count = 1; 146 | head.reset(new Node(*it)); 147 | shared_ptr> new_node, current_node = head; 148 | auto i = it; 149 | 150 | i++; 151 | while(i) 152 | { 153 | new_node.reset(new Node(*i)); 154 | current_node->setNext(new_node); 155 | current_node = current_node->getNext(); 156 | count++; 157 | i++; 158 | } 159 | tail = current_node; 160 | } 161 | 162 | catch (const bad_alloc &exc) 163 | { 164 | time_t t = time(NULL); 165 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 166 | } 167 | } 168 | 169 | 170 | template 171 | Type& List::get_front() const 172 | { 173 | if (!head) 174 | { 175 | time_t t = time(NULL); 176 | throw ErrorProdigalAlias(__FILE__, __LINE__, ctime(&t)); 177 | } 178 | 179 | return head->getData(); 180 | } 181 | 182 | 183 | template 184 | Type& List::get_back() const 185 | { 186 | if (!tail) 187 | { 188 | time_t t = time(NULL); 189 | throw ErrorProdigalAlias(__FILE__, __LINE__, ctime(&t)); 190 | } 191 | 192 | return tail->getData(); 193 | } 194 | 195 | 196 | template 197 | bool List::is_empty() const noexcept 198 | { 199 | return count == 0; 200 | } 201 | 202 | 203 | template 204 | int List::get_length() const noexcept 205 | { 206 | return count; 207 | } 208 | 209 | 210 | template 211 | void List::push_back(const Type& value) 212 | { 213 | try 214 | { 215 | if (is_empty()) 216 | { 217 | head.reset(new Node(value)); 218 | tail = head; 219 | count = 1; 220 | return; 221 | } 222 | 223 | auto new_node = shared_ptr>(new Node(value)); 224 | tail->setNext(new_node); 225 | tail = tail->getNext(); 226 | count += 1; 227 | } 228 | catch (const bad_alloc &exc) 229 | { 230 | time_t t = time(NULL); 231 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 232 | } 233 | } 234 | 235 | 236 | template 237 | void List::push_back(const List &list) noexcept 238 | { 239 | for(auto it = list.begin(); it != list.end(); it++) 240 | push_back(*it); 241 | } 242 | 243 | 244 | template 245 | void List::push_front(const Type& value) 246 | { 247 | try 248 | { 249 | if (is_empty()) 250 | { 251 | head.reset(new Node(value)); 252 | tail = head; 253 | count = 1; 254 | return; 255 | } 256 | auto new_node = shared_ptr>(new Node(value)); 257 | new_node->setNext(head); 258 | head = new_node; 259 | count += 1; 260 | } 261 | catch (const bad_alloc &exc) 262 | { 263 | time_t t = time(NULL); 264 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 265 | } 266 | } 267 | 268 | 269 | template 270 | void List::push_front(const List &list) noexcept 271 | { 272 | if (list.is_empty()) return; 273 | 274 | List front_list(list); 275 | 276 | if (is_empty()) tail = front_list.tail; 277 | 278 | front_list.tail->setNext(head); 279 | head = front_list.head; 280 | count += list.count; 281 | } 282 | 283 | 284 | template 285 | void List::pop_back() 286 | { 287 | if (is_empty()) 288 | { 289 | time_t t = time(NULL); 290 | throw EmptyList(__FILE__, __LINE__, ctime(&t)); 291 | } 292 | else if (count == 1) 293 | { 294 | head = nullptr; 295 | tail = nullptr; 296 | count = 0; 297 | return; 298 | } 299 | 300 | auto current_node = head; 301 | 302 | int i = 0; 303 | while(i < count - 2) 304 | { 305 | current_node = current_node->getNext(); 306 | i++; 307 | } 308 | current_node->removeNext(); 309 | tail = current_node; 310 | count -= 1; 311 | } 312 | 313 | 314 | template 315 | void List::pop_front() 316 | { 317 | if (is_empty()) 318 | { 319 | time_t t = time(NULL); 320 | throw EmptyList(__FILE__, __LINE__, ctime(&t)); 321 | } 322 | else if (count == 1) 323 | { 324 | head = nullptr; 325 | tail = nullptr; 326 | count = 0; 327 | return; 328 | } 329 | 330 | head = head->getNext(); 331 | count -= 1; 332 | } 333 | 334 | 335 | 336 | template 337 | List& List::combine(const List& list) noexcept 338 | { 339 | push_back(list); 340 | return (*this); 341 | } 342 | 343 | 344 | template 345 | Type* List::to_array() 346 | { 347 | Type* array = new Type[count]; 348 | if (!array) 349 | { 350 | time_t t = time(NULL); 351 | throw ErrorBadAlloc(__FILE__, __LINE__, ctime(&t)); 352 | } 353 | 354 | int i = 0; 355 | for (auto &element : *this) 356 | { 357 | array[i] = element; 358 | i++; 359 | } 360 | return array; 361 | } 362 | 363 | 364 | template 365 | void List::clear() noexcept 366 | { 367 | for (auto &element : *this) 368 | element = 0; 369 | } 370 | 371 | 372 | template 373 | Iterator List::begin() noexcept 374 | { 375 | return Iterator(head); 376 | } 377 | 378 | 379 | template 380 | Iterator List::end() noexcept 381 | { 382 | return Iterator(nullptr); 383 | } 384 | 385 | 386 | template 387 | Iterator List::begin() const noexcept 388 | { 389 | return Iterator(head); 390 | } 391 | 392 | 393 | template 394 | Iterator List::end() const noexcept 395 | { 396 | return Iterator(nullptr); 397 | } 398 | 399 | 400 | template 401 | ConstIterator List::cbegin() const noexcept 402 | { 403 | return ConstIterator(head); 404 | } 405 | 406 | 407 | template 408 | ConstIterator List::cend() const noexcept 409 | { 410 | return ConstIterator(nullptr); 411 | } 412 | 413 | 414 | template 415 | List& List::operator=(const List& list) 416 | { 417 | List new_list; 418 | new_list.push_back(list); 419 | 420 | *this = move(new_list); 421 | 422 | return *this; 423 | } 424 | 425 | 426 | template 427 | List& List::operator=(const initializer_list &init_list) 428 | { 429 | List new_list; 430 | for (auto &element : init_list) 431 | new_list.push_back(element); 432 | 433 | *this = move(new_list); 434 | 435 | return *this; 436 | } 437 | 438 | 439 | template 440 | List& List::operator=(List&& list) 441 | { 442 | head = list.head; 443 | tail = list.tail; 444 | count = list.count; 445 | 446 | list.head.reset(); 447 | list.tail.reset(); 448 | 449 | return *this; 450 | } 451 | 452 | 453 | template 454 | List& List::operator+(const List& list) 455 | { 456 | return combine(list); 457 | } 458 | 459 | 460 | template 461 | List& List::operator+=(const List& list) 462 | { 463 | (*this) = (*this).combine(list); 464 | return (*this); 465 | } 466 | 467 | 468 | template 469 | List& List::operator+=(const initializer_list &init_list) 470 | { 471 | List new_list(init_list); 472 | (*this) = (*this).combine(new_list); 473 | return (*this); 474 | } 475 | 476 | 477 | template 478 | ostream& operator<<(ostream& os, List& list) 479 | { 480 | os << "List: "; 481 | if (!list.get_length()) 482 | return os << "null"; 483 | 484 | for (auto &element: list) 485 | os << element << " "; 486 | 487 | return os; 488 | } 489 | 490 | #endif // LIST_HPP 491 | -------------------------------------------------------------------------------- /lab_02/lab/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include "node.hpp" 5 | #include "list.hpp" 6 | #include "iterator.hpp" 7 | #include "constiterator.hpp" 8 | 9 | 10 | using namespace std; 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | QCoreApplication a(argc, argv); 15 | return a.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /lab_02/lab/node.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_H 2 | #define NODE_H 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | template 9 | class Node 10 | { 11 | public: 12 | Node(); 13 | Node(const Type &data); 14 | explicit Node(Node &node); 15 | 16 | ~Node(); 17 | 18 | void setData(Type data); 19 | Type& getData(); 20 | 21 | void setNext(shared_ptr> node); 22 | shared_ptr> getNext(); 23 | 24 | void removeNext(); 25 | 26 | Node operator+(Node op); 27 | 28 | bool operator ==(const Node& op) const; 29 | bool operator !=(const Node& op) const; 30 | 31 | private: 32 | shared_ptr> next; 33 | Type data; 34 | }; 35 | 36 | #endif // NODE_H 37 | -------------------------------------------------------------------------------- /lab_02/lab/node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NODE_HPP 2 | #define NODE_HPP 3 | 4 | #include "node.h" 5 | #include 6 | 7 | 8 | template 9 | Node::Node() 10 | { 11 | next = nullptr; 12 | } 13 | 14 | 15 | template 16 | Node::Node(const Type &data) 17 | { 18 | next = nullptr; 19 | this->data = data; 20 | } 21 | 22 | 23 | template 24 | Node::Node(Node &node) 25 | { 26 | data = node.data; 27 | next = node.next; 28 | } 29 | 30 | 31 | template 32 | Node::~Node() 33 | { 34 | next = nullptr; 35 | } 36 | 37 | 38 | template 39 | void Node::setData(Type data) 40 | { 41 | this->data = data; 42 | } 43 | 44 | 45 | template 46 | Type& Node::getData() 47 | { 48 | return data; 49 | } 50 | 51 | 52 | template 53 | void Node::setNext(shared_ptr> node) 54 | { 55 | next = node; 56 | } 57 | 58 | 59 | template 60 | shared_ptr> Node::getNext() 61 | { 62 | return next; 63 | } 64 | 65 | 66 | template 67 | void Node::removeNext() 68 | { 69 | next = nullptr; 70 | } 71 | 72 | 73 | template 74 | Node Node::operator+(Node op) 75 | { 76 | return Node(data + op.data); 77 | } 78 | 79 | 80 | template 81 | bool Node::operator ==(const Node& op) const 82 | { 83 | return data == op.data; 84 | } 85 | 86 | 87 | template 88 | bool Node::operator !=(const Node& op) const 89 | { 90 | return data != op.data; 91 | } 92 | 93 | #endif // NODE_HPP 94 | -------------------------------------------------------------------------------- /lab_02/tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include "testing_constructors.h" 2 | //#include "testing_iterators.h" 3 | //#include "testing_push.h" 4 | //#include "testing_pop.h" 5 | //#include "testing_operators.h" 6 | 7 | 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | ::testing::InitGoogleTest(&argc, argv); 13 | return RUN_ALL_TESTS(); 14 | } 15 | -------------------------------------------------------------------------------- /lab_02/tests/testing_constructors.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTING_CONSTRUCTORS_H 2 | #define TESTING_CONSTRUCTORS_H 3 | 4 | #include 5 | #include 6 | 7 | #include "list.h" 8 | #include "list.hpp" 9 | #include "baselist.h" 10 | #include "baselist.cpp" 11 | #include "errors.h" 12 | #include "iterator.h" 13 | #include "iterator.hpp" 14 | #include "constiterator.h" 15 | #include "constiterator.hpp" 16 | 17 | 18 | using namespace testing; 19 | 20 | 21 | TEST(ListBaseSuite, DefaultConstrucor) 22 | { 23 | List list; 24 | ASSERT_TRUE(list.is_empty()); 25 | } 26 | 27 | 28 | TEST(ListBaseSuite, CreationFromInitializerList) 29 | { 30 | // size = 0 31 | initializer_list empty_initializer_list{}; 32 | ASSERT_THROW(List empty_list{empty_initializer_list}, ConstructorBadArguments); 33 | 34 | 35 | // size = 1 36 | ASSERT_NO_THROW(List list_1({1})); 37 | 38 | List list_1{1}; 39 | ASSERT_EQ(list_1.get_length(), 1); 40 | ASSERT_EQ(list_1.get_front(), list_1.get_back()); 41 | 42 | 43 | // size = 2 44 | ASSERT_NO_THROW(List list_2({1, 2})); 45 | 46 | List list_2{1, 2}; 47 | ASSERT_EQ(list_2.get_length(), 2); 48 | ASSERT_EQ(list_2.get_front(), 1); 49 | ASSERT_EQ(list_2.get_back(), 2); 50 | 51 | 52 | // size = 3 53 | ASSERT_NO_THROW(List list_3({1, 2, 3})); 54 | 55 | List list_3{1, 2, 3}; 56 | ASSERT_EQ(list_3.get_length(), 3); 57 | ASSERT_EQ(list_3.get_front(), 1); 58 | ASSERT_EQ(list_3.get_back(), 3); 59 | } 60 | 61 | 62 | TEST(ListBaseSuite, CopyConstructor) 63 | { 64 | // size = 0 65 | List list_0; 66 | ASSERT_THROW(List empty_list(list_0), ConstructorBadArguments); 67 | 68 | 69 | // size = 1 70 | List list_1{1}; 71 | ASSERT_NO_THROW(List list(list_1)); 72 | 73 | List list_10(list_1); 74 | ASSERT_EQ(list_10.get_length(), 1); 75 | ASSERT_EQ(list_10.get_front(), list_10.get_back()); 76 | 77 | ASSERT_NE(list_1.begin(), list_10.begin()); 78 | 79 | 80 | // size = 2 81 | List list_2{1, 2}; 82 | ASSERT_NO_THROW(List list(list_2)); 83 | 84 | List list_20(list_2); 85 | ASSERT_EQ(list_20.get_length(), 2); 86 | ASSERT_EQ(list_20.get_front(), 1); 87 | ASSERT_EQ(list_20.get_back(), 2); 88 | 89 | ASSERT_NE(list_2.begin(), list_20.begin()); 90 | 91 | 92 | // size = 3 93 | List list_3{1, 2, 3}; 94 | ASSERT_NO_THROW(List list(list_3)); 95 | 96 | List list_30(list_3); 97 | ASSERT_EQ(list_30.get_length(), 3); 98 | ASSERT_EQ(list_30.get_front(), 1); 99 | ASSERT_EQ(list_30.get_back(), 3); 100 | 101 | ASSERT_NE(list_3.begin(), list_30.begin()); 102 | } 103 | 104 | TEST(ListBaseSuite, CreationFromIterator) 105 | { 106 | // size = 0 107 | List list_0; 108 | Iterator it = list_0.begin(); 109 | ASSERT_THROW(List empty_list(it), ConstructorBadArguments); 110 | 111 | // size = 1 112 | List list_1{1}; 113 | it = list_1.begin(); 114 | 115 | ASSERT_NO_THROW(List list(it)); 116 | 117 | List list_10(it); 118 | ASSERT_EQ(list_10.get_length(), 1); 119 | ASSERT_EQ(list_10.get_front(), list_10.get_back()); 120 | 121 | ASSERT_NE(list_1.begin(), list_10.begin()); 122 | 123 | 124 | // size = 2 125 | List list_2{1, 2}; 126 | Iterator it2 = list_2.begin(); 127 | 128 | List list_20(it2); 129 | ASSERT_EQ(list_20.get_length(), 2); 130 | 131 | ASSERT_NE(list_2.begin(), list_20.begin()); 132 | 133 | 134 | // Const iterator 135 | List list_3{1, 2, 3}; 136 | ConstIterator c_it = list_3.cbegin(); 137 | 138 | List list_4(c_it); 139 | ASSERT_EQ(list_4.get_length(), 3); 140 | } 141 | 142 | 143 | TEST(ListBaseSuite, CreationFromArray) 144 | { 145 | int array[5] = {1, 2, 3, 4, 5}; 146 | 147 | // Invalid data (incorrect index) 148 | ASSERT_THROW(List list(array, 0), ConstructorBadArguments); 149 | ASSERT_THROW(List list(array, -1), ConstructorBadArguments); 150 | 151 | // What I must to do with memory?.. 152 | 153 | //___________________________________________________________ 154 | // Array size = 5. 155 | ASSERT_NO_THROW(List list(array, 5)); 156 | 157 | List list(array, 5); 158 | ASSERT_EQ(list.get_length(), 5); 159 | 160 | int i = 0; 161 | for (auto it = list.begin(); it != list.end(); it++) 162 | { 163 | ASSERT_EQ(*it, array[i]); 164 | i++; 165 | } 166 | //___________________________________________________________ 167 | } 168 | 169 | 170 | #endif // TESTING_CONSTRUCTORS_H 171 | -------------------------------------------------------------------------------- /lab_02/tests/testing_iterators.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTING_ITERATORS_H 2 | #define TESTING_ITERATORS_H 3 | 4 | #include 5 | #include 6 | 7 | #include "list.h" 8 | #include "list.hpp" 9 | #include "baselist.h" 10 | #include "baselist.cpp" 11 | #include "errors.h" 12 | #include "iterator.h" 13 | #include "iterator.hpp" 14 | 15 | 16 | using namespace testing; 17 | 18 | 19 | TEST(ListIteratorsSuite, OutOfRangeAccess) 20 | { 21 | List list{1, 2}; 22 | Iteratorit_1 = list.begin(); 23 | Iteratorit_2 = list.begin(); 24 | list.pop_front(); 25 | 26 | ASSERT_THROW(++it_1, BadObjectPtr); 27 | 28 | //How I can catch BadObjectPtr? :") 29 | //ASSERT_THROW(it_2++, BadObjectPtr); 30 | } 31 | 32 | 33 | TEST(ListIteratorSuite, AssignIterator) 34 | { 35 | // size = 0 36 | List list_0; 37 | ASSERT_NO_THROW(Iterator it = list_0.begin()); 38 | ASSERT_NO_THROW(Iterator it = list_0.end()); 39 | 40 | // size = 3 41 | List list_3{1, 2, 3}; 42 | ASSERT_NO_THROW(Iterator it = list_3.begin()); 43 | ASSERT_NO_THROW(Iterator it = list_3.end()); 44 | } 45 | 46 | #endif // TESTING_ITERATORS_H 47 | -------------------------------------------------------------------------------- /lab_02/tests/testing_operators.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTING_OPERATORS_H 2 | #define TESTING_OPERATORS_H 3 | 4 | #include 5 | #include 6 | 7 | #include "list.h" 8 | #include "list.hpp" 9 | #include "baselist.h" 10 | #include "baselist.cpp" 11 | #include "errors.h" 12 | #include "iterator.h" 13 | #include "iterator.hpp" 14 | 15 | 16 | using namespace testing; 17 | 18 | TEST(ListOperatorsSuite, EqualityListOperator) 19 | { 20 | // empty list = empty list 21 | List l1; 22 | List l2; 23 | ASSERT_NO_THROW(l1 = l2); 24 | 25 | 26 | // empty list = full list 27 | List list_1{1, 2, 3, 4}; 28 | List list_2; 29 | 30 | ASSERT_NO_THROW(list_2 = list_1); 31 | ASSERT_NE(list_1.begin(), list_2.begin()); 32 | 33 | ASSERT_EQ(list_2.get_length(), 4); 34 | 35 | 36 | // full list = empty list 37 | List list_3{1, 2, 3, 4}; 38 | List list_4; 39 | 40 | ASSERT_NO_THROW(list_3 = list_4); 41 | 42 | ASSERT_EQ(list_3.get_length(), 0); 43 | 44 | 45 | // full list = full list 46 | List list_5{1, 2, 3, 4}; 47 | List list_6{7, 8, 9}; 48 | 49 | ASSERT_NO_THROW(list_5 = list_6); 50 | ASSERT_NE(list_5.begin(), list_6.begin()); 51 | 52 | ASSERT_EQ(list_5.get_length(), 3); 53 | 54 | // this list = this list 55 | List list_7{6, 6, 6}; 56 | ASSERT_NO_THROW(list_7 = list_7); 57 | 58 | ASSERT_EQ(list_7.get_length(), 3); 59 | } 60 | 61 | 62 | TEST(ListOperatorsSuite, EqualityInitListOperator) 63 | { 64 | // empty list = empty init list 65 | List l1; 66 | initializer_list i_list = {}; 67 | ASSERT_NO_THROW(l1 = i_list); 68 | 69 | // empty list = full init list 70 | List list_1; 71 | 72 | ASSERT_NO_THROW((list_1 = {1, 2, 3, 4})); 73 | ASSERT_EQ(list_1.get_length(), 4); 74 | 75 | 76 | // full list = empty init list 77 | List list_2{1, 2, 3, 4}; 78 | initializer_list init_list = {}; 79 | 80 | ASSERT_NO_THROW(list_2 = init_list); 81 | 82 | ASSERT_EQ(list_2.get_length(), 0); 83 | 84 | 85 | // full list = full init list 86 | List list_5{1, 2, 3, 4}; 87 | 88 | ASSERT_NO_THROW((list_5 = {7, 8, 9})); 89 | 90 | ASSERT_EQ(list_5.get_length(), 3); 91 | } 92 | 93 | 94 | TEST(ListOperatorsSuite, OperatorPlus) 95 | { 96 | List l1{1, 2, 3}; 97 | List l2{4, 5, 6}; 98 | List l3; 99 | 100 | ASSERT_NO_THROW(l3 = l1 + l2); 101 | ASSERT_EQ(l3.get_length(), 6); 102 | ASSERT_EQ(l3.get_front(), 1); 103 | ASSERT_EQ(l3.get_back(), 6); 104 | } 105 | 106 | 107 | #endif // TESTING_OPERATORS_H 108 | -------------------------------------------------------------------------------- /lab_02/tests/testing_pop.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTING_POP_H 2 | #define TESTING_POP_H 3 | 4 | #include 5 | #include 6 | 7 | #include "list.h" 8 | #include "list.hpp" 9 | #include "baselist.h" 10 | #include "baselist.cpp" 11 | #include "errors.h" 12 | #include "iterator.h" 13 | #include "iterator.hpp" 14 | 15 | using namespace testing; 16 | 17 | TEST(ListPopMethodsSuite, PopBack) 18 | { 19 | // empty list 20 | List empty_list; 21 | ASSERT_THROW(empty_list.pop_back(), EmptyList); 22 | 23 | 24 | // list size = 1 25 | List list_1{1}; 26 | ASSERT_NO_THROW(list_1.pop_back()); 27 | ASSERT_EQ(list_1.get_length(), 0); 28 | 29 | 30 | // list size = 2 31 | List list_2{1, 2}; 32 | ASSERT_NO_THROW(list_2.pop_back()); 33 | ASSERT_EQ(list_2.get_length(), 1); 34 | ASSERT_EQ(list_2.get_front(), 1); 35 | ASSERT_EQ(list_2.get_back(), 1); 36 | 37 | 38 | // list size = 3 39 | List list_3{1, 2, 3}; 40 | ASSERT_NO_THROW(list_3.pop_back()); 41 | ASSERT_EQ(list_3.get_length(), 2); 42 | ASSERT_EQ(list_3.get_front(), 1); 43 | ASSERT_EQ(list_3.get_back(), 2); 44 | } 45 | 46 | 47 | TEST(ListPopMethodsSuite, PopFront) 48 | { 49 | // empty list 50 | List empty_list; 51 | ASSERT_THROW(empty_list.pop_front(), EmptyList); 52 | 53 | 54 | // list size = 1 55 | List list_1{1}; 56 | ASSERT_NO_THROW(list_1.pop_front()); 57 | ASSERT_EQ(list_1.get_length(), 0); 58 | 59 | 60 | // list size = 2 61 | List list_2{1, 2}; 62 | ASSERT_NO_THROW(list_2.pop_front()); 63 | ASSERT_EQ(list_2.get_length(), 1); 64 | ASSERT_EQ(list_2.get_front(), 2); 65 | ASSERT_EQ(list_2.get_back(), 2); 66 | 67 | 68 | // list size = 3 69 | List list_3{1, 2, 3}; 70 | ASSERT_NO_THROW(list_3.pop_front()); 71 | ASSERT_EQ(list_3.get_length(), 2); 72 | ASSERT_EQ(list_3.get_front(), 2); 73 | ASSERT_EQ(list_3.get_back(), 3); 74 | } 75 | 76 | #endif // TESTING_POP_H 77 | -------------------------------------------------------------------------------- /lab_02/tests/testing_push.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTING_PUSH_H 2 | #define TESTING_PUSH_H 3 | 4 | #include 5 | #include 6 | 7 | #include "list.h" 8 | #include "list.hpp" 9 | #include "baselist.h" 10 | #include "baselist.cpp" 11 | #include "errors.h" 12 | #include "iterator.h" 13 | #include "iterator.hpp" 14 | 15 | using namespace testing; 16 | 17 | 18 | TEST(ListPushMethodsSuite, PushBackData) 19 | { 20 | // empty list + data 21 | List list_1; 22 | 23 | ASSERT_NO_THROW(list_1.push_back(10)); 24 | 25 | ASSERT_EQ(list_1.get_length(), 1); 26 | 27 | ASSERT_EQ(list_1.get_front(), 10); 28 | ASSERT_EQ(list_1.get_back(), 10); 29 | 30 | 31 | // full list + data 32 | List list_2{10}; 33 | auto it_2 = list_2.begin(); 34 | 35 | ASSERT_NO_THROW(list_2.push_back(20)); 36 | 37 | ASSERT_EQ(list_2.get_length(), 2); 38 | 39 | ASSERT_EQ(list_2.get_front(), 10); 40 | ASSERT_EQ(list_2.get_back(), 20); 41 | ASSERT_EQ(it_2, list_2.begin()); 42 | } 43 | 44 | 45 | TEST(ListPushMethodsSuite, PushBackList) 46 | { 47 | // empty list + empty list 48 | List empty_list_1, empty_list_2; 49 | 50 | ASSERT_NO_THROW(empty_list_1.push_back(empty_list_2)); 51 | ASSERT_EQ(empty_list_1.get_length(), 0); 52 | 53 | 54 | // empty + full list 55 | List list_1; 56 | List full_list{10, 20, 30}; 57 | 58 | ASSERT_NO_THROW(list_1.push_back(full_list)); 59 | 60 | ASSERT_EQ(list_1.get_length(), 3); 61 | 62 | ASSERT_EQ(list_1.get_front(), 10); 63 | ASSERT_EQ(list_1.get_back(), 30); 64 | 65 | auto it = list_1.begin(); 66 | list_1.push_back(full_list); 67 | ASSERT_EQ(it, list_1.begin()); 68 | 69 | 70 | // full list + empty 71 | List list_2{10, 20}; 72 | List empty_list; 73 | 74 | ASSERT_NO_THROW(list_2.push_back(empty_list)); 75 | ASSERT_EQ(list_2.get_length(), 2); 76 | 77 | 78 | // full + full list 79 | List list_3{10, 20, 30}; 80 | List list_4{40, 50, 60}; 81 | 82 | ASSERT_NO_THROW(list_3.push_back(list_4)); 83 | 84 | ASSERT_EQ(list_3.get_length(), 6); 85 | 86 | ASSERT_EQ(list_3.get_front(), 10); 87 | ASSERT_EQ(list_3.get_back(), 60); 88 | } 89 | 90 | 91 | TEST(ListPushMethodsSuite, PushFrontData) 92 | { 93 | // empty list + data 94 | List list_1; 95 | 96 | ASSERT_NO_THROW(list_1.push_front(10)); 97 | 98 | ASSERT_EQ(list_1.get_length(), 1); 99 | 100 | ASSERT_EQ(list_1.get_front(), 10); 101 | ASSERT_EQ(list_1.get_back(), 10); 102 | 103 | 104 | // full list + data 105 | List list_2{10}; 106 | auto it_2 = list_2.begin(); 107 | 108 | ASSERT_NO_THROW(list_2.push_front(20)); 109 | 110 | ASSERT_EQ(list_2.get_length(), 2); 111 | 112 | ASSERT_EQ(list_2.get_front(), 20); 113 | ASSERT_EQ(list_2.get_back(), 10); 114 | ASSERT_NE(it_2, list_2.begin()); 115 | } 116 | 117 | 118 | TEST(ListPushMethodsSuite, PushFrontList) 119 | { 120 | // empty + empty list 121 | List empty_list_1, empty_list_2; 122 | 123 | ASSERT_NO_THROW(empty_list_1.push_front(empty_list_2)); 124 | ASSERT_EQ(empty_list_1.get_length(), 0); 125 | 126 | 127 | // empty + full list 128 | List list_1; 129 | List full_list{10, 20, 30}; 130 | 131 | ASSERT_NO_THROW(list_1.push_front(full_list)); 132 | 133 | ASSERT_EQ(list_1.get_length(), 3); 134 | 135 | ASSERT_EQ(list_1.get_front(), 10); 136 | ASSERT_EQ(list_1.get_back(), 30); 137 | 138 | 139 | // full + empty list 140 | List list_2{10, 20, 30}; 141 | List empty_list; 142 | 143 | ASSERT_NO_THROW(list_2.push_front(empty_list)); 144 | 145 | ASSERT_EQ(list_2.get_length(), 3); 146 | 147 | ASSERT_EQ(list_2.get_front(), 10); 148 | ASSERT_EQ(list_2.get_back(), 30); 149 | 150 | 151 | // full + full list 152 | List list_3{10, 20, 30}; 153 | List list_4{40, 50, 60}; 154 | 155 | ASSERT_NO_THROW(list_4.push_front(list_3)); 156 | 157 | ASSERT_NE(list_3.begin(), list_4.begin()); 158 | 159 | ASSERT_EQ(list_4.get_length(), 6); 160 | 161 | ASSERT_EQ(list_4.get_front(), 10); 162 | ASSERT_EQ(list_4.get_back(), 60); 163 | } 164 | 165 | #endif // TESTING_PUSH_H 166 | --------------------------------------------------------------------------------