Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

### Для удобства можно пользоваться папкой lib, все файлы из этой папки будут подключаться к любой задаче

### Можно получить дополнительные баллы, если добавить интересные текстовые задачи. Необходимы текст задачи, решение и тесты. Каждая задача отдельный ПР, полчуть дополнительные баллы можно только если пулл реквест замержен в основную ветку.

### Код должен быть отформатирован clang-format'ом со стилем Google
6 changes: 5 additions & 1 deletion sandbox/template/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include <iostream>

int main() { return 0; }
int main () {
int k = 65;
auto sup_k = static_cast <char> (k);
std :: cout << sup_k;
}
2 changes: 1 addition & 1 deletion task_01/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
string(REPLACE " " "_" PROJECT_NAME ${PROJECT_NAME})
project(${PROJECT_NAME} C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp")
Expand Down
Binary file added task_01/src/main
Binary file not shown.
2 changes: 1 addition & 1 deletion task_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <iostream>

int main() { return 0; }
int main() {}
8 changes: 8 additions & 0 deletions task_01/src/mediana.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <algorithm>
#include <vector>

inline int mediana(int first_number, int second_number, int third_number) {
std ::vector<int> nums = {first_number, second_number, third_number};
sort(nums.begin(), nums.end());
return (nums[1]);
}
1 change: 0 additions & 1 deletion task_01/src/sum.hpp

This file was deleted.

11 changes: 8 additions & 3 deletions task_01/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "mediana.hpp"
#include <gtest/gtest.h>

#include <sum.hpp>

TEST(Test, Simple) { ASSERT_EQ(Sum(1, 2, 3), 6); }
TEST(Test, Simple) {
ASSERT_EQ(mediana(1, 2, 3), 2);
ASSERT_EQ(mediana(3, 13, 2), 3);
ASSERT_EQ(mediana(3, 65, 17), 17);
ASSERT_EQ(mediana(-2, 8, -100), -2);
ASSERT_EQ(mediana(-5, -8, -17), -8);
}
Binary file added task_02/src/main
Binary file not shown.
2 changes: 1 addition & 1 deletion task_02/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <iostream>

int main() { return 0; }
int main() {}
19 changes: 19 additions & 0 deletions task_02/src/max_value.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <vector>
#include <string>
#include <algorithm>

struct array_error{
std :: string message {"array error"};
};

inline int max_value(std :: vector <int> arr, int length) {
if (length < 1)
throw array_error {};

int max_val = {arr[0]};
for (auto num:arr) {
max_val = std::max(max_val, num);
}

return max_val;
}
32 changes: 30 additions & 2 deletions task_02/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
#include <gtest/gtest.h>
#include <vector>
#include <max_value.hpp>

TEST(Test, Simple) {
ASSERT_EQ(1, 1); // Stack []
TEST(max_value, normal) {
std::vector <int> a {1,2,3,4};
ASSERT_EQ(max_value(a, 4), 4);
}

TEST(max_value, unsorted) {
std::vector <int> a {5, 16, 7, 48, 3, 13};
ASSERT_EQ(max_value(a, 6), 48);
}

TEST(max_value, bellow_zero) {
std::vector <int> a {-1,-5,-6,-10,-3};
ASSERT_EQ(max_value(a, 5), -1);
}

TEST(max_value, repeated) {
std::vector <int> a {1,2,2,2,2,5,5,5};
ASSERT_EQ(max_value(a, 8), 5);
}

TEST(max_value, error) {
std::vector <int> a {7, 0, -5, 13, 14, -48, 7, 18, 17, 1, -30};
ASSERT_THROW(max_value(a, 0), array_error);
}

TEST(max_value, all) {
std::vector <int> a {7, 0, -5, 13, 14, -48, 7, 18, 17, 1, -30};
ASSERT_EQ(max_value(a, 11), 18);
}
Binary file added task_03/src/main
Binary file not shown.
6 changes: 5 additions & 1 deletion task_03/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
int main() { return 0; }
#include <iostream>


int main() {}

3 changes: 0 additions & 3 deletions task_03/src/reverse.cpp

This file was deleted.

18 changes: 15 additions & 3 deletions task_03/src/reverse.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#pragma once
#include <vector>
#include <string>

#include <cstddef>
struct array_error{
std :: string message {"array errror"};
};

void Reverse(int *array, size_t len);
inline std::vector<int> Reverse (std::vector<int> arr, int length) {
if (length <1)
throw array_error {};

std :: vector <int> rev_arr {};
for (int i{length-1}; i>=0; --i)
rev_arr.push_back (arr[i]);

return rev_arr;
}
28 changes: 26 additions & 2 deletions task_03/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@

#include <gtest/gtest.h>

#include <vector>
#include "reverse.hpp"

TEST(Reverse, Simple) {}
TEST(Reverse, error) {
std :: vector <int> a {};
ASSERT_THROW (Reverse (a, 0), array_error);
}

TEST(Reverse, normal) {
std :: vector <int> a {1,2,3,4};
std :: vector <int> b {4,3,2,1};
a = Reverse (a, a.size());
ASSERT_EQ (a, b);
}

TEST(Reverse, bellow_zero) {
std :: vector <int> a {-5,-3,-10};
std :: vector <int> b {-10,-3,-5};
a = Reverse (a, a.size());
ASSERT_EQ (a, b);
}

TEST(Reverse, repeated) {
std :: vector <int> a {1,1,1,1};
std :: vector <int> b {1,1,1,1};
a = Reverse (a, a.size());
ASSERT_EQ (a, b);
}
4 changes: 3 additions & 1 deletion task_04/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <iostream>

int main() { return 0; }

int main() {}

21 changes: 21 additions & 0 deletions task_04/src/move_array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <vector>
#include <string>

struct array_error{
std :: string message {"array errror"};
};

inline std :: vector <int> move_array (std::vector <int> arr, int length, int N) {
if (length < 1)
throw array_error {};

N = N % length;
std :: vector <int> moved_arr = arr;
for (int i{0}; i<N; ++i) {
auto point = moved_arr.begin();
moved_arr.insert(point, moved_arr[length-1]);
moved_arr.pop_back();
}

return moved_arr;
}
81 changes: 79 additions & 2 deletions task_04/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,83 @@

#include <gtest/gtest.h>
#include <move_array.hpp>

TEST(TopologySort, Simple) {
ASSERT_EQ(1, 1); // Stack []
TEST(task4, normal1) {
std :: vector <int> a {7, 32, 15, 0, 67, 1, 67, 90};
std :: vector <int> b {15, 0, 67, 1, 67, 90, 7, 32};
a = move_array(a, a.size(), 6);
ASSERT_EQ(a, b);
}

TEST(task4, cycle1) {
std :: vector <int> a {7, 32, 15, 0, 67, 1, 67, 90};
std :: vector <int> b {15, 0, 67, 1, 67, 90, 7, 32};
a = move_array(a, a.size(), 6);
ASSERT_EQ(a, b);
}

TEST(task4, cycle2) {
std :: vector <int> a {7, 32, 15, 0, 67, 1, 67, 90};
std :: vector <int> b {15, 0, 67, 1, 67, 90, 7, 32};
a = move_array(a, a.size(), 6);
ASSERT_EQ(a, b);
}

TEST(task4, error) {
std :: vector <int> a {0,1,2,3,4,5,6,7};
ASSERT_THROW (move_array(a, 0, 13), array_error);
}

TEST(task4, normal2) {
std :: vector <int> a {5, 19, 4, 72, 85, 1, 4, 6};
std :: vector <int> b {1, 4, 6, 5, 19, 4, 72, 85};
a = move_array(a, a.size(), 11);
ASSERT_EQ(a, b);
}

TEST(task4, bellow_zero) {
std :: vector <int> a {-1,3,5,10,-8};
std :: vector <int> b {10,-8,-1, 3,5};
a = move_array(a, a.size(), 2);
ASSERT_EQ(a, b);
}

TEST(task4, big_test1) {
std :: vector <int> a {};
for (int i{0}; i<100; ++i)
a.push_back(11);
std :: vector <int> b = move_array(a, a.size(), 1);
ASSERT_EQ(b, a);
}

TEST(task4, big_test2) {
std :: vector <int> a {};
for (int i{0}; i<10000; ++i)
a.push_back(11);
std :: vector <int> b = move_array(a, a.size(), 100);
ASSERT_EQ(b, a);
}

TEST(task4, big_test3) {
std :: vector <int> a {};
for (int i{0}; i<1000000; ++i)
a.push_back(11);
std :: vector <int> b = move_array(a, a.size(), 1000);
ASSERT_EQ(b, a);
}

TEST(task4, big_test4) {
std :: vector <int> a {};
for (int i{0}; i<10000000; ++i)
a.push_back(11);
std :: vector <int> b = move_array(a, a.size(), 10000000);
ASSERT_EQ(b, a);
}

TEST(task4, big_test_final) {
std :: vector <int> a {};
for (int i{0}; i<100000000; ++i)
a.push_back(11);
std :: vector <int> b = move_array(a, a.size(), 1000000000);
ASSERT_EQ(b, a);
}