Files
calculator-challenge/BinaryOperatorFactoryTests.cpp
T
2024-03-13 01:55:14 +00:00

31 lines
1.1 KiB
C++

#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));
}