diff --git a/CMakeLists.txt b/CMakeLists.txt index fb5abf3a..5bc4b038 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,10 @@ include(cmake/function.cmake) # подхватываем функции, # и для создания исполняемого проекта в отдельные функции add_subdirectory(lib_easy_example) # подключаем дополнительный CMakeLists.txt из подкаталога с именем lib_easy_example - +add_subdirectory(lib_Stack) +add_subdirectory(lib_Algorithms) +add_subdirectory(lib_list) +add_subdirectory(lib_doublyList) add_subdirectory(main) # подключаем дополнительный CMakeLists.txt из подкаталога с именем main option(BTEST "build test?" ON) # указываем подключаем ли google-тесты (ON или YES) или нет (OFF или NO) diff --git a/lib_algorithms/Algorithms.cpp b/lib_algorithms/Algorithms.cpp new file mode 100644 index 00000000..945579f8 --- /dev/null +++ b/lib_algorithms/Algorithms.cpp @@ -0,0 +1,26 @@ +#include "Algorithms.h" + +bool check_balanced_brackets(const std::string& expression) { + Stack stack(expression.length()); + + for (char ch : expression) { + if (ch == '(' || ch == '{' || ch == '[') { + stack.push(ch); + } + else if (ch == ')' || ch == '}' || ch == ']') { + + if (stack.is_empty()) { + return false; + } + + char top_char = stack.pop(); + + if ((ch == ')' && top_char != '(') || + (ch == '}' && top_char != '{') || + (ch == ']' && top_char != '[')) { + return false; + } + } + } + return stack.is_empty(); +} \ No newline at end of file diff --git a/lib_algorithms/Algorithms.h b/lib_algorithms/Algorithms.h new file mode 100644 index 00000000..0550627b --- /dev/null +++ b/lib_algorithms/Algorithms.h @@ -0,0 +1,2 @@ +#include "Stack.h" +bool check_balanced_brackets(const std::string& expression); \ No newline at end of file diff --git a/lib_algorithms/CMakeLists.txt b/lib_algorithms/CMakeLists.txt new file mode 100644 index 00000000..a43026e7 --- /dev/null +++ b/lib_algorithms/CMakeLists.txt @@ -0,0 +1,3 @@ +create_project_lib(Algorithms) +add_depend(Algorithms List ../lib_list) +add_depend(Algorithms Stack ../lib_stack) \ No newline at end of file diff --git a/lib_doublyList/CMakeLists.txt b/lib_doublyList/CMakeLists.txt new file mode 100644 index 00000000..3356e664 --- /dev/null +++ b/lib_doublyList/CMakeLists.txt @@ -0,0 +1,2 @@ +create_project_lib(DoublyList) +add_depend(DoublyList List ../lib_list) \ No newline at end of file diff --git a/lib_doublyList/doublyList.cpp b/lib_doublyList/doublyList.cpp new file mode 100644 index 00000000..e69de29b diff --git a/lib_doublyList/doublyList.h b/lib_doublyList/doublyList.h new file mode 100644 index 00000000..00d2ff73 --- /dev/null +++ b/lib_doublyList/doublyList.h @@ -0,0 +1,245 @@ +#pragma once + +template +struct Node { + T value; + Node* next; + Node* prev; + + Node(T value_, Node* prev_ = nullptr, Node* next_ = nullptr) + : value(value_), prev(prev_), next(next_) { + } +}; + +template +class List { + Node* _head; + Node* _tail; + int _count; + +public: + class Iterator { + Node* current; + + public: + Iterator() : current(nullptr) {} + Iterator(Node* node) : current(node) {} + + Iterator& operator=(const Iterator& other) { + current = other.current; + return *this; + } + + T& operator*() { + return current->value; + } + + + Iterator& operator++() { + if (current != nullptr) { + current = current->next; + } + return *this; + } + Iterator operator++(int) { + Iterator temp = *this; + ++(*this); + return temp; + } + + Iterator operator--(int) { + Iterator temp = *this; + --(*this); + return temp; + } + + bool operator==(const Iterator& other) const { + return current == other.current; + } + + bool operator!=(const Iterator& other) const { + return current != other.current; + } + + Node* get_node() const { return current; } + }; + + + List() : _head(nullptr), _tail(nullptr), _count(0) {} + + List(const List& other) : _head(nullptr), _tail(nullptr), _count(0) { + Node* current = other._head; + while (current != nullptr) { + push_back(current->value); + current = current->next; + } + } + + ~List() { + clear(); + } + + List& operator=(const List& other) { + if (this != &other) { + clear(); + Node* current = other._head; + while (current != nullptr) { + push_back(current->value); + current = current->next; + } + } + return *this; + } + + Iterator begin() { return Iterator(_head); } + Iterator end() { return Iterator(nullptr); } + + void push_front(const T& val) { + Node* new_node = new Node(val, nullptr, _head); + + if (_head != nullptr) { + _head->prev = new_node; + } + + _head = new_node; + + if (_tail == nullptr) { + _tail = new_node; + } + + _count++; + } + + void push_back(const T& val) { + Node* new_node = new Node(val, _tail, nullptr); + + if (_tail != nullptr) { + _tail->next = new_node; + } + + _tail = new_node; + + if (_head == nullptr) { + _head = new_node; + } + + _count++; + } + + void insert(const Iterator& position, const T& val) { + if (position == begin()) { + push_front(val); + return; + } + + if (position == end()) { + push_back(val); + return; + } + + Node* current_node = position.get_node(); + Node* prev_node = current_node->prev; + + Node* new_node = new Node(val, prev_node, current_node); + + prev_node->next = new_node; + current_node->prev = new_node; + + _count++; + } + + void pop_front() { + if (is_empty()) throw "List is empty"; + + Node* temp = _head; + _head = _head->next; + + if (_head != nullptr) { + _head->prev = nullptr; + } + else { + _tail = nullptr; + } + + delete temp; + _count--; + } + + void pop_back() { + if (is_empty()) throw "List is empty"; + + Node* temp = _tail; + _tail = _tail->prev; + + if (_tail != nullptr) { + _tail->next = nullptr; + } + else { + _head = nullptr; + } + + delete temp; + _count--; + } + + void erase(const Iterator& position) { + if (position == end()) return; + + Node* node_to_delete = position.get_node(); + + if (node_to_delete == _head) { + pop_front(); + return; + } + + if (node_to_delete == _tail) { + pop_back(); + return; + } + + Node* prev_node = node_to_delete->prev; + Node* next_node = node_to_delete->next; + + prev_node->next = next_node; + next_node->prev = prev_node; + + delete node_to_delete; + _count--; + } + + T& front() { + if (is_empty()) throw "List is empty"; + return _head->value; + } + + + T& back() { + if (is_empty()) throw "List is empty"; + return _tail->value; + } + + bool is_empty() const { + return _head == nullptr; + } + + int size() const { + return _count; + } + + void clear() { + while (!is_empty()) { + pop_front(); + } + } + + Iterator find(const T& val) { + Node* current = _head; + while (current != nullptr) { + if (current->value == val) { + return Iterator(current); + } + current = current->next; + } + return end(); + } +}; \ No newline at end of file diff --git a/lib_list/CMakeLists.txt b/lib_list/CMakeLists.txt new file mode 100644 index 00000000..148b539a --- /dev/null +++ b/lib_list/CMakeLists.txt @@ -0,0 +1 @@ +create_project_lib(List) \ No newline at end of file diff --git a/lib_list/List.cpp b/lib_list/List.cpp new file mode 100644 index 00000000..e69de29b diff --git a/lib_list/List.h b/lib_list/List.h new file mode 100644 index 00000000..4746b8df --- /dev/null +++ b/lib_list/List.h @@ -0,0 +1,278 @@ +#pragma once + + +template +struct Node { + + T value; + Node* next; + Node(T value_, Node* next_ = nullptr); +}; + +template +Node::Node(T value_, Node* next_) : value(value_), next(next_) {} + +template +class List { + + Node* _head; + Node* _tail; + int _count; + +public: + + + class Iterator { + + + Node* current; + + public: + + Iterator() : current(nullptr) {} + Iterator(Node* node) : current(node) {} + + Iterator& operator=(const Iterator& other) { + current = other.current; + return *this; + } + + T& operator*() { + return current->value; + } + + Iterator& operator++() { + if (current != nullptr) { + current = current->next; + } + return *this; + } + + Iterator operator++(int) { + Iterator temp = *this; + ++(*this); + return temp; + } + + bool operator==(const Iterator& other) const { + return current == other.current; + } + + bool operator!=(const Iterator& other) const { + return current != other.current; + } + + }; + + + + List() : _head(nullptr), _tail(nullptr), _count(0) {} + List(const List& other) { + _head = nullptr; + _tail = nullptr; + _count = 0; + + Node* current = other._head; + while (current != nullptr) { + push_back(current->value); + current = current->next; + } + } + + ~List() { + while (!is_empty()) { + pop_front(); + } + } + + List& operator=(const List& other) { + if (this != &other) { + while (!is_empty()) { + pop_front(); + } + + Node* current = other._head; + while (current != nullptr) { + push_back(current->value); + current = current->next; + } + } + return *this; + } + + void push_front(const T& val); + void push_back(const T& val); + void insert(int pos, const T& val); + void insert(Node* node, const T& val); + + void pop_front(); + void pop_back(); + T front() const; + T back() const; + void erase(Node* node); + + bool is_empty() const; + Node* find(const T& val); + int size() const { return _count; } + +}; + +template +void List::push_front(const T& val) { + + Node* node = new Node(val, _head); + if (is_empty()) _tail = node; + _head = node; + _count++; + +} + +template +bool List::is_empty() const { + return _head == nullptr; +} + +template +void List::push_back(const T& val) { + + Node* node = new Node(val); + // _tail->next = node; // -, + if (is_empty()) { + _head = node; + _tail = node; + _count++; + return; + } + + _tail->next = node; + _tail = node; + ++_count; + // nullptr + // (val) ---> Null + // node + +} + +template +void List::insert(Node* node, const T& val) { + if (node == nullptr) throw ("Error"); + Node* new_node = new Node(val, node->next); + node->next = new_node; + if (_tail == node) { + _tail = new_node; + } + _count++; +} + +template +void List::insert(int pos, const T& val) { + if (pos < 0 || pos >= _count) throw ("Error"); + + if (pos == 0) { + push_front(val); + } + else if (pos == _count - 1) { + push_back(val); + } + else { + int cur_pos = 0; + Node* cur = _head; + while (cur != nullptr) { + if (cur_pos == pos - 1) break; + cur_pos++; + cur = cur->next; + } + + if (cur != nullptr) { + Node* new_node = new Node(val, cur->next); + cur->next = new_node; + _count++; + } + } +} + +template +Node* List::find(const T& val) { + Node* current = _head; + while (current != nullptr) { + if (current->value == val) { + return current; + } + current = current->next; + } + return nullptr; +} + +template +void List::pop_front() { + if (is_empty()) throw ("List is empty"); + + Node* temp = _head; + _head = _head->next; + delete temp; + _count--; + + if (_head == nullptr) { + _tail = nullptr; + } +} + +template +void List::pop_back() { + if (is_empty()) throw ("List is empty"); + + if (_head == _tail) { + delete _head; + _head = nullptr; + _tail = nullptr; + _count = 0; + return; + } + + Node* current = _head; + while (current->next != _tail) { + current = current->next; + } + + delete _tail; + _tail = current; + _tail->next = nullptr; + _count--; +} + +template +T List::front() const { + if (is_empty()) throw ("List is empty"); + return _head->value; +} + +template +T List::back() const { + if (is_empty()) throw ("List is empty"); + return _tail->value; +} + + +template +void List::erase(Node* node) { + if (node == nullptr || is_empty()) return; + + if (node == _head) { + pop_front(); + return; + } + + Node* prev = _head; + while (prev != nullptr && prev->next != node) { + prev = prev->next; + } + + if (prev != nullptr) { + prev->next = node->next; + if (node == _tail) { + _tail = prev; + } + delete node; + _count--; + } +} diff --git a/lib_stack/CMakeLists.txt b/lib_stack/CMakeLists.txt new file mode 100644 index 00000000..b6bedb01 --- /dev/null +++ b/lib_stack/CMakeLists.txt @@ -0,0 +1 @@ +create_project_lib(Stack) \ No newline at end of file diff --git a/lib_stack/Stack.cpp b/lib_stack/Stack.cpp new file mode 100644 index 00000000..e69de29b diff --git a/lib_stack/Stack.h b/lib_stack/Stack.h new file mode 100644 index 00000000..a9747a09 --- /dev/null +++ b/lib_stack/Stack.h @@ -0,0 +1,122 @@ +#pragma once +#include +#include "List.h" +template +class Stack { + +private: + + T* _data; + int _size, _top; + +public: + + Stack(int size); + Stack(); + void push(const T& val); + T pop(); + inline T top(); + inline bool is_empty() const noexcept; + inline bool is_full() const noexcept; + void clear(); + +}; + +template +inline bool Stack::is_empty() const noexcept { + + return _top == 0; + +} + +template +inline bool Stack::is_full() const noexcept { + + return _top == _size; + +} + +template +Stack::Stack(int size) : _data(new T[size]), _size(size), _top(0) {}; +template +Stack::Stack() : _data(nullptr), _size(0), _top(0) {}; + +template +void Stack::push(const T& val) { + + if (is_full()) { + throw std::logic_error("Queue is full"); + } + _data[_top++] = val; + +} + +template +T Stack::pop() { + + if (is_empty()) { + throw std::logic_error("Stack is empty"); + } + return _data[--_top]; + +} +template +inline T Stack::top() { + if (is_empty()) { + throw std::logic_error("Stack is empty"); + } + return _data[_top - 1]; +} + +template +void Stack::clear() { + + _top = 0; + +} + + +template +class StackList { +private: + List _list; + +public: + StackList() = default; + + void push(const T& val) { + _list.push_front(val); + } + + T pop() { + if (_list.is_empty()) { + throw std::logic_error("Stack is empty"); + } + T value = _list.front(); + _list.pop_front(); + return value; + } + + T& top() { + if (_list.is_empty()) { + throw std::logic_error("Stack is empty"); + } + return _list.front(); + } + + bool is_empty() const { + return _list.is_empty(); + } + + int size() const { + return _list.size(); + } + + void clear() { + _list.clear(); + } + + bool is_full() const { + return false; + } +}; \ No newline at end of file diff --git a/tests/test_algorithms.cpp b/tests/test_algorithms.cpp new file mode 100644 index 00000000..0e4e5f07 --- /dev/null +++ b/tests/test_algorithms.cpp @@ -0,0 +1,76 @@ +#include +#include "Algorithms.h" + +TEST(CheckBalancedBracketsTest1, BalancedSimpleParentheses) { + EXPECT_TRUE(check_balanced_brackets("()")); + EXPECT_TRUE(check_balanced_brackets("(())")); + EXPECT_TRUE(check_balanced_brackets("()()")); +} + +TEST(CheckBalancedBracketsTest2, BalancedMixedBrackets) { + EXPECT_TRUE(check_balanced_brackets("{}")); + EXPECT_TRUE(check_balanced_brackets("[]")); + EXPECT_TRUE(check_balanced_brackets("{[()]}")); + EXPECT_TRUE(check_balanced_brackets("[{()}]")); +} + +TEST(CheckBalancedBracketsTest3, BalancedComplexExpressions) { + EXPECT_TRUE(check_balanced_brackets("({[]})")); + EXPECT_TRUE(check_balanced_brackets("{([])}")); + EXPECT_TRUE(check_balanced_brackets("([{}])")); +} + +TEST(CheckBalancedBracketsTest4, BalancedWithOtherCharacters) { + EXPECT_TRUE(check_balanced_brackets("(a + b)")); + EXPECT_TRUE(check_balanced_brackets("{a * [b + c]}")); + EXPECT_TRUE(check_balanced_brackets("if (x > 0) { y = x * 2; }")); +} + +TEST(CheckBalancedBracketsTest5, UnbalancedMissingClosing) { + EXPECT_FALSE(check_balanced_brackets("(")); + EXPECT_FALSE(check_balanced_brackets("{")); + EXPECT_FALSE(check_balanced_brackets("[")); + EXPECT_FALSE(check_balanced_brackets("(()")); +} + +TEST(CheckBalancedBracketsTest6, UnbalancedMissingOpening) { + EXPECT_FALSE(check_balanced_brackets(")")); + EXPECT_FALSE(check_balanced_brackets("}")); + EXPECT_FALSE(check_balanced_brackets("]")); + EXPECT_FALSE(check_balanced_brackets("())")); +} + +TEST(CheckBalancedBracketsTest7, UnbalancedWrongOrder) { + EXPECT_FALSE(check_balanced_brackets(")(")); + EXPECT_FALSE(check_balanced_brackets("][")); + EXPECT_FALSE(check_balanced_brackets("}{")); +} + +TEST(CheckBalancedBracketsTest8, UnbalancedMismatchedTypes) { + EXPECT_FALSE(check_balanced_brackets("(]")); + EXPECT_FALSE(check_balanced_brackets("{]")); + EXPECT_FALSE(check_balanced_brackets("[}")); + EXPECT_FALSE(check_balanced_brackets("{)")); +} + +TEST(CheckBalancedBracketsTest9, UnbalancedNestedMismatch) { + EXPECT_FALSE(check_balanced_brackets("{[}]")); + EXPECT_FALSE(check_balanced_brackets("({[}])")); + EXPECT_FALSE(check_balanced_brackets("[(])")); +} + +TEST(CheckBalancedBracketsTest10, EmptyString) { + EXPECT_TRUE(check_balanced_brackets("")); +} + +TEST(CheckBalancedBracketsTest11, NoBrackets) { + EXPECT_TRUE(check_balanced_brackets("abc")); + EXPECT_TRUE(check_balanced_brackets("123")); + EXPECT_TRUE(check_balanced_brackets("hello world")); +} + +TEST(CheckBalancedBracketsTest12, MixedBalanced) { + EXPECT_TRUE(check_balanced_brackets("([]){()}")); + EXPECT_TRUE(check_balanced_brackets("({[]})()")); + EXPECT_TRUE(check_balanced_brackets("(([]){})")); +} \ No newline at end of file diff --git a/tests/tests_List.cpp b/tests/tests_List.cpp new file mode 100644 index 00000000..071b6f5b --- /dev/null +++ b/tests/tests_List.cpp @@ -0,0 +1,152 @@ +#include +#include "List.h" + +TEST(ListTest1, DefaultConstructor) { + List list; + EXPECT_TRUE(list.is_empty()); + EXPECT_EQ(list.size(), 0); +} + +TEST(ListTest2, PushFrontSingle) { + List list; + list.push_front(42); + EXPECT_FALSE(list.is_empty()); + EXPECT_EQ(list.size(), 1); + EXPECT_EQ(list.front(), 42); + EXPECT_EQ(list.back(), 42); +} + +TEST(ListTest3, PushBackSingle) { + List list; + list.push_back(42); + EXPECT_FALSE(list.is_empty()); + EXPECT_EQ(list.size(), 1); + EXPECT_EQ(list.front(), 42); + EXPECT_EQ(list.back(), 42); +} + +TEST(ListTest4, PushFrontMultiple) { + List list; + list.push_front(3); + list.push_front(2); + list.push_front(1); + EXPECT_EQ(list.size(), 3); + EXPECT_EQ(list.front(), 1); + EXPECT_EQ(list.back(), 3); +} + +TEST(ListTest5, PushBackMultiple) { + List list; + list.push_back(1); + list.push_back(2); + list.push_back(3); + EXPECT_EQ(list.size(), 3); + EXPECT_EQ(list.front(), 1); + EXPECT_EQ(list.back(), 3); +} + +TEST(ListTest6, MixedPushOperations) { + List list; + list.push_front(2); + list.push_back(3); + list.push_front(1); + list.push_back(4); + EXPECT_EQ(list.size(), 4); + EXPECT_EQ(list.front(), 1); + EXPECT_EQ(list.back(), 4); +} + +TEST(ListTest7, PopFront) { + List list; + list.push_back(1); + list.push_back(2); + list.push_back(3); + + list.pop_front(); + EXPECT_EQ(list.size(), 2); + EXPECT_EQ(list.front(), 2); + EXPECT_EQ(list.back(), 3); + + list.pop_front(); + EXPECT_EQ(list.size(), 1); + EXPECT_EQ(list.front(), 3); + EXPECT_EQ(list.back(), 3); + + list.pop_front(); + EXPECT_TRUE(list.is_empty()); +} + +TEST(ListTest8, PopBack) { + List list; + list.push_back(1); + list.push_back(2); + list.push_back(3); + + list.pop_back(); + EXPECT_EQ(list.size(), 2); + EXPECT_EQ(list.front(), 1); + EXPECT_EQ(list.back(), 2); + + list.pop_back(); + EXPECT_EQ(list.size(), 1); + EXPECT_EQ(list.front(), 1); + EXPECT_EQ(list.back(), 1); + + list.pop_back(); + EXPECT_TRUE(list.is_empty()); +} + +TEST(ListTest9, PopFrontEmptyThrows) { + List list; + EXPECT_THROW(list.pop_front(), const char*); +} + +TEST(ListTest10, PopBackEmptyThrows) { + List list; + EXPECT_THROW(list.pop_back(), const char*); +} + +TEST(ListTest11, FrontEmptyThrows) { + List list; + EXPECT_THROW(list.front(), const char*); +} + +TEST(ListTest12, BackEmptyThrows) { + List list; + EXPECT_THROW(list.back(), const char*); +} + +TEST(ListTest13, FindExisting) { + List list; + list.push_back(1); + list.push_back(2); + list.push_back(3); + + Node* found = list.find(2); + ASSERT_NE(found, nullptr); + EXPECT_EQ(found->value, 2); +} + +TEST(ListTest14, FindNonExisting) { + List list; + list.push_back(1); + list.push_back(2); + + Node* found = list.find(3); + EXPECT_EQ(found, nullptr); +} + +TEST(ListTest15, FindInEmpty) { + List list; + Node* found = list.find(1); + EXPECT_EQ(found, nullptr); +} + +TEST(ListTest16, InsertAtFront) { + List list; + list.push_back(2); + list.insert(0, 1); + EXPECT_EQ(list.size(), 2); + EXPECT_EQ(list.front(), 1); + EXPECT_EQ(list.back(), 2); +} diff --git a/tests/tests_stack.cpp b/tests/tests_stack.cpp new file mode 100644 index 00000000..abbde70b --- /dev/null +++ b/tests/tests_stack.cpp @@ -0,0 +1,128 @@ +#include +#include "Stack.h" + + +TEST(StackTest, ConstructorWithSize) { + Stack stack(5); + EXPECT_TRUE(stack.is_empty()); + EXPECT_FALSE(stack.is_full()); +} + +TEST(StackTest, DefaultConstructor) { + Stack stack; + EXPECT_TRUE(stack.is_empty()); + EXPECT_TRUE(stack.is_full()); +} + +TEST(StackTest, PushElements) { + Stack stack(3); + + stack.push(10); + EXPECT_FALSE(stack.is_empty()); + EXPECT_EQ(stack.top(), 10); + + stack.push(20); + EXPECT_EQ(stack.top(), 20); + + stack.push(30); + EXPECT_TRUE(stack.is_full()); + EXPECT_EQ(stack.top(), 30); + ASSERT_ANY_THROW(stack.push(40)); +} + +TEST(StackTest, PopElements) { + Stack stack(3); + stack.push(10); + stack.push(20); + stack.push(30); + + EXPECT_EQ(stack.top(), 30); + stack.pop(); + + EXPECT_EQ(stack.top(), 20); + stack.pop(); + + EXPECT_EQ(stack.top(), 10); + stack.pop(); + + EXPECT_TRUE(stack.is_empty()); +} + +TEST(StackTest, ClearStack) { + Stack stack(3); + stack.push(10); + stack.push(20); + + EXPECT_FALSE(stack.is_empty()); + stack.clear(); + EXPECT_TRUE(stack.is_empty()); +} + +TEST(StackTest, DifferentDataTypes) { + Stack doubleStack(3); + doubleStack.push(3.14); + doubleStack.push(2.71); + EXPECT_DOUBLE_EQ(doubleStack.top(), 2.71); + + Stack stringStack(2); + stringStack.push("Hello"); + stringStack.push("World"); + EXPECT_EQ(stringStack.top(), "World"); +} + +TEST(StackTest, SequenceOfOperations) { + Stack stack(5); + + for (int i = 1; i <= 5; ++i) { + stack.push(i * 10); + } + + EXPECT_TRUE(stack.is_full()); + EXPECT_EQ(stack.top(), 50); + + stack.pop(); + stack.pop(); + + EXPECT_EQ(stack.top(), 30); + EXPECT_FALSE(stack.is_empty()); + EXPECT_FALSE(stack.is_full()); + + stack.push(60); + stack.push(70); + + EXPECT_EQ(stack.top(), 70); + EXPECT_TRUE(stack.is_full()); + + stack.clear(); + EXPECT_TRUE(stack.is_empty()); + + stack.push(100); + EXPECT_EQ(stack.top(), 100); +} + +TEST(StackTest, IsEmptyMethod) { + Stack stack(2); + + EXPECT_TRUE(stack.is_empty()); + + stack.push(1); + EXPECT_FALSE(stack.is_empty()); + + stack.pop(); + EXPECT_TRUE(stack.is_empty()); +} + +TEST(StackTest, IsFullMethod) { + Stack stack(3); + + EXPECT_FALSE(stack.is_full()); + + stack.push(1); + stack.push(2); + stack.push(3); + + EXPECT_TRUE(stack.is_full()); + + stack.pop(); + EXPECT_FALSE(stack.is_full()); +} \ No newline at end of file