generated from Me-Phew/programowanie-zaawansowane-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Me-Phew/dev
ci: fix test case after verifying tests configuration
- Loading branch information
Showing
17 changed files
with
291 additions
and
33 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,4 @@ | ||
[submodule "extern/googletest"] | ||
path = extern/googletest | ||
url = https://github.com/google/googletest.git | ||
branch = v1.15.x |
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 |
---|---|---|
@@ -1,16 +1,44 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(MergeSort) | ||
|
||
include_directories(src/app src/merge_sorter) | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(SOURCES src/main.cpp src/app/app.cpp src/merge_sorter/merge_sorter.cpp) | ||
include_directories(src/app src/merge_sorter src/utils) | ||
|
||
# Create merge_sorter library | ||
add_library(merge_sorter | ||
src/merge_sorter/merge_sorter.cpp | ||
) | ||
|
||
target_include_directories(merge_sorter PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/merge_sorter | ||
) | ||
|
||
# Main executable | ||
set(SOURCES src/main.cpp src/app/app.cpp | ||
src/merge_sorter/merge_sorter.cpp | ||
src/utils/array_utils/array_utils.cpp | ||
src/utils/random_number_generator/random_number_generator.cpp | ||
) | ||
|
||
add_executable(MergeSort ${SOURCES}) | ||
target_link_libraries(MergeSort PRIVATE merge_sorter) | ||
|
||
# Compile with all warnings, treat warnings as errors | ||
if (MSVC) | ||
add_compile_options(/W4 /WX) | ||
else() | ||
add_compile_options(-Wall -Wextra -pedantic -Werror) | ||
endif() | ||
|
||
# Force Google Test to use dynamic runtime library | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
|
||
option(PACKAGE_TESTS "Build the tests" ON) | ||
if(PACKAGE_TESTS) | ||
enable_testing() | ||
include(GoogleTest) | ||
add_subdirectory(tests) | ||
endif() |
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
Submodule googletest
added at
b514bd
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,46 @@ | ||
/** | ||
* @file array_utils.cpp | ||
* @author Mateusz Basiaga (basmateusz@wp.pl) | ||
* @brief | ||
* @date 2024-11-14 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <vector> | ||
#include <random> | ||
#include <algorithm> | ||
#include <iostream> | ||
|
||
void displayArray(std::vector<int> arr) { | ||
std::cout << "["; | ||
|
||
for (auto it = arr.begin(); it != arr.end(); ++it) { | ||
std::cout << *it; | ||
|
||
if (it != arr.end() - 1) { | ||
std::cout << ", "; | ||
} | ||
} | ||
|
||
std::cout << "]\n"; | ||
} | ||
|
||
void randomlyShuffleArray(std::vector<int>& arr) { | ||
std::random_device randomDevice; | ||
std::mt19937 generator(randomDevice()); | ||
|
||
std::shuffle(arr.begin(), arr.end(), generator); | ||
} | ||
|
||
void reverseArray(std::vector<int>& arr) { | ||
for (int i = 0; i < arr.size() / 2; i++) { | ||
//std::swap(arr[i], arr[arrSize - i - 1]); | ||
int temp = arr[i]; | ||
|
||
int swappedElementIndex = arr.size() - i - 1; | ||
arr[i] = arr[swappedElementIndex]; | ||
arr[swappedElementIndex] = temp; | ||
} | ||
} |
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,22 @@ | ||
/** | ||
* @file array_utils.hpp | ||
* @author Mateusz Basiaga (basmateusz@wp.pl) | ||
* @brief | ||
* @date 2024-11-14 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#ifndef ARRAY_UTILS_HPP | ||
#define ARRAY_UTILS_HPP | ||
|
||
#include <vector> | ||
|
||
void displayArray(std::vector<int>); | ||
|
||
void randomlyShuffleArray(std::vector<int>&); | ||
|
||
void reverseArray(std::vector<int>&); | ||
|
||
#endif /* ARRAY_UTILS_HPP */ |
30 changes: 30 additions & 0 deletions
30
src/utils/random_number_generator/random_number_generator.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,30 @@ | ||
/** | ||
* @file random_number_generator.cpp | ||
* @author Mateusz Basiaga (basmateusz@wp.pl) | ||
* @brief | ||
* @date 2024-11-14 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include<cstdlib> | ||
#include<ctime> | ||
|
||
#include <random_number_generator/random_number_generator.hpp> | ||
|
||
bool RandomNumberGenerator::isSeeded = false; | ||
|
||
void RandomNumberGenerator::seed() { | ||
if (!isSeeded) { | ||
std::srand(std::time(NULL)); | ||
isSeeded = true; | ||
} | ||
} | ||
|
||
int RandomNumberGenerator::getRandomNumber(int min, int max) { | ||
RandomNumberGenerator::seed(); | ||
|
||
int range = max - min; | ||
return std::rand() % range; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/utils/random_number_generator/random_number_generator.hpp
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,25 @@ | ||
/** | ||
* @file random_number_generator.hpp | ||
* @author Mateusz Basiaga (basmateusz@wp.pl) | ||
* @brief | ||
* @date 2024-11-14 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#ifndef RANDOM_NUMBER_GENERATOR_HPP | ||
#define RANDOM_NUMBER_GENERATOR_HPP | ||
|
||
class RandomNumberGenerator { | ||
private: | ||
static bool isSeeded; | ||
|
||
/// @brief Inicjalizuje generator liczb losowych. | ||
static void seed(); | ||
|
||
public: | ||
static int getRandomNumber(int min, int max); | ||
}; | ||
|
||
#endif /* RANDOM_NUMBER_GENERATOR_HPP */ |
Oops, something went wrong.