-
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.
- Loading branch information
noctera
committed
Dec 4, 2021
1 parent
159a1d7
commit 15f5cea
Showing
4 changed files
with
57 additions
and
2 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,27 @@ | ||
#define CATCH_CONFIG_ENABLE_BENCHMARKING | ||
#include "AlgoCpp/Algorithms/Sorting/BubbleSort.hpp" | ||
#include <catch2/catch.hpp> | ||
#include <random> | ||
#include <vector> | ||
|
||
|
||
TEST_CASE("Benchmarking", "[bubbleSort]") { | ||
std::vector<int> test1 = {1, 4, 5, 2, 3}; | ||
BENCHMARK("Bubble sort 5") { | ||
return algocpp::sorting::bubbleSort(test1); | ||
}; | ||
|
||
|
||
std::random_device rd; | ||
std::mt19937 mt(rd()); | ||
std::uniform_real_distribution<double> dist(1.0, 1000000.0); | ||
|
||
std::vector<int> test2; | ||
for (int i = 1; i < 50000; ++i) { | ||
test2.push_back(int(dist(mt))); | ||
} | ||
|
||
BENCHMARK("Bubble sort 1000000") { | ||
return algocpp::sorting::bubbleSort(test2); | ||
}; | ||
} |
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,28 @@ | ||
#define CATCH_CONFIG_ENABLE_BENCHMARKING | ||
#include "AlgoCpp/Algorithms/Sorting/BubbleSort.hpp" | ||
#include <catch2/catch.hpp> | ||
#include <vector> | ||
|
||
|
||
TEST_CASE("Check if Bubble sort is sorting the right way", "[bubbleSort]") { | ||
std::vector<int> test1 = {1, 4, 5, 2, 3}; | ||
std::vector<int> test2 = {1, 2, 5, 2, 3}; | ||
std::vector<int> test3 = {1, 1, 1, 1, 1}; | ||
std::vector<int> test4 = {1}; | ||
std::array<int, 5> test5 = {5, 3, 1, 4, 2}; | ||
std::vector<char> test6 = {'c', 'b', 'x', 'm', 'n'}; | ||
|
||
algocpp::sorting::bubbleSort(test1); | ||
algocpp::sorting::bubbleSort(test2); | ||
algocpp::sorting::bubbleSort(test3); | ||
algocpp::sorting::bubbleSort(test4); | ||
algocpp::sorting::bubbleSort(test5); | ||
algocpp::sorting::bubbleSort(test6); | ||
|
||
REQUIRE(test1 == std::vector<int>{1, 2, 3, 4, 5}); | ||
REQUIRE(test2 == std::vector<int>{1, 2, 2, 3, 5}); | ||
REQUIRE(test3 == std::vector<int>{1, 1, 1, 1, 1}); | ||
REQUIRE(test4 == std::vector<int>{1}); | ||
REQUIRE(test5 == std::array<int, 5>{1, 2, 3, 4, 5}); | ||
REQUIRE(test6 == std::vector<char>{'b', 'c', 'm', 'n', 'x'}); | ||
} |
This file was deleted.
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