#include #include #include "BinaryOperatorFactory.hpp" TEMPLATE_TEST_CASE("BinaryOperatorFactory", "[calculator-challenge]", std::int64_t, double) { constexpr TestType kLeftOperand{20}; constexpr TestType kRightOperand{2}; BinaryOperatorFactory 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)); }