-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* init * style fix * import fix
- Loading branch information
1 parent
77721d7
commit 0b18972
Showing
7 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
12 changes: 12 additions & 0 deletions
12
modules/graph_comp_shem_a/application/graph_components.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2024 Konovalov Igor | ||
|
||
#include <iostream> | ||
|
||
#include "include/graph_components_app.h" | ||
|
||
int main(int argc, char* argv[]) { | ||
auto output = GraphComponentsApplication()(argc, argv); | ||
|
||
std::cout << output << '\n'; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Konovalov Igor | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Konovalov Igor | ||
|
||
#include "include/graph_components_app.h" | ||
|
||
#include <cstring> | ||
#include <sstream> | ||
#include <iostream> | ||
#include <stdexcept> | ||
#include <vector> | ||
|
||
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<std::vector<int>> 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_; | ||
} |