Skip to content

Commit

Permalink
tests: Bubble sort unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noctera committed Dec 4, 2021
1 parent 159a1d7 commit 15f5cea
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
27 changes: 27 additions & 0 deletions tests/Benchmark.cpp
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);
};
}
28 changes: 28 additions & 0 deletions tests/BubbleSort.cpp
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'});
}
2 changes: 0 additions & 2 deletions tests/TextToBin.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_ENABLE_BENCHMARKING

#include <catch2/catch.hpp>

int main(int argc, char** argv) {
Expand Down

0 comments on commit 15f5cea

Please sign in to comment.