-
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
* first commit * second commit * third commit * fourth commit * fifth commit * sixth commit * seventh commit * eighth commit * nineth commit * tenth commit * eleventh commit
- Loading branch information
1 parent
cd73e54
commit d94ef15
Showing
7 changed files
with
166 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Declare variables for binaries' names | ||
get_filename_component(DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
set(MODULE "${DIR_NAME}") | ||
set(LIBRARY "lib_${MODULE}") | ||
set(TESTS "test_${MODULE}") | ||
|
||
# Include directory with public headers | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
# Add all submodules | ||
add_subdirectory(src) | ||
add_subdirectory(test) | ||
|
||
############################################# | ||
##### Testing | ||
############################################# | ||
|
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 Shemiakina Alesia | ||
|
||
#ifndef MODULES_GRAPH_COMP_SHEM_A_INCLUDE_GRAPH_COMPONENTS_H_ | ||
#define MODULES_GRAPH_COMP_SHEM_A_INCLUDE_GRAPH_COMPONENTS_H_ | ||
|
||
#include <vector> | ||
|
||
void DFS(int x, std::vector<std::vector<int>>& v, std::vector<int>& was); | ||
int graph_components_numbers(int n, std::vector<std::vector<int>> v); | ||
|
||
|
||
#endif // MODULES_GRAPH_COMP_SHEM_A_INCLUDE_GRAPH_COMPONENTS_H_ |
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,18 @@ | ||
set(target ${LIBRARY}) | ||
|
||
file(GLOB srcs "*.cpp") | ||
file(GLOB hdrs "../include/*.h") | ||
set_source_files_properties(${srcs} ${hdrs} PROPERTIES | ||
LABELS "${MODULE};Library") | ||
|
||
add_library(${target} STATIC ${srcs} ${hdrs}) | ||
set_target_properties(${target} PROPERTIES | ||
OUTPUT_NAME ${MODULE} | ||
LABELS "${MODULE};Library") | ||
|
||
if (UNIX) | ||
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT}) | ||
endif (UNIX) | ||
target_link_libraries(${target} ${LIBRARY_DEPS}) | ||
|
||
set(LIBRARY_DEPS "${LIBRARY_DEPS};${target}" PARENT_SCOPE) |
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,27 @@ | ||
// Copyright 2024 Shemiakina Alesia | ||
|
||
#include "include/graph_components.h" | ||
|
||
#include <vector> | ||
|
||
void DFS(int x, std::vector<std::vector<int>>& v, std::vector<int>& was) { | ||
was[x] = 1; | ||
for (int y : v[x]) | ||
if (was[y] == 0) | ||
DFS(y, v, was); | ||
} | ||
|
||
int graph_components_numbers(int n, std::vector<std::vector<int>> v) { | ||
std::vector<int> was(n); | ||
for (int x = 0; x < n; x++) { | ||
was[x] = 0; | ||
} | ||
int ans = 0; | ||
for (int x = 0; x < n; x++) { | ||
if (was[x] == 0) { | ||
DFS(x, v, was); | ||
ans++; | ||
} | ||
} | ||
return ans; | ||
} |
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,27 @@ | ||
set(target ${TESTS}) | ||
|
||
file(GLOB srcs "*.cpp") | ||
set_source_files_properties(${srcs} PROPERTIES | ||
LABELS "${MODULE};Test") | ||
|
||
add_executable(${target} ${srcs} ${hdrs}) | ||
set_target_properties(${target} PROPERTIES | ||
LABELS "${MODULE};Test") | ||
|
||
if (UNIX) | ||
target_link_libraries(${target} gtest ${CMAKE_THREAD_LIBS_INIT} pthread) | ||
endif (UNIX) | ||
target_link_libraries(${target} gtest ${LIBRARY}) | ||
|
||
# VS2012 doesn't support correctly the tuples yet, | ||
# see http://code.google.com/p/googletest/issues/detail?id=412 | ||
if(MSVC) | ||
target_compile_definitions(${target} PUBLIC _VARIADIC_MAX=10) | ||
endif() | ||
|
||
add_test( | ||
NAME ${MODULE}_gtest | ||
COMMAND ${target} | ||
) | ||
set_tests_properties (${MODULE}_gtest PROPERTIES | ||
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,57 @@ | ||
// Copyright 2024 Shemiakina Alesia | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <tuple> | ||
#include <vector> | ||
#include "include/graph_components.h" | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, returns_1_when_given_2_super) { | ||
std::vector<std::vector<int>> v{{1}, {0}}; | ||
int count = graph_components_numbers(2, v); | ||
EXPECT_EQ(1, count); | ||
} | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, returns_2_when_given_5) { | ||
std::vector<std::vector<int>> v{{1}, {0, 2}, {1}, {4}, {3}}; | ||
int count = graph_components_numbers(5, v); | ||
|
||
EXPECT_EQ(count, 2); | ||
} | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, returns_1_when_given_1) { | ||
std::vector<std::vector<int>> v{{ }}; | ||
int count = graph_components_numbers(1, v); | ||
|
||
EXPECT_EQ(count, 1); | ||
} | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, returns_3_when_given_8) { | ||
std::vector<std::vector<int>> v{{1, 7}, {0, 6}, {3}, {2, 4}, | ||
{3}, { }, {1, 7}, {0, 6}}; | ||
int count = graph_components_numbers(8, v); | ||
|
||
EXPECT_EQ(count, 3); | ||
} | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, returns_1_when_given_10) { | ||
std::vector<std::vector<int>> v{{1}, {0, 2}, {3, 1}, {4, 2}, {5, 3}, | ||
{6, 4}, {7, 5}, {8, 6}, {9, 7}, {8}}; | ||
int count = graph_components_numbers(10, v); | ||
|
||
EXPECT_EQ(count, 1); | ||
} | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, returns_0_when_given_0) { | ||
std::vector<std::vector<int>> v{ }; | ||
int count = graph_components_numbers(0, v); | ||
|
||
EXPECT_EQ(count, 0); | ||
} | ||
|
||
TEST(Shemiakina_Alesia_GraphNumbersTest, one_sided_list) { | ||
std::vector<std::vector<int>> v{{1}, {2}, {0}}; | ||
int count = graph_components_numbers(3, v); | ||
|
||
EXPECT_EQ(count, 1); | ||
} |
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,8 @@ | ||
// Copyright 2024 Shemiakina Alesia | ||
|
||
#include <gtest/gtest.h> | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |