From 0b1897257cb3931ccdf5a0afba024f0bf04c6ce1 Mon Sep 17 00:00:00 2001 From: IgorKonovalovAleks <43146597+IgorKonovalovAleks@users.noreply.github.com> Date: Sat, 8 Jun 2024 21:18:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20-=20=D0=9B?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20#3=20(#383)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * init * style fix * import fix --- modules/graph_comp_shem_a/CMakeLists.txt | 3 + modules/graph_comp_shem_a/CTestTests.txt | 69 +++++++++++++++++++ .../application/CMakeLists.txt | 15 ++++ .../application/graph_components.cpp | 12 ++++ .../include/graph_components_app.h | 20 ++++++ .../src/graph_components.cpp | 1 + .../src/graph_components_app.cpp | 48 +++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 modules/graph_comp_shem_a/CTestTests.txt create mode 100644 modules/graph_comp_shem_a/application/CMakeLists.txt create mode 100644 modules/graph_comp_shem_a/application/graph_components.cpp create mode 100644 modules/graph_comp_shem_a/include/graph_components_app.h create mode 100644 modules/graph_comp_shem_a/src/graph_components_app.cpp diff --git a/modules/graph_comp_shem_a/CMakeLists.txt b/modules/graph_comp_shem_a/CMakeLists.txt index 6bd24443b..5c277256f 100644 --- a/modules/graph_comp_shem_a/CMakeLists.txt +++ b/modules/graph_comp_shem_a/CMakeLists.txt @@ -3,6 +3,7 @@ get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) set(MODULE "${DIR_NAME}") set(LIBRARY "lib_${MODULE}") set(TESTS "test_${MODULE}") +set(APPLICATION "app_${MODULE}") # Include directory with public headers include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -10,8 +11,10 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # Add all submodules add_subdirectory(src) add_subdirectory(test) +add_subdirectory(application) ############################################# ##### Testing ############################################# +include("CTestTests.txt") diff --git a/modules/graph_comp_shem_a/CTestTests.txt b/modules/graph_comp_shem_a/CTestTests.txt new file mode 100644 index 000000000..349ec553e --- /dev/null +++ b/modules/graph_comp_shem_a/CTestTests.txt @@ -0,0 +1,69 @@ +############################################# +##### Testing +############################################# + +set(prefix "${MODULE}") + +add_test( + NAME ${prefix}_run + COMMAND ${APPLICATION} +) +set_tests_properties (${prefix}_run PROPERTIES + LABELS "${MODULE}") + +add_test( + NAME ${prefix}_thelp + COMMAND ${APPLICATION} --help +) +set_tests_properties (${prefix}_thelp PROPERTIES + PASS_REGULAR_EXPRESSION "This program calculates number of graph components" + LABELS "${MODULE}") + +add_test( + NAME ${prefix}_test_one + COMMAND ${APPLICATION} 2 1 0 +) +set_tests_properties (${prefix}_test_one PROPERTIES + PASS_REGULAR_EXPRESSION "1" + LABELS "${MODULE}") + +add_test( + NAME ${prefix}_test_two + COMMAND ${APPLICATION} 5 1 0,2 1 4 3 +) +set_tests_properties (${prefix}_test_two PROPERTIES + PASS_REGULAR_EXPRESSION "2" + LABELS "${MODULE}") + +add_test( + NAME ${prefix}_test_three + COMMAND ${APPLICATION} 1 +) +set_tests_properties (${prefix}_test_three PROPERTIES + PASS_REGULAR_EXPRESSION "1" + LABELS "${MODULE}") + + +add_test( + NAME ${prefix}_test_one_naive + COMMAND ${APPLICATION} 8 1,7 0,6 3 2,4 3 1,7 0,6 +) +set_tests_properties (${prefix}_test_one_naive PROPERTIES + PASS_REGULAR_EXPRESSION "3" + LABELS "${MODULE}") + +add_test( + NAME ${prefix}_test_two_naive + COMMAND ${APPLICATION} 10 1 0,2 3,1 4,2 5,3 6,4 7,5 8,6 9,7 8 +) +set_tests_properties (${prefix}_test_two_naive PROPERTIES + PASS_REGULAR_EXPRESSION "1" + LABELS "${MODULE}") + +add_test( + NAME ${prefix}_test_three_naive + COMMAND ${APPLICATION} 0 +) +set_tests_properties (${prefix}_test_three_naive PROPERTIES + PASS_REGULAR_EXPRESSION "0" + LABELS "${MODULE}") \ No newline at end of file diff --git a/modules/graph_comp_shem_a/application/CMakeLists.txt b/modules/graph_comp_shem_a/application/CMakeLists.txt new file mode 100644 index 000000000..e8a53c3d7 --- /dev/null +++ b/modules/graph_comp_shem_a/application/CMakeLists.txt @@ -0,0 +1,15 @@ +set(target ${APPLICATION}) + +file(GLOB srcs "*.cpp") +set_source_files_properties(${srcs} PROPERTIES + LABELS "${MODULE};Application") + +add_executable(${target} ${srcs}) +set_target_properties(${target} PROPERTIES + OUTPUT_NAME ${MODULE} + LABELS "${MODULE};Application") + +target_link_libraries(${target} ${LIBRARY}) +if (UNIX) + target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT}) +endif (UNIX) diff --git a/modules/graph_comp_shem_a/application/graph_components.cpp b/modules/graph_comp_shem_a/application/graph_components.cpp new file mode 100644 index 000000000..5051ab861 --- /dev/null +++ b/modules/graph_comp_shem_a/application/graph_components.cpp @@ -0,0 +1,12 @@ +// Copyright 2024 Konovalov Igor + +#include + +#include "include/graph_components_app.h" + +int main(int argc, char* argv[]) { + auto output = GraphComponentsApplication()(argc, argv); + + std::cout << output << '\n'; + return 0; +} diff --git a/modules/graph_comp_shem_a/include/graph_components_app.h b/modules/graph_comp_shem_a/include/graph_components_app.h new file mode 100644 index 000000000..3a6f9ba64 --- /dev/null +++ b/modules/graph_comp_shem_a/include/graph_components_app.h @@ -0,0 +1,20 @@ +// Copyright 2024 Konovalov Igor + +#pragma once + +#include + +#include "include/graph_components.h" + +class GraphComponentsApplication { + public: + GraphComponentsApplication() = default; + std::string operator()(int argc, char* argv[]); + + private: + int n{}; + int result{}; + std::string message_{}; + bool validate(int argc, char* argv[]); + void help(const char* appName, const char* msg = nullptr); +}; diff --git a/modules/graph_comp_shem_a/src/graph_components.cpp b/modules/graph_comp_shem_a/src/graph_components.cpp index 14b8b3662..a28e7f35b 100644 --- a/modules/graph_comp_shem_a/src/graph_components.cpp +++ b/modules/graph_comp_shem_a/src/graph_components.cpp @@ -3,6 +3,7 @@ #include "include/graph_components.h" #include +#include void DFS(int x, std::vector>& v, std::vector& was) { was[x] = 1; diff --git a/modules/graph_comp_shem_a/src/graph_components_app.cpp b/modules/graph_comp_shem_a/src/graph_components_app.cpp new file mode 100644 index 000000000..37c85acf4 --- /dev/null +++ b/modules/graph_comp_shem_a/src/graph_components_app.cpp @@ -0,0 +1,48 @@ +// Copyright 2024 Konovalov Igor + +#include "include/graph_components_app.h" + +#include +#include +#include +#include +#include + +bool GraphComponentsApplication::validate(int argc, char* argv[]) { + if (argc == 1) { + help(argv[0]); + return false; + } else if (std::strcmp(argv[1], "--help") == 0) { + help(argv[0]); + return false; + } + n = std::stoi(argv[1]); + return true; +} + +void GraphComponentsApplication::help(const char* appName, const char* msg) { + std::stringstream message; + + if (msg) message << "Error: " << msg << '\n'; + + message << "This program calculates number of graph components"; + message_ = message.str(); +} + +std::string GraphComponentsApplication::operator()(int argc, char* argv[]) { + bool b = validate(argc, argv); + std::vector> v(n); + for (int i = 2; i < argc; i++) { + std::istringstream ss; + ss.str(argv[i]); + for (std::string s; std::getline(ss, s, ','); ) { + v[i - 2].push_back(std::stoi(s)); + } + } + if (b) { + std::stringstream str; + str << graph_components_numbers(n, v); + message_ = str.str(); + } + return message_; +}