From 04a76217a1420ff471585cc8b86e32f6f05babdf Mon Sep 17 00:00:00 2001 From: danberx <118466592+danberx@users.noreply.github.com> Date: Sat, 7 Mar 2026 09:03:25 +0000 Subject: [PATCH 1/5] task01 solved + tests --- task_01/src/main.cpp | 24 +++++++++++++++++++++++- task_01/src/solution.cpp | 24 ++++++++++++++++++++++++ task_01/src/solution.hpp | 16 ++++++++++++++++ task_01/src/test.cpp | 31 +++++++++++++++++++++++++++++-- 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 task_01/src/solution.cpp create mode 100644 task_01/src/solution.hpp diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 0e4393b..dad2b25 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,3 +1,25 @@ #include +#include -int main() { return 0; } +int main() { + int n, summ; + std::cin >> summ >> n; + std::vector arr(n); + for (int i = 0; i < n; i++) { + std::cin >> arr[i]; + } + int i = 0, j = arr.size() - 1; + while (i < j) { + int cur_summ = arr[i] + arr[j]; + if (cur_summ == summ) { + std::cout << arr[i] << " " << arr[j]; + return 0; + } + if (cur_summ < summ) { + i++; + } else { + j--; + } + } + std::cout << -1; +} diff --git a/task_01/src/solution.cpp b/task_01/src/solution.cpp new file mode 100644 index 0000000..d53d670 --- /dev/null +++ b/task_01/src/solution.cpp @@ -0,0 +1,24 @@ +#include "solution.hpp" + +// bool operator==(const Answer& lhs, const Answer& rhs) { +// if (!lhs.have_answer && !rhs.have_answer) { +// return true; +// } +// return lhs.have_answer == rhs.have_answer && lhs.lhs == rhs.lhs && lhs.rhs == rhs.rhs; +// } + +Answer SumOfTwo(std::vector arr, int summ) { + int i = 0, j = arr.size() - 1; + while (i < j) { + int cur_summ = arr[i] + arr[j]; + if (cur_summ == summ) { + return Answer(arr[i], arr[j]); + } + if (cur_summ < summ) { + i++; + } else { + j--; + } + } + return Answer(); +} diff --git a/task_01/src/solution.hpp b/task_01/src/solution.hpp new file mode 100644 index 0000000..11ef8cd --- /dev/null +++ b/task_01/src/solution.hpp @@ -0,0 +1,16 @@ +#include + +struct Answer { + int lhs, rhs; + bool have_answer; + Answer(): have_answer(false) {} + Answer(int l, int r): lhs(l), rhs(r), have_answer(true) {} + bool operator==(const Answer other) { + if (!have_answer && !other.have_answer) { + return true; + } + return have_answer == other.have_answer && lhs == other.lhs && rhs == other.rhs; + } +}; + +Answer SumOfTwo(std::vector arr, int summ); diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index 87cef73..12ad423 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,5 +1,32 @@ #include +#include "solution.hpp" -TEST(Test, Simple) { - ASSERT_EQ(1, 1); // Stack [] +TEST(SumOfTwoTest, Simple) { + std::vector array = {1, 3, 5, 6, 10, 23, 30}; + ASSERT_EQ((SumOfTwo(array, 26) == Answer(3, 23)), true); + ASSERT_EQ((SumOfTwo(array, 16) == Answer(6, 10)), true); + ASSERT_EQ((SumOfTwo(array, 53) == Answer(23, 30)), true); + ASSERT_EQ((SumOfTwo(array, 4) == Answer(1, 3)), true); + std::vector with_negative = {-12, -10, -4, 0, 2, 5, 10}; + ASSERT_EQ((SumOfTwo(with_negative, -16) == Answer(-12, -4)), true); + ASSERT_EQ((SumOfTwo(with_negative, 0) == Answer(-10, 10)), true); + ASSERT_EQ((SumOfTwo(with_negative, 10) == Answer(0, 10)), true); +} + +TEST(SumOfTwoTest, NoSolution) { + std::vector array = {1, 4, 6, 10}; + ASSERT_EQ((SumOfTwo(array, 100) == Answer()), true); + ASSERT_EQ((SumOfTwo(array, 6) == Answer()), true); + ASSERT_EQ((SumOfTwo({1}, 2)) == Answer(), true); +} + +TEST(SumOfTwoTest, MoreSolutions) { + std::vector two_sol = {1, 2, 4, 5}; + Answer result = SumOfTwo(two_sol, 6); + bool check = (result == Answer(1, 5)) || (result == Answer(2, 4)); + ASSERT_EQ(check, true); + std::vector four_sol = {-10, 0, 1, 3, 4, 6, 7, 17}; + result = SumOfTwo(four_sol, 7); + check = (result == Answer(-10, 17)) || (result == Answer(0, 7)) || (result == Answer(1, 6)) || (result == Answer(3, 4)); + ASSERT_EQ(check, true); } \ No newline at end of file From 77967fd05c7031d17a89a0dc6c6548ebedecd056 Mon Sep 17 00:00:00 2001 From: danberx <118466592+danberx@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:54:14 +0000 Subject: [PATCH 2/5] task_03 + tests --- task_03/src/main.cpp | 9 ++++++++- task_03/src/solution.cpp | 20 ++++++++++++++++++++ task_03/src/solution.hpp | 4 ++++ task_03/src/test.cpp | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 task_03/src/solution.cpp create mode 100644 task_03/src/solution.hpp diff --git a/task_03/src/main.cpp b/task_03/src/main.cpp index 0e4393b..403906c 100644 --- a/task_03/src/main.cpp +++ b/task_03/src/main.cpp @@ -1,3 +1,10 @@ #include +#include "solution.hpp" -int main() { return 0; } +int main() { + std::string s; + std::cin >> s; + for (const auto& el : ButtonPhone(s)) { + std::cout << el << " "; + } +} \ No newline at end of file diff --git a/task_03/src/solution.cpp b/task_03/src/solution.cpp new file mode 100644 index 0000000..207d80b --- /dev/null +++ b/task_03/src/solution.cpp @@ -0,0 +1,20 @@ +#include "solution.hpp" + +const std::vector convert = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; + +void AddCombination(int index, const std::string& s, std::vector& add, std::string current) { + if (index == s.size()) { + add.push_back(current); + return; + } + for (char c : convert[s[index] - '2']) { + std::string new_s = current + c; + AddCombination(index + 1, s, add, new_s); + } +} + +std::vector ButtonPhone(std::string s) { + std::vector result; + AddCombination(0, s, result, ""); + return result; +} \ No newline at end of file diff --git a/task_03/src/solution.hpp b/task_03/src/solution.hpp new file mode 100644 index 0000000..aa79cf0 --- /dev/null +++ b/task_03/src/solution.hpp @@ -0,0 +1,4 @@ +#include +#include + +std::vector ButtonPhone(std::string s); \ No newline at end of file diff --git a/task_03/src/test.cpp b/task_03/src/test.cpp index 869094d..5f77e2a 100644 --- a/task_03/src/test.cpp +++ b/task_03/src/test.cpp @@ -1,4 +1,39 @@ #include +#include "solution.hpp" -TEST(TopologySort, Simple) { ASSERT_EQ(1, 1); } +TEST(ButtonPhoneTest, OneLetter) { + std::vector expected1 = {"a", "b", "c"}; + std::vector res1 = ButtonPhone("2"); + ASSERT_EQ(res1, expected1); + + std::vector expected2 = {"w", "x", "y", "z"}; + std::vector res2 = ButtonPhone("9"); + ASSERT_EQ(res2, expected2); +} + +TEST(ButtonPhoneTest, TwoLetters) { + std::vector expected1 = {"pw", "px", "py", "pz", "qw", "qx", "qy", "qz", "rw", "rx", "ry", "rz", "sw", "sx", "sy", "sz"}; + std::vector res1 = ButtonPhone("79"); + ASSERT_EQ(res1, expected1); + + std::vector expected2 = {"gg", "gh", "gi", "hg", "hh", "hi", "ig", "ih", "ii"}; + std::vector res2 = ButtonPhone("44"); + ASSERT_EQ(res2, expected2); +} + +TEST(ButtonPhoneTest, ThreeLetters) { + std::vector expected1 = {"ajw", "ajx", "ajy", "ajz", "akw", "akx", "aky", "akz", "alw", "alx", "aly", "alz", "bjw", "bjx", "bjy", "bjz", "bkw", "bkx", "bky", "bkz", "blw", "blx", "bly", "blz", "cjw", "cjx", "cjy", "cjz", "ckw", "ckx", "cky", "ckz", "clw", "clx", "cly", "clz"}; + std::vector res1 = ButtonPhone("259"); + ASSERT_EQ(res1, expected1); + + std::vector expected2 = {"ddd", "dde", "ddf", "ded", "dee", "def", "dfd", "dfe", "dff", "edd", "ede", "edf", "eed", "eee", "eef", "efd", "efe", "eff", "fdd", "fde", "fdf", "fed", "fee", "fef", "ffd", "ffe", "fff"}; + std::vector res2 = ButtonPhone("333"); + ASSERT_EQ(res2, expected2); +} + +TEST(ButtonPhoneTest, FourLetters) { + std::vector expected = {"amwj", "amwk", "amwl", "amxj", "amxk", "amxl", "amyj", "amyk", "amyl", "amzj", "amzk", "amzl", "anwj", "anwk", "anwl", "anxj", "anxk", "anxl", "anyj", "anyk", "anyl", "anzj", "anzk", "anzl", "aowj", "aowk", "aowl", "aoxj", "aoxk", "aoxl", "aoyj", "aoyk", "aoyl", "aozj", "aozk", "aozl", "bmwj", "bmwk", "bmwl", "bmxj", "bmxk", "bmxl", "bmyj", "bmyk", "bmyl", "bmzj", "bmzk", "bmzl", "bnwj", "bnwk", "bnwl", "bnxj", "bnxk", "bnxl", "bnyj", "bnyk", "bnyl", "bnzj", "bnzk", "bnzl", "bowj", "bowk", "bowl", "boxj", "boxk", "boxl", "boyj", "boyk", "boyl", "bozj", "bozk", "bozl", "cmwj", "cmwk", "cmwl", "cmxj", "cmxk", "cmxl", "cmyj", "cmyk", "cmyl", "cmzj", "cmzk", "cmzl", "cnwj", "cnwk", "cnwl", "cnxj", "cnxk", "cnxl", "cnyj", "cnyk", "cnyl", "cnzj", "cnzk", "cnzl", "cowj", "cowk", "cowl", "coxj", "coxk", "coxl", "coyj", "coyk", "coyl", "cozj", "cozk", "cozl"}; + std::vector res = ButtonPhone("2695"); + ASSERT_EQ(res, expected); +} \ No newline at end of file From 62ca2ac65bae26b84e1e002c15e74ee1eb2cd4bf Mon Sep 17 00:00:00 2001 From: danberx <118466592+danberx@users.noreply.github.com> Date: Sat, 14 Mar 2026 08:55:39 +0000 Subject: [PATCH 3/5] task_07 selection sort --- task_07/src/main.cpp | 14 ++++++++++- task_07/src/sort.cpp | 13 ++++++++++ task_07/src/sort.hpp | 3 +++ task_07/src/test.cpp | 57 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 task_07/src/sort.cpp create mode 100644 task_07/src/sort.hpp diff --git a/task_07/src/main.cpp b/task_07/src/main.cpp index 0e4393b..1067d7d 100644 --- a/task_07/src/main.cpp +++ b/task_07/src/main.cpp @@ -1,3 +1,15 @@ #include +#include "sort.hpp" -int main() { return 0; } +int main() { + int n; + std::cin >> n; + std::vector arr(n); + for (int i = 0; i < n; ++i) { + std::cin >> arr[i]; + } + SelectionSort(arr); + for (int i = 0; i < n; ++i) { + std::cout << arr[i] << " "; + } +} \ No newline at end of file diff --git a/task_07/src/sort.cpp b/task_07/src/sort.cpp new file mode 100644 index 0000000..eda332c --- /dev/null +++ b/task_07/src/sort.cpp @@ -0,0 +1,13 @@ +#include "sort.hpp" + +void SelectionSort(std::vector& data) { + for (int bord = 0; bord < data.size(); ++bord) { + int min_index = bord; + for (int j = bord + 1; j < data.size(); ++j) { + if (data[j] < data[min_index]) { + min_index = j; + } + } + std::swap(data[min_index], data[bord]); + } +} \ No newline at end of file diff --git a/task_07/src/sort.hpp b/task_07/src/sort.hpp new file mode 100644 index 0000000..6495eeb --- /dev/null +++ b/task_07/src/sort.hpp @@ -0,0 +1,3 @@ +#include + +void SelectionSort(std::vector& data); \ No newline at end of file diff --git a/task_07/src/test.cpp b/task_07/src/test.cpp index 5e11617..0782606 100644 --- a/task_07/src/test.cpp +++ b/task_07/src/test.cpp @@ -1,6 +1,55 @@ - #include +#include "sort.hpp" +#include +#include +#include + + +TEST(Sort, Simple) { + std::mt19937 mt(time(nullptr)); + + int size = 10; + std::vector data1(size); + for (int i = 0; i < size; ++i) { + data1[i] = mt() % 30; + } + + std::vector sorted1(size); + std::copy(data1.begin(), data1.end(), sorted1.begin()); + std::sort(sorted1.begin(), sorted1.end()); + SelectionSort(data1); + ASSERT_EQ(data1, sorted1); + + size = 50; + std::vector data2(size); + for (int i = 0; i < size; ++i) { + data2[i] = mt() % 1000; + } + std::vector sorted2(size); + std::copy(data2.begin(), data2.end(), sorted2.begin()); + std::sort(sorted2.begin(), sorted2.end()); + SelectionSort(data2); + ASSERT_EQ(data2, sorted2); + + size = 500; + std::vector data3(size); + for (int i = 0; i < size; ++i) { + data3[i] = mt() % 100000; + } + std::vector sorted3(size); + std::copy(data3.begin(), data3.end(), sorted3.begin()); + std::sort(sorted3.begin(), sorted3.end()); + SelectionSort(data3); + ASSERT_EQ(data3, sorted3); -TEST(TopologySort, Simple) { - ASSERT_EQ(1, 1); // Stack [] -} + size = 1000; + std::vector data4(size); + for (int i = 0; i < size; ++i) { + data4[i] = mt() % 100000; + } + std::vector sorted4(size); + std::copy(data4.begin(), data4.end(), sorted4.begin()); + std::sort(sorted4.begin(), sorted4.end()); + SelectionSort(data4); + ASSERT_EQ(data4, sorted4); + } From 5ca902c83fb872ccfe221eeb011fde419e9c585f Mon Sep 17 00:00:00 2001 From: danberx <118466592+danberx@users.noreply.github.com> Date: Sat, 14 Mar 2026 09:41:26 +0000 Subject: [PATCH 4/5] task_02 + tests --- task_02/src/main.cpp | 12 +++++++++++- task_02/src/solution.cpp | 10 ++++++++++ task_02/src/solution.hpp | 3 +++ task_02/src/test.cpp | 20 ++++++++++++++++++-- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 task_02/src/solution.cpp create mode 100644 task_02/src/solution.hpp diff --git a/task_02/src/main.cpp b/task_02/src/main.cpp index 0e4393b..948be03 100644 --- a/task_02/src/main.cpp +++ b/task_02/src/main.cpp @@ -1,3 +1,13 @@ +#include "solution.cpp" #include -int main() { return 0; } +int main() { + int n; + std::cin >> n; + std::vector arr(n); + for (int i = 0; i < n; ++i) { + std::cin >> arr[i]; + } + + std::cout << FindBorder(arr); +} diff --git a/task_02/src/solution.cpp b/task_02/src/solution.cpp new file mode 100644 index 0000000..f23ddc4 --- /dev/null +++ b/task_02/src/solution.cpp @@ -0,0 +1,10 @@ +#include "solution.hpp" + +int FindBorder(std::vector arr) { + for (int i = 0; i < arr.size() - 1; ++i) { + if (!arr[i] && arr[i + 1]) { + return i; + } + } + return -1; +} diff --git a/task_02/src/solution.hpp b/task_02/src/solution.hpp new file mode 100644 index 0000000..11a9b26 --- /dev/null +++ b/task_02/src/solution.hpp @@ -0,0 +1,3 @@ +#include + +int FindBorder(std::vector arr); diff --git a/task_02/src/test.cpp b/task_02/src/test.cpp index ee23770..782f961 100644 --- a/task_02/src/test.cpp +++ b/task_02/src/test.cpp @@ -1,5 +1,21 @@ #include +#include "solution.cpp" -TEST(Test, Simple) { - ASSERT_EQ(1, 1); // placeholder +TEST(FindBorderTest, Simple) { + std::vector a = {0, 0, 0, 1, 1, 1, 1}; + ASSERT_EQ(FindBorder(a), 2); + + std::vector b = {0, 1}; + ASSERT_EQ(FindBorder(b), 0); + + std::vector c = {0, 0, 0, 0, 0, 0, 0, 1}; + ASSERT_EQ(FindBorder(c), 6); + + std::vector d = {0, 1, 1, 1, 1}; + ASSERT_EQ(FindBorder(d), 0); + + std::vector many = {0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1}; + int ans = FindBorder(many); + bool check = ans < many.size() - 1 && !many[ans] && many[ans + 1]; + ASSERT_EQ(check, true); } From dc79ae668acd722622179fe3f647319c6e1b98f5 Mon Sep 17 00:00:00 2001 From: danberx <118466592+danberx@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:13:04 +0000 Subject: [PATCH 5/5] fix task02 + task04 --- task_02/src/main.cpp | 2 +- task_02/src/solution.cpp | 2 +- task_02/src/solution.hpp | 5 ++++ task_02/src/test.cpp | 2 +- task_04/src/min_stack.cpp | 40 +++++++++++++++++++++++++ task_04/src/min_stack.hpp | 17 +++++++++++ task_04/src/stack.cpp | 37 +++++++++++++++-------- task_04/src/stack.hpp | 35 ++++++++-------------- task_04/src/test.cpp | 62 +++++++++++++++++---------------------- 9 files changed, 129 insertions(+), 73 deletions(-) create mode 100644 task_04/src/min_stack.cpp create mode 100644 task_04/src/min_stack.hpp diff --git a/task_02/src/main.cpp b/task_02/src/main.cpp index 948be03..63a2292 100644 --- a/task_02/src/main.cpp +++ b/task_02/src/main.cpp @@ -1,4 +1,4 @@ -#include "solution.cpp" +#include "solution.hpp" #include int main() { diff --git a/task_02/src/solution.cpp b/task_02/src/solution.cpp index f23ddc4..fccd40b 100644 --- a/task_02/src/solution.cpp +++ b/task_02/src/solution.cpp @@ -7,4 +7,4 @@ int FindBorder(std::vector arr) { } } return -1; -} +} \ No newline at end of file diff --git a/task_02/src/solution.hpp b/task_02/src/solution.hpp index 11a9b26..b563544 100644 --- a/task_02/src/solution.hpp +++ b/task_02/src/solution.hpp @@ -1,3 +1,8 @@ +#ifndef SOLUTION_HPP +#define SOLUTION_HPP + #include int FindBorder(std::vector arr); + +#endif \ No newline at end of file diff --git a/task_02/src/test.cpp b/task_02/src/test.cpp index 782f961..60d0337 100644 --- a/task_02/src/test.cpp +++ b/task_02/src/test.cpp @@ -1,5 +1,5 @@ #include -#include "solution.cpp" +#include "solution.hpp" TEST(FindBorderTest, Simple) { std::vector a = {0, 0, 0, 1, 1, 1, 1}; diff --git a/task_04/src/min_stack.cpp b/task_04/src/min_stack.cpp new file mode 100644 index 0000000..8eda7e0 --- /dev/null +++ b/task_04/src/min_stack.cpp @@ -0,0 +1,40 @@ +#include "min_stack.hpp" + +MinStack::MinStack() { + head = nullptr; +} + +void MinStack::Push(int value) { + MinNode *node = new MinNode(); + node->value = value; + node->min = std::min(value, GetMin()); + node->prev = head; + head = node; +} + +int MinStack::Pop() { + if (!head) { + return -1; + } + int value = head->value; + MinNode *temp = head->prev; + delete head; + head = temp; + return value; +} + +int MinStack::GetMin() { + if (!head) { + return 1e9; + } + return head->min; +} + +MinStack::~MinStack() { + MinNode* tmp = head; + while (tmp) { + MinNode* pr = tmp->prev; + delete tmp; + tmp = pr; + } +} \ No newline at end of file diff --git a/task_04/src/min_stack.hpp b/task_04/src/min_stack.hpp new file mode 100644 index 0000000..9cee587 --- /dev/null +++ b/task_04/src/min_stack.hpp @@ -0,0 +1,17 @@ +#include + +class MinStack { +public: + void Push(int value); + int Pop(); + int GetMin(); + MinStack(); + ~MinStack(); +private: + struct MinNode { + int value; + int min; + MinNode *prev; + }; + MinNode *head; +}; \ No newline at end of file diff --git a/task_04/src/stack.cpp b/task_04/src/stack.cpp index 8ca8990..f659216 100644 --- a/task_04/src/stack.cpp +++ b/task_04/src/stack.cpp @@ -1,21 +1,32 @@ #include "stack.hpp" -#include +Stack::Stack() { + head = nullptr; +} -void Stack::Push(int value) { data_.push(value); } +void Stack::Push(int value) { + Node *node = new Node(); + node->value = value; + node->prev = head; + head = node; +} int Stack::Pop() { - auto result = data_.top(); - data_.pop(); - return result; + if (!head) { + return -1; + } + int value = head->value; + Node *temp = head->prev; + delete head; + head = temp; + return value; } -void MinStack::Push(int value) { data_.push_back(value); } - -int MinStack::Pop() { - auto result = data_.back(); - data_.pop_back(); - return result; +Stack::~Stack() { + Node* tmp = head; + while (tmp) { + Node* pr = tmp->prev; + delete tmp; + tmp = pr; + } } - -int MinStack::GetMin() { return *std::min_element(data_.begin(), data_.end()); } \ No newline at end of file diff --git a/task_04/src/stack.hpp b/task_04/src/stack.hpp index 138ec40..0229b41 100644 --- a/task_04/src/stack.hpp +++ b/task_04/src/stack.hpp @@ -1,23 +1,14 @@ -#pragma once - -#include -#include - class Stack { - public: - void Push(int value); - int Pop(); - - private: - std::stack data_; -}; - -class MinStack { - public: - void Push(int value); - int Pop(); - int GetMin(); - - private: - std::vector data_; -}; +public: + void Push(int value); + int Pop(); + Stack(); + ~Stack(); +private: + struct Node { + int value; + int min; + Node *prev; + }; + Node *head; +}; \ No newline at end of file diff --git a/task_04/src/test.cpp b/task_04/src/test.cpp index 54e7ce9..b982990 100644 --- a/task_04/src/test.cpp +++ b/task_04/src/test.cpp @@ -1,42 +1,34 @@ #include - -#include - #include "stack.hpp" +#include "min_stack.hpp" +#include -TEST(StackTest, Simple) { - Stack stack; - stack.Push(1); // Stack [1] - ASSERT_EQ(stack.Pop(), 1); // Stack [] - stack.Push(1); // Stack [1] - stack.Push(2); // Stack [1, 2] - ASSERT_EQ(stack.Pop(), 2); // Stack [1] - ASSERT_EQ(stack.Pop(), 1); // Stack [] - stack.Push(1); // Stack [1] - stack.Push(2); // Stack [1, 2] - ASSERT_EQ(stack.Pop(), 2); // Stack [1] - stack.Push(3); // Stack [1, 3] - ASSERT_EQ(stack.Pop(), 3); // Stack [1] - ASSERT_EQ(stack.Pop(), 1); // Stack [] +TEST(Stack, SimpleStack) { + std::vector arr = {4, 1, 3, 6, 7, 8}; + Stack stack; + for (int i = 0; i < arr.size(); ++i) { + stack.Push(arr[i]); + } + for (int i = arr.size() - 1; i >= 0; --i) { + ASSERT_EQ(arr[i], stack.Pop()); + } + stack.Push(1); + stack.Push(2); + ASSERT_EQ(stack.Pop(), 2); + stack.Push(3); + ASSERT_EQ(stack.Pop(), 3); } -TEST(MinStackTest, Simple) { - MinStack stack; - stack.Push(1); // Stack [1] - ASSERT_EQ(stack.GetMin(), 1); - ASSERT_EQ(stack.Pop(), 1); // Stack [] - stack.Push(1); // Stack [1] - stack.Push(2); // Stack [1, 2] - ASSERT_EQ(stack.GetMin(), 1); - ASSERT_EQ(stack.Pop(), 2); // Stack [1] - ASSERT_EQ(stack.Pop(), 1); // Stack [] - stack.Push(1); // Stack [1] - stack.Push(2); // Stack [1, 2] - ASSERT_EQ(stack.GetMin(), 1); - ASSERT_EQ(stack.Pop(), 2); // Stack [1] - stack.Push(3); // Stack [1, 3] - ASSERT_EQ(stack.GetMin(), 1); - ASSERT_EQ(stack.Pop(), 3); // Stack [1] - ASSERT_EQ(stack.Pop(), 1); // Stack [] +TEST(Stack, SimpleMinStack) { + std::vector arr = {8, 3, 4, 1, 5}; + MinStack stack; + for (int i : arr) { + stack.Push(i); + } + ASSERT_EQ(stack.GetMin(), 1); + ASSERT_EQ(stack.Pop(), 5); + ASSERT_EQ(stack.GetMin(), 1); + ASSERT_EQ(stack.Pop(), 1); + ASSERT_EQ(stack.GetMin(), 3); } \ No newline at end of file