From 07009430427ee1afbdcc4a66af88e81ed452e2bd Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Wed, 27 Nov 2024 07:21:54 +0000 Subject: [PATCH 1/8] Mediana code --- task_01/src/main.cpp | 14 +++++++++++++- task_01/src/mediana.cpp | 23 +++++++++++++++++++++++ task_01/src/mediana.hpp | 1 + task_01/src/sum.hpp | 1 - task_01/src/test.cpp | 13 +++++++++++-- 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 task_01/src/mediana.cpp create mode 100644 task_01/src/mediana.hpp delete mode 100644 task_01/src/sum.hpp diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 0e4393b..0ff86f9 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,3 +1,15 @@ +#include "mediana.hpp" + #include -int main() { return 0; } +int main() +try +{ + setlocale(LC_ALL, "RU"); + + return 0; +} +catch(const std::exception& e) +{ + std::cerr << e.what() << '\n'; +} diff --git a/task_01/src/mediana.cpp b/task_01/src/mediana.cpp new file mode 100644 index 0000000..3634074 --- /dev/null +++ b/task_01/src/mediana.cpp @@ -0,0 +1,23 @@ +#include "mediana.hpp" +#include + +int mediana(int a, int b, int c) { + int m{-999999999}; + int n{999999999}; + + std::vector vec {a, b, c}; + for (int i=0; i<3; i++) + { + if (vec[i]>m) + m=vec[i]; + } + + for (int i=0; i<3; i++) + { + if (vec[i] -#include +#include "mediana.hpp" + +TEST(Mediana, Simple1) { EXPECT_EQ(mediana(1, 2, 3), 2); } +TEST(Mediana, Simple2) { EXPECT_EQ(mediana(-1, 2, 3), 2); } +TEST(Mediana, Simple3) { EXPECT_EQ(mediana(123, 22, 32345), 123); } +TEST(Mediana, Simple4) { EXPECT_EQ(mediana(1, 3, 3), 3); } +TEST(Mediana, Simple5) { ASSERT_EQ(mediana(1, 2, 3), 2); } +TEST(Mediana, Simple6) { ASSERT_EQ(mediana(1, 1, 1), 1); } +TEST(Mediana, Simple7) { ASSERT_EQ(mediana(-10, 0, 10), 0); } +TEST(Mediana, Simple8) { ASSERT_EQ(mediana(-3, -2, -1), -2); } +TEST(Mediana, Simple9) { ASSERT_EQ(mediana(2, 2, 3), 2); } -TEST(Test, Simple) { ASSERT_EQ(Sum(1, 2, 3), 6); } \ No newline at end of file From fe805b224268ab7b1b176065340cc727253039e3 Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Wed, 27 Nov 2024 08:07:24 +0000 Subject: [PATCH 2/8] Finding max element in array --- task_02/src/main.cpp | 13 ++++++++++++- task_02/src/max_element.cpp | 12 ++++++++++++ task_02/src/max_element.hpp | 1 + task_02/src/test.cpp | 4 +--- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 task_02/src/max_element.cpp create mode 100644 task_02/src/max_element.hpp diff --git a/task_02/src/main.cpp b/task_02/src/main.cpp index 0e4393b..97a08b9 100644 --- a/task_02/src/main.cpp +++ b/task_02/src/main.cpp @@ -1,3 +1,14 @@ #include +#include "max_element.hpp" -int main() { return 0; } +int main() +try +{ + setlocale(LC_ALL, "RU"); + + return 0; +} +catch(const std::exception& e) +{ + std::cerr << e.what() << '\n'; +} \ No newline at end of file diff --git a/task_02/src/max_element.cpp b/task_02/src/max_element.cpp new file mode 100644 index 0000000..d1563be --- /dev/null +++ b/task_02/src/max_element.cpp @@ -0,0 +1,12 @@ +#include "max_element.hpp" + +int get_max_element(int* array, int size) +{ + int max_element = array[0]; + for (int i{ 0 }; i < size; i++) + { + if (max_element < array[i]) + max_element = array[i]; + } + return max_element; +}; \ No newline at end of file diff --git a/task_02/src/max_element.hpp b/task_02/src/max_element.hpp new file mode 100644 index 0000000..65475c8 --- /dev/null +++ b/task_02/src/max_element.hpp @@ -0,0 +1 @@ +int get_max_element(int* arr[] , int len); \ No newline at end of file diff --git a/task_02/src/test.cpp b/task_02/src/test.cpp index 87cef73..a950c43 100644 --- a/task_02/src/test.cpp +++ b/task_02/src/test.cpp @@ -1,5 +1,3 @@ #include +#include "max_element.hpp" -TEST(Test, Simple) { - ASSERT_EQ(1, 1); // Stack [] -} \ No newline at end of file From 16772cd1385354ac5ee3dc8657eec1337efe700d Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Wed, 27 Nov 2024 08:28:40 +0000 Subject: [PATCH 3/8] Reverse_funk --- task_03/src/main.cpp | 25 ++++++++++++++++++++++++- task_03/src/reverse.cpp | 8 +++++++- task_03/src/reverse.hpp | 3 +-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/task_03/src/main.cpp b/task_03/src/main.cpp index 76e8197..2046048 100644 --- a/task_03/src/main.cpp +++ b/task_03/src/main.cpp @@ -1 +1,24 @@ -int main() { return 0; } +#include "reverse.hpp" +#include + +int main() +try +{ + setlocale(LC_ALL, "RU"); + + int array[4]{ 1, 2, 3, 4 }; + int len = 4; + + Reverse(array, len); + + std::cout << "Инвертированный массив:" << std::endl; + + for (int i{ 0 }; i < len; i++) + std::cout << array[i] << " "; + + return 0; +} +catch(const std::exception& e) +{ + std::cerr << e.what() << '\n'; +} diff --git a/task_03/src/reverse.cpp b/task_03/src/reverse.cpp index 3457424..f717dcc 100644 --- a/task_03/src/reverse.cpp +++ b/task_03/src/reverse.cpp @@ -1,3 +1,9 @@ #include "reverse.hpp" +#include -void Reverse(int *array, size_t len) {} \ No newline at end of file + +void Reverse(int* array, size_t len) +{ + for (int i{ 0 }; i < len / 2; i++) + std::swap(array[i], array[(len -i - 1)]); +} \ No newline at end of file diff --git a/task_03/src/reverse.hpp b/task_03/src/reverse.hpp index 450a729..47be137 100644 --- a/task_03/src/reverse.hpp +++ b/task_03/src/reverse.hpp @@ -1,5 +1,4 @@ #pragma once - #include -void Reverse(int *array, size_t len); +void Reverse(int* array, size_t len); From d9c7d6b4b76388cefeb0c4ca3efcd318781a348a Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Sat, 30 Nov 2024 18:14:20 +0000 Subject: [PATCH 4/8] NOT_Completed_rotate_func --- task_04/src/main.cpp | 23 ++++++++++++++++++++++- task_04/src/rotate.cpp | 19 +++++++++++++++++++ task_04/src/rotate.hpp | 1 + task_04/src/test.cpp | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 task_04/src/rotate.cpp create mode 100644 task_04/src/rotate.hpp diff --git a/task_04/src/main.cpp b/task_04/src/main.cpp index 0e4393b..0905584 100644 --- a/task_04/src/main.cpp +++ b/task_04/src/main.cpp @@ -1,3 +1,24 @@ #include +#include "rotate.hpp" +int main() +try +{ + setlocale(LC_ALL, "RU"); -int main() { return 0; } + int array[5]{ 1, 2, 3, 4, 5}; + int len = 5; + int N = 2; + + rotate(array, len, N); + + std::cout << "Сдвинутый массив:" << std::endl; + + for (int i{ 0 }; i < len; i++) + std::cout << array[i] << " "; + + return 0; +} +catch(const std::exception& e) +{ + std::cerr << e.what() << '\n'; +} diff --git a/task_04/src/rotate.cpp b/task_04/src/rotate.cpp new file mode 100644 index 0000000..9c7b2fa --- /dev/null +++ b/task_04/src/rotate.cpp @@ -0,0 +1,19 @@ +#include "rotate.hpp" + +void rotate(int* array, int len, int N) +{ + int* new_arr = new int[len]; + + for {int i{0}; i < len; i++} + { + if (len == N) + new_arr[i] = array[i] + + if (len < N) + new_arr[] + } + + + + +} \ No newline at end of file diff --git a/task_04/src/rotate.hpp b/task_04/src/rotate.hpp new file mode 100644 index 0000000..8a8a09a --- /dev/null +++ b/task_04/src/rotate.hpp @@ -0,0 +1 @@ +void rotate(int* arr, len, N); \ No newline at end of file diff --git a/task_04/src/test.cpp b/task_04/src/test.cpp index 5e11617..2f6134b 100644 --- a/task_04/src/test.cpp +++ b/task_04/src/test.cpp @@ -1,4 +1,4 @@ - +#include "rotate.hpp" #include TEST(TopologySort, Simple) { From 62366c201e2a7b058eee04d0515dcecb730c4e10 Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Sun, 1 Dec 2024 06:01:13 +0000 Subject: [PATCH 5/8] Completed shift func --- task_04/src/main.cpp | 7 ++++--- task_04/src/rotate.cpp | 19 ------------------- task_04/src/rotate.hpp | 1 - task_04/src/shift.cpp | 16 ++++++++++++++++ task_04/src/shift.hpp | 3 +++ 5 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 task_04/src/rotate.cpp delete mode 100644 task_04/src/rotate.hpp create mode 100644 task_04/src/shift.cpp create mode 100644 task_04/src/shift.hpp diff --git a/task_04/src/main.cpp b/task_04/src/main.cpp index 0905584..0453044 100644 --- a/task_04/src/main.cpp +++ b/task_04/src/main.cpp @@ -1,13 +1,14 @@ #include -#include "rotate.hpp" +#include "shift.hpp" + int main() try { setlocale(LC_ALL, "RU"); int array[5]{ 1, 2, 3, 4, 5}; - int len = 5; - int N = 2; + size_t len = 5; + unsigned int N = 2; rotate(array, len, N); diff --git a/task_04/src/rotate.cpp b/task_04/src/rotate.cpp deleted file mode 100644 index 9c7b2fa..0000000 --- a/task_04/src/rotate.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "rotate.hpp" - -void rotate(int* array, int len, int N) -{ - int* new_arr = new int[len]; - - for {int i{0}; i < len; i++} - { - if (len == N) - new_arr[i] = array[i] - - if (len < N) - new_arr[] - } - - - - -} \ No newline at end of file diff --git a/task_04/src/rotate.hpp b/task_04/src/rotate.hpp deleted file mode 100644 index 8a8a09a..0000000 --- a/task_04/src/rotate.hpp +++ /dev/null @@ -1 +0,0 @@ -void rotate(int* arr, len, N); \ No newline at end of file diff --git a/task_04/src/shift.cpp b/task_04/src/shift.cpp new file mode 100644 index 0000000..7141924 --- /dev/null +++ b/task_04/src/shift.cpp @@ -0,0 +1,16 @@ +#include "shift.hpp" + +void rotate(int* array, size_t& len, unsigned int& N) +{ + int* new_arr = new int[len]; + + for (int i{0}; i < len; i++) + new_arr[i] = array[(i+N)%len]; + + for (int i{0}; i < len; i++) + array[i] = new_arr[i]; + + delete [] new_arr; + + +} \ No newline at end of file diff --git a/task_04/src/shift.hpp b/task_04/src/shift.hpp new file mode 100644 index 0000000..30f85db --- /dev/null +++ b/task_04/src/shift.hpp @@ -0,0 +1,3 @@ +#include + +void rotate(int* array, size_t& len, unsigned int& N); \ No newline at end of file From 89b60328cc01aeef011fbf6c4ed23543bcf0c993 Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Fri, 13 Dec 2024 21:46:37 +0000 Subject: [PATCH 6/8] Fixed problems in the 2nd task --- task_02/src/main.cpp | 5 ++++- task_02/src/max_element.cpp | 22 +++++++++++----------- task_02/src/max_element.hpp | 11 ++++++++++- task_02/src/test.cpp | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/task_02/src/main.cpp b/task_02/src/main.cpp index 97a08b9..42090cf 100644 --- a/task_02/src/main.cpp +++ b/task_02/src/main.cpp @@ -5,7 +5,10 @@ int main() try { setlocale(LC_ALL, "RU"); - + int array[] = {1, 3, 5, 7, 9}; + int size = sizeof(array) / sizeof(array[0]); + int res = get_max_element(array, size); + std::cout << res; return 0; } catch(const std::exception& e) diff --git a/task_02/src/max_element.cpp b/task_02/src/max_element.cpp index d1563be..e211427 100644 --- a/task_02/src/max_element.cpp +++ b/task_02/src/max_element.cpp @@ -1,12 +1,12 @@ -#include "max_element.hpp" +// #include "max_element.hpp" -int get_max_element(int* array, int size) -{ - int max_element = array[0]; - for (int i{ 0 }; i < size; i++) - { - if (max_element < array[i]) - max_element = array[i]; - } - return max_element; -}; \ No newline at end of file +// int get_max_element(int* array, int size) +// { +// int max_element = array[0]; +// for (int i{ 0 }; i < size; i++) +// { +// if (max_element < array[i]) +// max_element = array[i]; +// } +// return max_element; +// }; \ No newline at end of file diff --git a/task_02/src/max_element.hpp b/task_02/src/max_element.hpp index 65475c8..f5f91a3 100644 --- a/task_02/src/max_element.hpp +++ b/task_02/src/max_element.hpp @@ -1 +1,10 @@ -int get_max_element(int* arr[] , int len); \ No newline at end of file +int get_max_element(int* array, int size) +{ + int max_element = array[0]; + for (int i{ 0 }; i < size; i++) + { + if (max_element < array[i]) + max_element = array[i]; + } + return max_element; +}; \ No newline at end of file diff --git a/task_02/src/test.cpp b/task_02/src/test.cpp index a950c43..f2d7499 100644 --- a/task_02/src/test.cpp +++ b/task_02/src/test.cpp @@ -1,3 +1,37 @@ #include #include "max_element.hpp" +TEST(MaxElementTests, PositiveArray) +{ + int array[] = {1, 3, 5, 7, 9}; + int size = sizeof(array) / sizeof(array[0]); + EXPECT_EQ(get_max_element(array, size), 9); +} + +TEST(MaxElementTests, NegativeArray) +{ + int array[] = {-1, -3, -5, -7, -9}; + int size = sizeof(array) / sizeof(array[0]); + EXPECT_EQ(get_max_element(array, size), -1); +} + +TEST(MaxElementTests, MixedArray) +{ + int array[] = {-1, 2, -3, 4, -5}; + int size = sizeof(array) / sizeof(array[0]); + EXPECT_EQ(get_max_element(array, size), 4); +} + +TEST(MaxElementTests, SingleElementArray) +{ + int array[] = {42}; + int size = sizeof(array) / sizeof(array[0]); + EXPECT_EQ(get_max_element(array, size), 42); +} + +TEST(MaxElementTests, SameElementArray) +{ + int array[] = {5, 5, 5, 5, 5}; + int size = sizeof(array) / sizeof(array[0]); + EXPECT_EQ(get_max_element(array, size), 5); +} From 536536d78c35e70dc76135ebf5324205f8659111 Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Fri, 13 Dec 2024 21:56:45 +0000 Subject: [PATCH 7/8] Completed the 3rd task --- task_03/src/reverse.cpp | 14 ++++---- task_03/src/reverse.hpp | 7 +++- task_03/src/test.cpp | 77 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 11 deletions(-) diff --git a/task_03/src/reverse.cpp b/task_03/src/reverse.cpp index f717dcc..74ab0d1 100644 --- a/task_03/src/reverse.cpp +++ b/task_03/src/reverse.cpp @@ -1,9 +1,9 @@ -#include "reverse.hpp" -#include +// #include "reverse.hpp" +// #include -void Reverse(int* array, size_t len) -{ - for (int i{ 0 }; i < len / 2; i++) - std::swap(array[i], array[(len -i - 1)]); -} \ No newline at end of file +// void Reverse(int* array, size_t len) +// { +// for (int i{ 0 }; i < len / 2; i++) +// std::swap(array[i], array[(len -i - 1)]); +// } \ No newline at end of file diff --git a/task_03/src/reverse.hpp b/task_03/src/reverse.hpp index 47be137..bd82fc9 100644 --- a/task_03/src/reverse.hpp +++ b/task_03/src/reverse.hpp @@ -1,4 +1,9 @@ #pragma once #include +#include -void Reverse(int* array, size_t len); +void Reverse(int* array, size_t len) +{ + for (int i{ 0 }; i < len / 2; i++) + std::swap(array[i], array[(len -i - 1)]); +} diff --git a/task_03/src/test.cpp b/task_03/src/test.cpp index 2d868db..1f336d8 100644 --- a/task_03/src/test.cpp +++ b/task_03/src/test.cpp @@ -1,6 +1,77 @@ - #include - #include "reverse.hpp" -TEST(Reverse, Simple) {} +TEST(ReverseTests, SimpleArray) +{ + int array[] = {1, 2, 3, 4, 5}; + size_t len = sizeof(array) / sizeof(array[0]); + + Reverse(array, len); + + EXPECT_EQ(array[0], 5); + EXPECT_EQ(array[1], 4); + EXPECT_EQ(array[2], 3); + EXPECT_EQ(array[3], 2); + EXPECT_EQ(array[4], 1); +} + +TEST(ReverseTests, EmptyArray) +{ + int array[] = {}; + size_t len = sizeof(array) / sizeof(array[0]); + + Reverse(array, len); + + EXPECT_EQ(len, 0); +} + +TEST(ReverseTests, SingleElementArray) +{ + int array[] = {42}; + size_t len = sizeof(array) / sizeof(array[0]); + + Reverse(array, len); + + EXPECT_EQ(array[0], 42); +} + +TEST(ReverseTests, EvenLengthArray) +{ + int array[] = {1, 2, 3, 4}; + size_t len = sizeof(array) / sizeof(array[0]); + + Reverse(array, len); + + EXPECT_EQ(array[0], 4); + EXPECT_EQ(array[1], 3); + EXPECT_EQ(array[2], 2); + EXPECT_EQ(array[3], 1); +} + +TEST(ReverseTests, SameElementArray) +{ + int array[] = {5, 5, 5, 5, 5}; + size_t len = sizeof(array) / sizeof(array[0]); + + Reverse(array, len); + + EXPECT_EQ(array[0], 5); + EXPECT_EQ(array[1], 5); + EXPECT_EQ(array[2], 5); + EXPECT_EQ(array[3], 5); + EXPECT_EQ(array[4], 5); +} + +TEST(ReverseTests, NegativeArray) +{ + int array[] = {-1, -2, -3, -4, -5}; + size_t len = sizeof(array) / sizeof(array[0]); + + Reverse(array, len); + + EXPECT_EQ(array[0], -5); + EXPECT_EQ(array[1], -4); + EXPECT_EQ(array[2], -3); + EXPECT_EQ(array[3], -2); + EXPECT_EQ(array[4], -1); +} From b1a402116881e1100d91554a84c920c5883c9ea6 Mon Sep 17 00:00:00 2001 From: Pavel-bur-dot Date: Fri, 13 Dec 2024 22:09:18 +0000 Subject: [PATCH 8/8] Completed 4th task --- task_02/src/max_element.cpp | 12 ----- task_03/src/reverse.cpp | 9 ---- task_04/src/main.cpp | 2 +- task_04/src/shift.cpp | 16 ------- task_04/src/shift.hpp | 18 +++++++- task_04/src/test.cpp | 88 +++++++++++++++++++++++++++++++++++-- 6 files changed, 103 insertions(+), 42 deletions(-) diff --git a/task_02/src/max_element.cpp b/task_02/src/max_element.cpp index e211427..e69de29 100644 --- a/task_02/src/max_element.cpp +++ b/task_02/src/max_element.cpp @@ -1,12 +0,0 @@ -// #include "max_element.hpp" - -// int get_max_element(int* array, int size) -// { -// int max_element = array[0]; -// for (int i{ 0 }; i < size; i++) -// { -// if (max_element < array[i]) -// max_element = array[i]; -// } -// return max_element; -// }; \ No newline at end of file diff --git a/task_03/src/reverse.cpp b/task_03/src/reverse.cpp index 74ab0d1..e69de29 100644 --- a/task_03/src/reverse.cpp +++ b/task_03/src/reverse.cpp @@ -1,9 +0,0 @@ -// #include "reverse.hpp" -// #include - - -// void Reverse(int* array, size_t len) -// { -// for (int i{ 0 }; i < len / 2; i++) -// std::swap(array[i], array[(len -i - 1)]); -// } \ No newline at end of file diff --git a/task_04/src/main.cpp b/task_04/src/main.cpp index 0453044..c87c81d 100644 --- a/task_04/src/main.cpp +++ b/task_04/src/main.cpp @@ -10,7 +10,7 @@ try size_t len = 5; unsigned int N = 2; - rotate(array, len, N); + shift(array, len, N); std::cout << "Сдвинутый массив:" << std::endl; diff --git a/task_04/src/shift.cpp b/task_04/src/shift.cpp index 7141924..e69de29 100644 --- a/task_04/src/shift.cpp +++ b/task_04/src/shift.cpp @@ -1,16 +0,0 @@ -#include "shift.hpp" - -void rotate(int* array, size_t& len, unsigned int& N) -{ - int* new_arr = new int[len]; - - for (int i{0}; i < len; i++) - new_arr[i] = array[(i+N)%len]; - - for (int i{0}; i < len; i++) - array[i] = new_arr[i]; - - delete [] new_arr; - - -} \ No newline at end of file diff --git a/task_04/src/shift.hpp b/task_04/src/shift.hpp index 30f85db..756c347 100644 --- a/task_04/src/shift.hpp +++ b/task_04/src/shift.hpp @@ -1,3 +1,19 @@ #include -void rotate(int* array, size_t& len, unsigned int& N); \ No newline at end of file +void shift(int* array, size_t& len, unsigned int& N) +{ + if (len == 0) return; + + N = N % len; + if (N == 0) return; + + for (size_t i = 0; i < N; ++i) + { + int temp = array[len - 1]; + for (size_t j = len - 1; j > 0; --j) + { + array[j] = array[j - 1]; + } + array[0] = temp; + } +} diff --git a/task_04/src/test.cpp b/task_04/src/test.cpp index 2f6134b..814f98b 100644 --- a/task_04/src/test.cpp +++ b/task_04/src/test.cpp @@ -1,6 +1,88 @@ -#include "rotate.hpp" +#include "shift.hpp" #include -TEST(TopologySort, Simple) { - ASSERT_EQ(1, 1); // Stack [] +// Тестовый случай для обычного массива с N < len +TEST(ShiftTests, NormalShift) +{ + int array[] = {1, 2, 3, 4, 5}; + size_t len = sizeof(array) / sizeof(array[0]); + unsigned int N = 2; + + shift(array, len, N); + + EXPECT_EQ(array[0], 4); + EXPECT_EQ(array[1], 5); + EXPECT_EQ(array[2], 1); + EXPECT_EQ(array[3], 2); + EXPECT_EQ(array[4], 3); +} + +// Тестовый случай для сдвига на 0 +TEST(ShiftTests, ZeroShift) +{ + int array[] = {1, 2, 3, 4, 5}; + size_t len = sizeof(array) / sizeof(array[0]); + unsigned int N = 0; + + shift(array, len, N); + + EXPECT_EQ(array[0], 1); + EXPECT_EQ(array[1], 2); + EXPECT_EQ(array[2], 3); + EXPECT_EQ(array[3], 4); + EXPECT_EQ(array[4], 5); +} + +// Тестовый случай для сдвига на длину массива +TEST(ShiftTests, LengthShift) +{ + int array[] = {1, 2, 3, 4, 5}; + size_t len = sizeof(array) / sizeof(array[0]); + unsigned int N = len; // Сдвиг на длину массива + + shift(array, len, N); + + EXPECT_EQ(array[0], 1); + EXPECT_EQ(array[1], 2); + EXPECT_EQ(array[2], 3); + EXPECT_EQ(array[3], 4); + EXPECT_EQ(array[4], 5); } + +// Тестовый случай для сдвига больше длины массива +TEST(ShiftTests, LargeShift) +{ + int array[] = {1, 2, 3, 4, 5}; + size_t len = sizeof(array) / sizeof(array[0]); + unsigned int N = 7; // Сдвиг больше длины массива + + shift(array, len, N); + + EXPECT_EQ(array[0], 4); + EXPECT_EQ(array[1], 5); + EXPECT_EQ(array[2], 1); + EXPECT_EQ(array[3], 2); + EXPECT_EQ(array[4], 3); +} + +// Тестовый случай для пустого массива +TEST(ShiftTests, EmptyArray) +{ + int array[] = {}; + size_t len = sizeof(array) / sizeof(array[0]); + unsigned int N = 2; + + shift(array, len, N); + + EXPECT_EQ(len, 0); // Допускаем, что пустой массив остается пустым +} + +// Тестовый случай для массива с одним элементом +TEST(ShiftTests, SingleElementArray) +{ + int array[] = {42}; + size_t len = sizeof(array) / sizeof(array[0]); + unsigned int N = 3; + + shift(array, len, N); +} \ No newline at end of file