small result fixes

This commit is contained in:
2026-07-28 09:52:49 +02:00
parent 06f6166f05
commit 730ab05213
2 changed files with 22 additions and 16 deletions
+7 -5
View File
@@ -5,13 +5,15 @@
#include "matador/utils/result.hpp"
namespace matador::test {
namespace {
enum class math_error : int32_t {
OK = 0,
DIVISION_BY_ZERO = 1,
FAILURE = 2
};
}
utils::result<float, math_error>divide(const float x, const float y) {
static utils::result<float, math_error>divide(const float x, const float y) {
if (y == 0) {
return utils::failure(math_error::DIVISION_BY_ZERO);
}
@@ -19,15 +21,15 @@ utils::result<float, math_error>divide(const float x, const float y) {
return utils::ok(x / y);
}
utils::result<float, math_error>multiply(const float x, const float y) {
static utils::result<float, math_error>multiply(const float x, const float y) {
return utils::ok(x * y);
}
utils::result<float, math_error>plus(const float x, const float y) {
static utils::result<float, math_error>plus(const float x, const float y) {
return utils::ok(x + y);
}
utils::result<void, math_error>action_on_greater_42(const float i) {
static utils::result<void, math_error>action_on_greater_42(const float i) {
if (i > 42) {
return utils::ok<void>();
}
@@ -88,7 +90,7 @@ TEST_CASE("Test result", "[result]") {
REQUIRE(!res2.is_ok());
REQUIRE(res2.is_error());
const auto e = res2.err();
// REQUIRE(res2.err() == "division by zero error");
REQUIRE(res2.err() == "division by zero error");
res = test::divide(4, 2)
.and_then([](const auto &val) { return test::multiply(val, 5); })