New Repository

Had my private email in a old commit of the first repository
This commit is contained in:
n0ffie 2024-10-28 00:33:32 +01:00
commit f25d3cc8da
20 changed files with 6534 additions and 0 deletions

6
tests/test_main.cpp Normal file
View file

@ -0,0 +1,6 @@
#include <gtest/gtest.h>
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -0,0 +1,54 @@
// tests/sorting_tests.cpp
#include <gtest/gtest.h>
#include <vector>
template<typename T>
void swap(T& a, T& b) noexcept
{
T temp = a;
a = b;
b = temp;
}
template<typename T>
void bubble_sort(std::vector<T>& in)
{
for (size_t i = 0; i < in.size(); ++i)
{
for (size_t j = 0; j < in.size() - 1; ++j)
{
if (in[j] > in[j + 1])
{
swap(in[j], in[j + 1]);
}
}
}
}
TEST(BubbleSortTest, CorrectlySortsVector) {
std::vector input = {5, 2, 8, 1, 9};
std::vector expected = {1, 2, 5, 8, 9};
bubble_sort(input);
EXPECT_EQ(input, expected);
}
TEST(BubbleSortTest, HandlesEmptyVector) {
std::vector<int> input = {};
std::vector<int> expected = {};
bubble_sort(input);
EXPECT_EQ(input, expected);
}
TEST(BubbleSortTest, HandlesSingleElement) {
std::vector input = {1};
std::vector expected = {1};
bubble_sort(input);
EXPECT_EQ(input, expected);
}