feat: add challenge code
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
|
||||
#include <catch2/catch_template_test_macros.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "BinaryOperatorFactory.hpp"
|
||||
|
||||
TEMPLATE_TEST_CASE("BinaryOperatorFactory", "[calculator-challenge]", std::int64_t, double)
|
||||
{
|
||||
constexpr TestType kLeftOperand{20};
|
||||
constexpr TestType kRightOperand{2};
|
||||
|
||||
BinaryOperatorFactory<TestType> factory;
|
||||
|
||||
auto check_factory = [&](std::string_view str, TestType result) {
|
||||
auto operation = factory.make(str);
|
||||
if (!operation.has_value()) {
|
||||
return false;
|
||||
}
|
||||
return (*operation)(kLeftOperand, kRightOperand) == result;
|
||||
};
|
||||
|
||||
CHECK(check_factory("+", kLeftOperand + kRightOperand));
|
||||
CHECK(check_factory(" + ", kLeftOperand + kRightOperand));
|
||||
CHECK(check_factory(" +", kLeftOperand + kRightOperand));
|
||||
CHECK(check_factory("+ ", kLeftOperand + kRightOperand));
|
||||
CHECK(check_factory("+ a", kLeftOperand + kRightOperand));
|
||||
CHECK(check_factory("-", kLeftOperand - kRightOperand));
|
||||
CHECK(check_factory("*", kLeftOperand * kRightOperand));
|
||||
CHECK(check_factory("/", kLeftOperand / kRightOperand));
|
||||
}
|
||||
Reference in New Issue
Block a user