improved result test with specific error test
This commit is contained in:
parent
4199c5029c
commit
38da76bfb3
|
|
@ -25,7 +25,12 @@ utils::result<float, math_error>plus(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::result<float, std::string>error_to_string(math_error err) {
|
utils::result<float, std::string>error_to_string(math_error err) {
|
||||||
return utils::error(std::string("error"));
|
switch (err) {
|
||||||
|
case math_error::DIVISION_BY_ZERO:
|
||||||
|
return utils::error(std::string("division by zero error"));
|
||||||
|
default:
|
||||||
|
return utils::error(std::string("unknown error"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +81,7 @@ TEST_CASE("Result tests", "[result]") {
|
||||||
REQUIRE(!res2);
|
REQUIRE(!res2);
|
||||||
REQUIRE(!res2.is_ok());
|
REQUIRE(!res2.is_ok());
|
||||||
REQUIRE(res2.is_error());
|
REQUIRE(res2.is_error());
|
||||||
REQUIRE((res2.err() == "error"));
|
REQUIRE((res2.err() == "division by zero error"));
|
||||||
|
|
||||||
res = test::divide(4, 2)
|
res = test::divide(4, 2)
|
||||||
.and_then([](const auto &val) { return test::multiply(val, 5); })
|
.and_then([](const auto &val) { return test::multiply(val, 5); })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue