add logger and some tests

This commit is contained in:
chatlanin
2025-01-03 11:53:18 +03:00
parent 67eab0a97f
commit 4fc81c4c04
8 changed files with 83 additions and 55 deletions

View File

@@ -2,5 +2,5 @@ catch2_with_main_dep = dependency('catch2-with-main')
dep = [hack_dep, catch2_with_main_dep]
test('patterns', executable('patterns', ['patterns/ring_buffer.cpp'], dependencies : dep))
test('mt', executable('mt', ['mt/max.cpp'], dependencies : dep))
test('mt', executable('mt', ['mt/mt.cpp'], dependencies : dep))

View File

@@ -1,13 +0,0 @@
#include "catch2/catch_test_macros.hpp"
#include "hack/mt/algorithms/max.hpp"
TEST_CASE("mt")
{
SECTION("max buffer")
{
int a = 4, b = 5;
int& c = a;
REQUIRE(hack::mt::algorithms::max(4, 5) == 5);
REQUIRE(hack::mt::algorithms::max(c, b) == 5);
}
}

31
tests/mt/mt.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include "catch2/catch_test_macros.hpp"
#include <forward_list>
#include "hack/mt/algorithms/max.hpp"
#include "hack/mt/algorithms/sort.hpp"
TEST_CASE("mt")
{
SECTION("max")
{
int a = 4, b = 5;
int& c = a;
REQUIRE(hack::mt::algorithms::max(4, 5) == 5);
REQUIRE(hack::mt::algorithms::max(c, b) == 5);
}
SECTION("sort")
{
std::vector<int> v { 4, 4, 6, 1, 4, 3, 2 };
std::vector<int> vs { 1, 2, 3, 4, 4, 4, 6 };
std::forward_list<int> l { 8, 7, 5, 9, 0, 1, 3, 2, 6, 4 };
std::forward_list<int> ls { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
hack::mt::algorithms::sort(v);
hack::mt::algorithms::sort(l);
REQUIRE(v == vs);
REQUIRE(l == ls);
}
}

View File

@@ -1,4 +1,5 @@
#include "catch2/catch_test_macros.hpp"
#include "hack/patterns/ring_buffer.hpp"
TEST_CASE("patterns")