This commit is contained in:
chatlanin
2025-01-03 10:25:22 +03:00
parent 6b1e1f9d0e
commit 55917da5ee
50 changed files with 246 additions and 1680 deletions

20
tests/base_test_fib.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <catch2/catch_test_macros.hpp>
static int Factorial(int number)
{
// return number <= 1 ? number : Factorial(number - 1) * number; // fail
return number <= 1 ? 1 : Factorial(number - 1) * number; // pass
}
TEST_CASE("[base_test_fib] Factorial of 0 is 1 (fail)", "[single-file]")
{
REQUIRE(Factorial(0) == 1);
}
TEST_CASE("[base_test_fib] Factorials of 1 and higher are computed (pass)", "[single-file]")
{
REQUIRE(Factorial(1) == 1);
REQUIRE(Factorial(2) == 2);
REQUIRE(Factorial(3) == 6);
REQUIRE(Factorial(10) == 3628800);
}

View File

@@ -1,12 +0,0 @@
#include <array>
#include "hack/exception/exception.hpp"
auto main(int argc, char *argv[]) -> int
{
hack::exception ex;
ex.service("test service");
ex.log();
}

12
tests/meson.build Executable file → Normal file
View File

@@ -1,7 +1,5 @@
executable(
meson.project_name(),
'main.cpp',
dependencies : deps,
cpp_args: args,
include_directories : inc
)
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))

View File

@@ -0,0 +1,59 @@
#include "catch2/catch_test_macros.hpp"
#include "hack/patterns/ring_buffer.hpp"
TEST_CASE("patterns")
{
SECTION("ring buffer")
{
// single value
hack::patterns::ring_buffer<int, 10> rb1;
REQUIRE(rb1.empty() == true);
for (int i = 1; i < 13; ++i) rb1.put(i);
REQUIRE(rb1.empty() == false);
REQUIRE(rb1.size() == 10);
while(!rb1.empty()) REQUIRE(rb1.get().has_value() == true);
REQUIRE(rb1.empty() == true);
REQUIRE(rb1.size() == 0);
rb1.put(123);
rb1.put(23);
rb1.put(3);
REQUIRE(rb1.get().value() == 123);
REQUIRE(rb1.empty() == false);
REQUIRE(rb1.size() == 2);
REQUIRE(rb1.get().value() == 23);
REQUIRE(rb1.empty() == false);
REQUIRE(rb1.size() == 1);
rb1.reset();
REQUIRE(rb1.empty() == true);
REQUIRE(rb1.size() == 0);
REQUIRE(rb1.get().has_value() == false);
// vector value
std::vector<int> v { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
hack::patterns::ring_buffer<int, 10> rb2;
REQUIRE(rb2.empty() == true);
rb2.put(v);
REQUIRE(rb2.get().value() == 1);
REQUIRE(rb2.get().value() == 2);
v.emplace_back(17);
rb2.put(v);
REQUIRE(rb2.get().value() == 2);
REQUIRE(rb2.get().value() == 3);
REQUIRE(rb2.get().value() == 4);
REQUIRE(rb2.get().value() == 5);
REQUIRE(rb2.get().value() == 6);
REQUIRE(rb2.get().value() == 7);
REQUIRE(rb2.get().value() == 8);
REQUIRE(rb2.get().value() == 9);
REQUIRE(rb2.get().value() == 10);
REQUIRE(rb2.get().value() == 17);
}
}