From 90f7488483797907f79cbfb459f13450d2794a2f Mon Sep 17 00:00:00 2001 From: fintarin Date: Sun, 18 Feb 2024 23:10:55 +0300 Subject: [PATCH] Rework all exceptions --- include/fintamath/core/IArithmetic.hpp | 3 + include/fintamath/core/IArithmeticCRTP.hpp | 8 +- include/fintamath/core/IComparable.hpp | 2 + include/fintamath/core/IComparableCRTP.hpp | 7 +- include/fintamath/exceptions/Exception.hpp | 11 +- .../exceptions/InvalidInputException.hpp | 48 +- .../exceptions/UndefinedException.hpp | 47 +- include/fintamath/expressions/IExpression.hpp | 2 + .../fintamath/expressions/IExpressionCRTP.hpp | 18 +- include/fintamath/numbers/IInteger.hpp | 2 + include/fintamath/numbers/IIntegerCRTP.hpp | 8 +- include/fintamath/numbers/Integer.hpp | 3 +- include/fintamath/numbers/Rational.hpp | 2 +- include/fintamath/numbers/Real.hpp | 4 +- src/fintamath/expressions/Expression.cpp | 6 +- src/fintamath/numbers/Integer.cpp | 21 +- src/fintamath/numbers/NumberAbstract.cpp | 4 +- src/fintamath/numbers/Rational.cpp | 54 +- src/fintamath/numbers/Real.cpp | 35 +- tests/src/core/IArithmeticTests.cpp | 41 +- tests/src/core/IComparableTests.cpp | 41 +- tests/src/exceptions/ExceptionTests.cpp | 4 +- ...validInputBinaryOperatorExceptionTests.cpp | 13 - .../exceptions/InvalidInputExceptionTests.cpp | 10 +- .../InvalidInputFunctionExceptionTests.cpp | 17 - ...nvalidInputUnaryOperatorExceptionTests.cpp | 17 - .../UndefinedBinaryOperatorExceptionTests.cpp | 13 - .../exceptions/UndefinedExceptionTests.cpp | 10 +- .../UndefinedFunctionExceptionTests.cpp | 17 - .../UndefinedUnaryOperatorExceptionTests.cpp | 17 - .../src/expressions/ExpressionParserTests.cpp | 551 ++++-- tests/src/expressions/ExpressionTests.cpp | 16 +- tests/src/expressions/IExpressionTests.cpp | 31 +- .../interfaces/IBinaryExpressionTests.cpp | 18 +- .../interfaces/IPolynomExpressionTests.cpp | 6 +- .../interfaces/IUnaryExpressionTests.cpp | 12 +- tests/src/functions/FunctionUtilsTests.cpp | 41 +- tests/src/functions/IFunctionTests.cpp | 40 +- tests/src/functions/arithmetic/AbsTests.cpp | 28 +- tests/src/functions/arithmetic/AddTests.cpp | 30 +- tests/src/literals/BooleanTests.cpp | 27 +- tests/src/literals/VariableTests.cpp | 96 +- tests/src/numbers/ComplexTests.cpp | 141 +- tests/src/numbers/IIntegerTests.cpp | 61 +- tests/src/numbers/IntegerFunctionsTests.cpp | 116 +- tests/src/numbers/IntegerTests.cpp | 51 +- tests/src/numbers/NumberAbstractTests.cpp | 21 +- tests/src/numbers/RationalTests.cpp | 101 +- tests/src/numbers/RealFunctionsTests.cpp | 1661 +++++++++++------ tests/src/numbers/RealTests.cpp | 122 +- 50 files changed, 2525 insertions(+), 1130 deletions(-) delete mode 100644 tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp delete mode 100644 tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp delete mode 100644 tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp delete mode 100644 tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp delete mode 100644 tests/src/exceptions/UndefinedFunctionExceptionTests.cpp delete mode 100644 tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp diff --git a/include/fintamath/core/IArithmetic.hpp b/include/fintamath/core/IArithmetic.hpp index 425882c5d..c9095d09d 100644 --- a/include/fintamath/core/IArithmetic.hpp +++ b/include/fintamath/core/IArithmetic.hpp @@ -5,10 +5,13 @@ #include #include +#include + #include "fintamath/core/CoreUtils.hpp" #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectTypes.hpp" #include "fintamath/core/Parser.hpp" +#include "fintamath/exceptions/InvalidInputException.hpp" namespace fintamath { diff --git a/include/fintamath/core/IArithmeticCRTP.hpp b/include/fintamath/core/IArithmeticCRTP.hpp index 92331d981..215eecb21 100644 --- a/include/fintamath/core/IArithmeticCRTP.hpp +++ b/include/fintamath/core/IArithmeticCRTP.hpp @@ -137,7 +137,13 @@ class IArithmeticCRTP_ : public IArithmetic { return cast(res->toMinimalObject()); } - throw InvalidInputBinaryOperatorException(operStr, toString(), rhs.toString()); + throw InvalidInputException(fmt::format( + R"(Invalid arguments of "{}" operator ({} "{}" and {} "{}" are unconvertible to each other))", + operStr, + this->getType().getName(), + this->toString(), + rhs.getType().getName(), + rhs.toString())); } private: diff --git a/include/fintamath/core/IComparable.hpp b/include/fintamath/core/IComparable.hpp index 99e47e55b..9af1f2839 100644 --- a/include/fintamath/core/IComparable.hpp +++ b/include/fintamath/core/IComparable.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include "fintamath/core/CoreUtils.hpp" #include "fintamath/core/IArithmetic.hpp" #include "fintamath/core/MathObjectTypes.hpp" diff --git a/include/fintamath/core/IComparableCRTP.hpp b/include/fintamath/core/IComparableCRTP.hpp index 2f04164da..6230ec6ae 100644 --- a/include/fintamath/core/IComparableCRTP.hpp +++ b/include/fintamath/core/IComparableCRTP.hpp @@ -34,7 +34,12 @@ class IComparableCRTP_ : public IComparable { return 0 <=> (rhs <=> *this); } - throw InvalidInputBinaryOperatorException("<=>", toString(), rhs.toString()); + throw InvalidInputException(fmt::format( + R"(Invalid arguments of comparison operator ({} "{}" and {} "{}" are unconvertible to each other))", + this->getType().getName(), + this->toString(), + rhs.getType().getName(), + rhs.toString())); } private: diff --git a/include/fintamath/exceptions/Exception.hpp b/include/fintamath/exceptions/Exception.hpp index 9605e835e..6bd190d8d 100644 --- a/include/fintamath/exceptions/Exception.hpp +++ b/include/fintamath/exceptions/Exception.hpp @@ -1,14 +1,23 @@ #pragma once #include +#include +#include namespace fintamath { class Exception : public std::exception { public: + explicit Exception(std::string inMessage) + : message(std::move(inMessage)) { + } + const char *what() const noexcept override { - return "Something went wrong..."; + return message.c_str(); } + +private: + std::string message; }; } diff --git a/include/fintamath/exceptions/InvalidInputException.hpp b/include/fintamath/exceptions/InvalidInputException.hpp index de2f10aba..1cbea1988 100644 --- a/include/fintamath/exceptions/InvalidInputException.hpp +++ b/include/fintamath/exceptions/InvalidInputException.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include "fintamath/exceptions/Exception.hpp" @@ -10,45 +10,22 @@ namespace fintamath { class InvalidInputException : public Exception { public: - InvalidInputException() = default; - - explicit InvalidInputException(const std::string &input) { - content += ": " + input; - } - - const char *what() const noexcept override { - return content.c_str(); + explicit InvalidInputException(std::string inMessage) + : Exception(std::move(inMessage)) { } - -protected: - std::string content = "Invalid input"; }; class InvalidInputFunctionException final : public InvalidInputException { public: - explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) { - content += ": " + func + "("; - - if (!argVect.empty()) { - for (const auto &arg : argVect) { - content += arg + ','; - } - - content.pop_back(); - } - - content += ")"; - } - - const char *what() const noexcept override { - return content.c_str(); + explicit InvalidInputFunctionException(const std::string &func, const std::vector &) + : InvalidInputException(func) { } }; class InvalidInputBinaryOperatorException final : public InvalidInputException { public: - explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { - content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; + explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &, const std::string &) + : InvalidInputException(oper) { } }; @@ -60,15 +37,8 @@ class InvalidInputUnaryOperatorException final : public InvalidInputException { }; public: - explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { - switch (type) { - case Type::Prefix: - content += ": " + oper + "(" + rhs + ")"; - break; - case Type::Postfix: - content += ": (" + rhs + ")" + oper; - break; - } + explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &, const Type) + : InvalidInputException(oper) { } }; diff --git a/include/fintamath/exceptions/UndefinedException.hpp b/include/fintamath/exceptions/UndefinedException.hpp index 56ab666db..c8dfe93a2 100644 --- a/include/fintamath/exceptions/UndefinedException.hpp +++ b/include/fintamath/exceptions/UndefinedException.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "fintamath/exceptions/Exception.hpp" @@ -10,45 +11,22 @@ namespace fintamath { class UndefinedException : public Exception { public: - UndefinedException() = default; - - explicit UndefinedException(const std::string &input) { - content += ": " + input; - } - - const char *what() const noexcept override { - return content.c_str(); + explicit UndefinedException(std::string inMessage) + : Exception(std::move(inMessage)) { } - -protected: - std::string content = "Undefined"; }; class UndefinedFunctionException final : public UndefinedException { public: - explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) { - content += ": " + func + "("; - - if (!argVect.empty()) { - for (const auto &arg : argVect) { - content += arg + ','; - } - - content.pop_back(); - } - - content += ")"; - } - - const char *what() const noexcept override { - return content.c_str(); + explicit UndefinedFunctionException(const std::string &func, const std::vector &) + : UndefinedException(func) { } }; class UndefinedBinaryOperatorException final : public UndefinedException { public: - explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { - content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; + explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &, const std::string &) + : UndefinedException(oper) { } }; @@ -60,15 +38,8 @@ class UndefinedUnaryOperatorException final : public UndefinedException { }; public: - explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { - switch (type) { - case Type::Prefix: - content += ": " + oper + "(" + rhs + ")"; - break; - case Type::Postfix: - content += ": (" + rhs + ")" + oper; - break; - } + explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &, const Type) + : UndefinedException(oper) { } }; diff --git a/include/fintamath/expressions/IExpression.hpp b/include/fintamath/expressions/IExpression.hpp index d326b24c9..1c7a3df6f 100644 --- a/include/fintamath/expressions/IExpression.hpp +++ b/include/fintamath/expressions/IExpression.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include "fintamath/core/IArithmetic.hpp" #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectTypes.hpp" diff --git a/include/fintamath/expressions/IExpressionCRTP.hpp b/include/fintamath/expressions/IExpressionCRTP.hpp index f1dd73f03..406b90432 100644 --- a/include/fintamath/expressions/IExpressionCRTP.hpp +++ b/include/fintamath/expressions/IExpressionCRTP.hpp @@ -34,24 +34,24 @@ class IExpressionCRTP_ : public IExpressionBaseCRTP { } protected: - Derived &add(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("+", this->toString(), rhs.toString()); + Derived &add(const Derived &) override { + throw InvalidInputException(fmt::format("Arithmetic operations are not permitted for {}", this->getType().getName())); } - Derived &substract(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("-", this->toString(), rhs.toString()); + Derived &substract(const Derived &) override { + throw InvalidInputException(fmt::format("Arithmetic operations are not permitted for {}", this->getType().getName())); } - Derived &multiply(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("*", this->toString(), rhs.toString()); + Derived &multiply(const Derived &) override { + throw InvalidInputException(fmt::format("Arithmetic operations are not permitted for {}", this->getType().getName())); } - Derived ÷(const Derived &rhs) override { - throw InvalidInputBinaryOperatorException("/", this->toString(), rhs.toString()); + Derived ÷(const Derived &) override { + throw InvalidInputException(fmt::format("Arithmetic operations are not permitted for {}", this->getType().getName())); } Derived &negate() override { - throw InvalidInputUnaryOperatorException("-", this->toString(), InvalidInputUnaryOperatorException::Type::Prefix); + throw InvalidInputException(fmt::format("Arithmetic operations are not permitted for {}", this->getType().getName())); } private: diff --git a/include/fintamath/numbers/IInteger.hpp b/include/fintamath/numbers/IInteger.hpp index 627eb29de..bb3d77dbb 100644 --- a/include/fintamath/numbers/IInteger.hpp +++ b/include/fintamath/numbers/IInteger.hpp @@ -4,6 +4,8 @@ #include #include +#include + #include "fintamath/core/CoreUtils.hpp" #include "fintamath/core/MathObjectTypes.hpp" #include "fintamath/core/Parser.hpp" diff --git a/include/fintamath/numbers/IIntegerCRTP.hpp b/include/fintamath/numbers/IIntegerCRTP.hpp index 2bb9c02d7..ab95d99fc 100644 --- a/include/fintamath/numbers/IIntegerCRTP.hpp +++ b/include/fintamath/numbers/IIntegerCRTP.hpp @@ -209,7 +209,13 @@ class IIntegerCRTP_ : public IInteger { return cast(res->toMinimalObject()); } - throw InvalidInputBinaryOperatorException(operStr, toString(), rhs.toString()); + throw InvalidInputException(fmt::format( + R"(Invalid arguments of "{}" operator ({} "{}" and {} "{}" are unconvertible to each other))", + operStr, + this->getType().getName(), + this->toString(), + rhs.getType().getName(), + rhs.toString())); } private: diff --git a/include/fintamath/numbers/Integer.hpp b/include/fintamath/numbers/Integer.hpp index 6e74e72a2..78bde2752 100644 --- a/include/fintamath/numbers/Integer.hpp +++ b/include/fintamath/numbers/Integer.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,7 @@ class Integer final : public IIntegerCRTP { Integer(Backend inBackend); - explicit Integer(std::string str); + explicit Integer(std::string_view str); explicit Integer(std::integral auto val) : backend(val) { } diff --git a/include/fintamath/numbers/Rational.hpp b/include/fintamath/numbers/Rational.hpp index b141a5e94..375220121 100644 --- a/include/fintamath/numbers/Rational.hpp +++ b/include/fintamath/numbers/Rational.hpp @@ -20,7 +20,7 @@ class Rational final : public INumberCRTP { public: Rational() = default; - explicit Rational(const std::string &str); + explicit Rational(std::string_view str); explicit Rational(Integer inNumer, Integer inDenom); diff --git a/include/fintamath/numbers/Real.hpp b/include/fintamath/numbers/Real.hpp index 199d2b020..628180c03 100644 --- a/include/fintamath/numbers/Real.hpp +++ b/include/fintamath/numbers/Real.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -12,7 +13,6 @@ #include "fintamath/core/IArithmetic.hpp" #include "fintamath/core/IComparable.hpp" -#include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectTypes.hpp" #include "fintamath/numbers/INumber.hpp" #include "fintamath/numbers/Integer.hpp" @@ -42,7 +42,7 @@ class Real final : public INumberCRTP { Real(Backend inBackend); - explicit Real(std::string str); + explicit Real(std::string_view str); Real(const Rational &val); diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index 3f629c7dc..570790457 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -165,9 +165,9 @@ std::unique_ptr parseExpr(const std::string &str) { try { auto tokens = Tokenizer::tokenize(str); auto terms = Expression::tokensToTerms(tokens); - auto stack = Expression::termsToOperands(terms); - auto obj = Expression::operandsToObject(stack); - return obj; + auto operands = Expression::termsToOperands(terms); + auto object = Expression::operandsToObject(operands); + return object; } catch (const InvalidInputException &) { throw InvalidInputException(str); diff --git a/src/fintamath/numbers/Integer.cpp b/src/fintamath/numbers/Integer.cpp index 52aba98eb..aa18f9b10 100644 --- a/src/fintamath/numbers/Integer.cpp +++ b/src/fintamath/numbers/Integer.cpp @@ -4,8 +4,11 @@ #include #include #include +#include #include +#include + #include "fintamath/exceptions/InvalidInputException.hpp" #include "fintamath/exceptions/UndefinedException.hpp" #include "fintamath/numbers/NumberUtils.hpp" @@ -17,18 +20,16 @@ using namespace detail; Integer::Integer(Backend inBackend) : backend(std::move(inBackend)) { } -Integer::Integer(std::string str) { +Integer::Integer(const std::string_view str) { if (str.empty()) { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format(R"(Invalid {} "")", getTypeStatic().getName())); } - str = removeLeadingZeroes(std::move(str)); - try { - backend.assign(str); + backend.assign(removeLeadingZeroes(std::string(str))); } catch (const std::runtime_error &) { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format(R"(Invalid {} "{}")", getTypeStatic().getName(), str)); } } @@ -72,7 +73,7 @@ Integer &Integer::multiply(const Integer &rhs) { Integer &Integer::divide(const Integer &rhs) { if (rhs == 0) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); + throw UndefinedException(fmt::format(R"(Undefined "{}" / "{}" (division by zero))", toString(), rhs.toString())); } backend /= rhs.backend; @@ -81,7 +82,7 @@ Integer &Integer::divide(const Integer &rhs) { Integer &Integer::mod(const Integer &rhs) { if (rhs == 0) { - throw UndefinedBinaryOperatorException("mod", toString(), rhs.toString()); + throw UndefinedException(fmt::format(R"(Undefined "{}" % "{}" (modulo by zero))", toString(), rhs.toString())); } backend %= rhs.backend; @@ -109,7 +110,7 @@ Integer &Integer::bitLeftShift(const Integer &rhs) { return *this; } catch (...) { - throw UndefinedBinaryOperatorException("<<", toString(), rhs.toString()); + throw UndefinedException(fmt::format(R"(Undefined "{}" / "{}" (negative shift))", toString(), rhs.toString())); } } @@ -119,7 +120,7 @@ Integer &Integer::bitRightShift(const Integer &rhs) { return *this; } catch (...) { - throw UndefinedBinaryOperatorException(">>", toString(), rhs.toString()); + throw UndefinedException(fmt::format(R"(Undefined "{}" >> "{}" (negative shift))", toString(), rhs.toString())); } } diff --git a/src/fintamath/numbers/NumberAbstract.cpp b/src/fintamath/numbers/NumberAbstract.cpp index c721dcb3c..7957389f4 100644 --- a/src/fintamath/numbers/NumberAbstract.cpp +++ b/src/fintamath/numbers/NumberAbstract.cpp @@ -28,9 +28,7 @@ std::unique_ptr Integer::divideAbstract(const IArithmetic &rhs) con } if (const auto *intRhs = cast(&rhs)) { - if (*this % *intRhs != 0) { - return cast(Rational(*this, *intRhs).clone()); - } + return cast(Rational(*this, *intRhs).toMinimalObject()); } return IIntegerCRTP::divideAbstract(rhs); diff --git a/src/fintamath/numbers/Rational.cpp b/src/fintamath/numbers/Rational.cpp index f25159cfc..378a0bdee 100644 --- a/src/fintamath/numbers/Rational.cpp +++ b/src/fintamath/numbers/Rational.cpp @@ -7,8 +7,11 @@ #include #include #include +#include #include +#include + #include "fintamath/core/IMathObject.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" #include "fintamath/exceptions/UndefinedException.hpp" @@ -17,13 +20,9 @@ namespace fintamath { -Rational::Rational(const std::string &str) { - if (str.empty()) { - throw InvalidInputException(str); - } - +Rational::Rational(const std::string_view str) { if (str.empty() || str == ".") { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format(R"(Invalid {} "{}")", getTypeStatic().getName(), str)); } int64_t firstDigitNum = 0; @@ -35,25 +34,30 @@ Rational::Rational(const std::string &str) { firstDigitNum++; } - const std::string intPartStr = str.substr(static_cast(firstDigitNum), - static_cast(firstDotNum - firstDigitNum)); + const std::string intPartStr(str.substr(static_cast(firstDigitNum), + static_cast(firstDotNum - firstDigitNum))); Integer intPart; - if (!intPartStr.empty()) { - intPart = Integer(str.substr(static_cast(firstDigitNum), - static_cast(firstDotNum - firstDigitNum))); + try { + if (!intPartStr.empty()) { + intPart = Integer(str.substr(static_cast(firstDigitNum), + static_cast(firstDotNum - firstDigitNum))); + } + + if (firstDotNum + 1 < std::ssize(str)) { + const std::string numeratorStr(str.substr(static_cast(firstDotNum) + 1)); + std::string denominatorStr(numeratorStr.size() + 1, '0'); + denominatorStr.front() = '1'; + numer = Integer(numeratorStr); + denom = Integer(denominatorStr); + } } - - if (firstDotNum + 1 < std::ssize(str)) { - const std::string numeratorStr = str.substr(static_cast(firstDotNum) + 1); - std::string denominatorStr(numeratorStr.size() + 1, '0'); - denominatorStr.front() = '1'; - numer = Integer(numeratorStr); - denom = Integer(denominatorStr); + catch (const InvalidInputException &) { + throw InvalidInputException(fmt::format(R"(Invalid {} "{}")", getTypeStatic().getName(), str)); } if (intPart < 0 || numer < 0) { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format(R"(Invalid {} "{}")", getTypeStatic().getName(), str)); } toIrreducibleRational(); @@ -68,6 +72,10 @@ Rational::Rational(Integer inNumer, Integer inDenom) : numer(std::move(inNumer)), denom(std::move(inDenom)) { + if (denom == 0) { + throw UndefinedException(fmt::format(R"(Undefined "{}" / "{}" (division by zero))", numer.toString(), denom.toString())); + } + toIrreducibleRational(); } @@ -141,6 +149,10 @@ Rational &Rational::multiply(const Rational &rhs) { } Rational &Rational::divide(const Rational &rhs) { + if (rhs == 0) { + throw UndefinedException(fmt::format(R"(Undefined "{}" / "{}" (division by zero))", toString(), rhs.toString())); + } + numer *= rhs.denom; denom *= rhs.numer; toIrreducibleRational(); @@ -153,10 +165,6 @@ Rational &Rational::negate() { } void Rational::toIrreducibleRational() { - if (denom == 0) { - throw UndefinedBinaryOperatorException("/", numer.toString(), denom.toString()); - } - if (denom < 0) { numer *= -1; denom *= -1; diff --git a/src/fintamath/numbers/Real.cpp b/src/fintamath/numbers/Real.cpp index 165735ed3..1dd2f6588 100644 --- a/src/fintamath/numbers/Real.cpp +++ b/src/fintamath/numbers/Real.cpp @@ -7,10 +7,13 @@ #include #include #include +#include #include #include +#include + #include "fintamath/exceptions/InvalidInputException.hpp" #include "fintamath/exceptions/UndefinedException.hpp" #include "fintamath/numbers/Integer.hpp" @@ -28,39 +31,39 @@ Real::Real(Backend inBackend) : backend(std::move(inBackend)), isNegative(backend < 0) { if (!isFinite()) { - throw UndefinedException(backend.str()); + throw UndefinedException(fmt::format(R"(Undefined {})", toString())); } } -Real::Real(std::string str) : Real() { +Real::Real(const std::string_view str) : Real() { if (str.empty() || str == ".") { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format(R"(Invalid {} "{}")", getTypeStatic().getName(), str)); } - str = removeLeadingZeroes(std::move(str)); + std::string mutableStr = removeLeadingZeroes(std::string(str)); - if (str.front() == '-') { + if (mutableStr.front() == '-') { isNegative = true; } { const std::string expStr = "*10^"; - const size_t expPos = str.find(expStr); + const size_t expPos = mutableStr.find(expStr); if (expPos != std::string::npos) { - str.replace(expPos, expStr.length(), "e"); + mutableStr.replace(expPos, expStr.length(), "e"); } } try { - backend.assign(str); + backend.assign(mutableStr); } catch (const std::runtime_error &) { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format(R"(Invalid {} "{}")", getTypeStatic().getName(), str)); } if (!isFinite()) { - throw UndefinedException(str); + throw UndefinedException(fmt::format(R"(Undefined "{}" (the value is too big))", str)); } } @@ -222,15 +225,15 @@ Real &Real::multiply(const Real &rhs) { } Real &Real::divide(const Real &rhs) { + if (rhs == 0) { + throw UndefinedException(fmt::format(R"(Undefined "{}" / "{}" (division by zero))", toString(), rhs.toString())); + } + updatePrecision(rhs); isNegative = isNegative != rhs.isNegative; backend /= rhs.backend; - if (!isFinite()) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); - } - return *this; } @@ -250,9 +253,7 @@ void Real::updatePrecision(const Real &rhs) { void Real::validateNewPrecision(const unsigned precision) const { if (precision > outputPrecision) { - // TODO: use std::format - throw InvalidInputException("Precision must be less than or equal to " + - std::to_string(outputPrecision)); + throw InvalidInputException(fmt::format("Precision must be <= {}", outputPrecision)); } } diff --git a/tests/src/core/IArithmeticTests.cpp b/tests/src/core/IArithmeticTests.cpp index 0b7aa8079..2d19a04a8 100644 --- a/tests/src/core/IArithmeticTests.cpp +++ b/tests/src/core/IArithmeticTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/core/IArithmetic.hpp" @@ -67,8 +68,14 @@ TEST(IArithmeticTests, addTest) { EXPECT_TRUE(is(*m3 + *m2)); EXPECT_TRUE(is(*m3 + *m3)); - EXPECT_THROW(*m1 + TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() + *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 + TestArithmetic(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "+" operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() + *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "+" operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a += 3).toString(), "3"); @@ -103,8 +110,14 @@ TEST(IArithmeticTests, subTest) { EXPECT_TRUE(is(*m3 - *m2)); EXPECT_TRUE(is(*m3 - *m3)); - EXPECT_THROW(*m1 - TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() - *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 - TestArithmetic(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "-" operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() - *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "-" operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a -= 3).toString(), "-3"); @@ -139,8 +152,14 @@ TEST(IArithmeticTests, mulTest) { EXPECT_TRUE(is(*m3 * *m2)); EXPECT_TRUE(is(*m3 * *m3)); - EXPECT_THROW(*m1 * TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() * *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 * TestArithmetic(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "*" operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() * *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "*" operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a = 2; EXPECT_EQ((a *= 3).toString(), "6"); @@ -175,8 +194,14 @@ TEST(IArithmeticTests, divTest) { EXPECT_TRUE(is(*m3 / *m2)); EXPECT_TRUE(is(*m3 / *m3)); - EXPECT_THROW(*m1 / TestArithmetic(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestArithmetic() / *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 / TestArithmetic(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "/" operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() / *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "/" operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a = 4; EXPECT_EQ((a /= 2).toString(), "2"); diff --git a/tests/src/core/IComparableTests.cpp b/tests/src/core/IComparableTests.cpp index 8702e3422..5ab4f8840 100644 --- a/tests/src/core/IComparableTests.cpp +++ b/tests/src/core/IComparableTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/core/IComparable.hpp" @@ -59,8 +60,14 @@ TEST(IComparableTests, lessTest) { EXPECT_TRUE(*m3 < *m1); EXPECT_TRUE(*m3 < *m2); - EXPECT_THROW((void)(*m1 < TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() < *m1), InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 < TestComparable(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() < *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_TRUE(Integer() < 1); EXPECT_TRUE(-1 < Integer()); @@ -84,8 +91,14 @@ TEST(IComparableTests, moreTest) { EXPECT_FALSE(*m3 > *m1); EXPECT_FALSE(*m3 > *m2); - EXPECT_THROW(void(*m1 > TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() > *m1), InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 < TestComparable(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() < *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_FALSE(Integer() > 1); EXPECT_FALSE(-1 > Integer()); @@ -109,8 +122,14 @@ TEST(IComparableTests, lessEqualsTest) { EXPECT_TRUE(*m3 <= *m1); EXPECT_TRUE(*m3 <= *m2); - EXPECT_THROW(void(*m1 <= TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() <= *m1), InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 <= TestComparable(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() <= *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_TRUE(Integer() <= 1); EXPECT_TRUE(-1 <= Integer()); @@ -134,8 +153,14 @@ TEST(IComparableTests, moreEqualsTest) { EXPECT_FALSE(*m3 >= *m1); EXPECT_FALSE(*m3 >= *m2); - EXPECT_THROW(void(*m1 >= TestComparable()), InvalidInputBinaryOperatorException); - EXPECT_THROW(void(TestComparable() >= *m1), InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 >= TestComparable(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() >= *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_FALSE(Integer() >= 1); EXPECT_FALSE(-1 >= Integer()); diff --git a/tests/src/exceptions/ExceptionTests.cpp b/tests/src/exceptions/ExceptionTests.cpp index 45a99b1df..f867013fa 100644 --- a/tests/src/exceptions/ExceptionTests.cpp +++ b/tests/src/exceptions/ExceptionTests.cpp @@ -7,7 +7,7 @@ using namespace fintamath; TEST(ExceptionTests, whatTest) { EXPECT_THAT( - [] { throw Exception(); }, + [] { throw Exception("Unknown exception"); }, testing::ThrowsMessage( - testing::StrEq("Something went wrong..."))); + testing::StrEq("Unknown exception"))); } diff --git a/tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp b/tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp deleted file mode 100644 index 0cc84d94f..000000000 --- a/tests/src/exceptions/InvalidInputBinaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputBinaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputBinaryOperatorException("^", "a", "0"); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: (a)^(0)"))); -} diff --git a/tests/src/exceptions/InvalidInputExceptionTests.cpp b/tests/src/exceptions/InvalidInputExceptionTests.cpp index aca858578..fe8a5754d 100644 --- a/tests/src/exceptions/InvalidInputExceptionTests.cpp +++ b/tests/src/exceptions/InvalidInputExceptionTests.cpp @@ -7,11 +7,7 @@ using namespace fintamath; TEST(InvalidInputExceptionTests, whatTest) { EXPECT_THAT( - [] { throw InvalidInputException(); }, + [] { throw InvalidInputException(R"(Integer("abc"))"); }, testing::ThrowsMessage( - testing::StrEq("Invalid input"))); - EXPECT_THAT( - [] { throw InvalidInputException("123"); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: 123"))); -} \ No newline at end of file + testing::StrEq(R"(Integer("abc"))"))); +} diff --git a/tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp b/tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp deleted file mode 100644 index 65416c397..000000000 --- a/tests/src/exceptions/InvalidInputFunctionExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputFunctionExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputFunctionException("f", {}); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: f()"))); - EXPECT_THAT( - [] { throw InvalidInputFunctionException("sqrt", {"-10", "a", "b"}); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: sqrt(-10,a,b)"))); -} diff --git a/tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp b/tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp deleted file mode 100644 index 2c1403984..000000000 --- a/tests/src/exceptions/InvalidInputUnaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/InvalidInputException.hpp" - -using namespace fintamath; - -TEST(InvalidInputUnaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw InvalidInputUnaryOperatorException("!", "-10", InvalidInputUnaryOperatorException::Type::Prefix); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: !(-10)"))); - EXPECT_THAT( - [] { throw InvalidInputUnaryOperatorException("!", "-10", InvalidInputUnaryOperatorException::Type::Postfix); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: (-10)!"))); -} diff --git a/tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp b/tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp deleted file mode 100644 index bd751dc64..000000000 --- a/tests/src/exceptions/UndefinedBinaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedBinaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedBinaryOperatorException("^", "a", "0"); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: (a)^(0)"))); -} diff --git a/tests/src/exceptions/UndefinedExceptionTests.cpp b/tests/src/exceptions/UndefinedExceptionTests.cpp index 59bd52967..23a07a216 100644 --- a/tests/src/exceptions/UndefinedExceptionTests.cpp +++ b/tests/src/exceptions/UndefinedExceptionTests.cpp @@ -7,11 +7,7 @@ using namespace fintamath; TEST(UndefinedExceptionTests, whatTest) { EXPECT_THAT( - [] { throw UndefinedException(); }, + [] { throw UndefinedException("Undefined 0 / 0"); }, testing::ThrowsMessage( - testing::StrEq("Undefined"))); - EXPECT_THAT( - [] { throw UndefinedException("123"); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: 123"))); -} \ No newline at end of file + testing::StrEq("Undefined 0 / 0"))); +} diff --git a/tests/src/exceptions/UndefinedFunctionExceptionTests.cpp b/tests/src/exceptions/UndefinedFunctionExceptionTests.cpp deleted file mode 100644 index 101edc757..000000000 --- a/tests/src/exceptions/UndefinedFunctionExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedFunctionExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedFunctionException("f", {}); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: f()"))); - EXPECT_THAT( - [] { throw UndefinedFunctionException("sqrt", {"-10", "a", "b"}); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: sqrt(-10,a,b)"))); -} diff --git a/tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp b/tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp deleted file mode 100644 index 297f3e5e7..000000000 --- a/tests/src/exceptions/UndefinedUnaryOperatorExceptionTests.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "fintamath/exceptions/UndefinedException.hpp" - -using namespace fintamath; - -TEST(UndefinedUnaryOpearatorExceptionTests, whatTest) { - EXPECT_THAT( - [] { throw UndefinedUnaryOperatorException("!", "-10", UndefinedUnaryOperatorException::Type::Prefix); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: !(-10)"))); - EXPECT_THAT( - [] { throw UndefinedUnaryOperatorException("!", "-10", UndefinedUnaryOperatorException::Type::Postfix); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: (-10)!"))); -} diff --git a/tests/src/expressions/ExpressionParserTests.cpp b/tests/src/expressions/ExpressionParserTests.cpp index 8957645c3..55dd1509e 100644 --- a/tests/src/expressions/ExpressionParserTests.cpp +++ b/tests/src/expressions/ExpressionParserTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/ExpressionParser.hpp" @@ -37,120 +38,450 @@ TEST(ExpressionParserTests, parseExprTest) { } TEST(ExpressionParserTests, parseExprNegativeTest) { - EXPECT_THROW(parseExpr(""), InvalidInputException); - EXPECT_THROW(parseExpr("1+"), InvalidInputException); - EXPECT_THROW(parseExpr("1-"), InvalidInputException); - EXPECT_THROW(parseExpr("1*"), InvalidInputException); - EXPECT_THROW(parseExpr("1/"), InvalidInputException); - EXPECT_THROW(parseExpr("*1"), InvalidInputException); - EXPECT_THROW(parseExpr("/1"), InvalidInputException); - EXPECT_THROW(parseExpr(" + "), InvalidInputException); - EXPECT_THROW(parseExpr("(1+2))"), InvalidInputException); - EXPECT_THROW(parseExpr("5-*3"), InvalidInputException); - EXPECT_THROW(parseExpr("5 3 +"), InvalidInputException); - EXPECT_THROW(parseExpr("2.2.2"), InvalidInputException); - EXPECT_THROW(parseExpr("--"), InvalidInputException); - EXPECT_THROW(parseExpr("."), InvalidInputException); - EXPECT_THROW(parseExpr(","), InvalidInputException); - EXPECT_THROW(parseExpr("/"), InvalidInputException); - EXPECT_THROW(parseExpr(";"), InvalidInputException); - EXPECT_THROW(parseExpr("\'"), InvalidInputException); - EXPECT_THROW(parseExpr("["), InvalidInputException); - EXPECT_THROW(parseExpr("]"), InvalidInputException); - EXPECT_THROW(parseExpr("!"), InvalidInputException); - EXPECT_THROW(parseExpr("@"), InvalidInputException); - EXPECT_THROW(parseExpr("\""), InvalidInputException); - EXPECT_THROW(parseExpr("#"), InvalidInputException); - EXPECT_THROW(parseExpr("№"), InvalidInputException); - EXPECT_THROW(parseExpr("%"), InvalidInputException); - EXPECT_THROW(parseExpr(":"), InvalidInputException); - EXPECT_THROW(parseExpr("?"), InvalidInputException); - EXPECT_THROW(parseExpr("*"), InvalidInputException); - EXPECT_THROW(parseExpr("("), InvalidInputException); - EXPECT_THROW(parseExpr(")"), InvalidInputException); - EXPECT_THROW(parseExpr("-"), InvalidInputException); - EXPECT_THROW(parseExpr("+"), InvalidInputException); - EXPECT_THROW(parseExpr("$"), InvalidInputException); - EXPECT_THROW(parseExpr("^"), InvalidInputException); - EXPECT_THROW(parseExpr("&"), InvalidInputException); - EXPECT_THROW(parseExpr("_"), InvalidInputException); - EXPECT_THROW(parseExpr("[1+1]"), InvalidInputException); - EXPECT_THROW(parseExpr("{1}"), InvalidInputException); - EXPECT_THROW(parseExpr(",2"), InvalidInputException); - EXPECT_THROW(parseExpr("2,"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr(""); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1+"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1-"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1*"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1/"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("*1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("/1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr(" + "); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(1+2))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("5-*3"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("5 3 +"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("2.2.2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("--"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("."); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr(","); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("/"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr(";"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("\'"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("["); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("]"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("!"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("@"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("\""); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("#"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("№"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("%"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr(":"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("?"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("*"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("("); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr(")"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("-"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("+"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("$"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("^"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("&"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("_"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("[1+1]"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("{1}"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr(",2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("2,"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(parseExpr("(1"), InvalidInputException); - EXPECT_THROW(parseExpr("(((2)"), InvalidInputException); - EXPECT_THROW(parseExpr("(((2))"), InvalidInputException); - EXPECT_THROW(parseExpr("((2)))"), InvalidInputException); - EXPECT_THROW(parseExpr("(2)))"), InvalidInputException); - EXPECT_THROW(parseExpr("(2"), InvalidInputException); - EXPECT_THROW(parseExpr("((2)"), InvalidInputException); - EXPECT_THROW(parseExpr("((2"), InvalidInputException); - EXPECT_THROW(parseExpr("((((2)((2))))"), InvalidInputException); - EXPECT_THROW(parseExpr("(()())"), InvalidInputException); - EXPECT_THROW(parseExpr("((()()))"), InvalidInputException); - EXPECT_THROW(parseExpr("((((()))))"), InvalidInputException); - EXPECT_THROW(parseExpr("(,) + (,)"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr("(1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(((2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(((2))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((2)))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(2)))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((((2)((2))))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(()())"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((()()))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((((()))))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(,) + (,)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(parseExpr("!2"), InvalidInputException); - EXPECT_THROW(parseExpr("!!2"), InvalidInputException); - EXPECT_THROW(parseExpr("!2!!"), InvalidInputException); - EXPECT_THROW(parseExpr("!(2"), InvalidInputException); - EXPECT_THROW(parseExpr("!(2)"), InvalidInputException); - EXPECT_THROW(parseExpr("2)!"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(2))!"), InvalidInputException); - EXPECT_THROW(parseExpr("!!!!!!"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr("!2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("!!2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("!2!!"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("!(2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("!(2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("2)!"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(2))!"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("!!!!!!"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(parseExpr("esin()"), InvalidInputException); - EXPECT_THROW(parseExpr("(a+b)*()"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr("esin()"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(a+b)*()"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(parseExpr("sin(2,3)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(2,3) + 2"), InvalidInputException); - EXPECT_THROW(parseExpr("cos(sin(2,3))"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(,)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(,2)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(2,)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin()"), InvalidInputException); - EXPECT_THROW(parseExpr("log(1)"), InvalidInputException); - EXPECT_THROW(parseExpr("log()"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr("sin(2,3)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(2,3) + 2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("cos(sin(2,3))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(,)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(,2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(2,)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin()"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("log(1)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("log()"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(parseExpr("(1 = 1) / 2"), InvalidInputException); - EXPECT_THROW(parseExpr("2 + (1 = 2)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(1 = 1)"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(sin(1 = 1))"), InvalidInputException); - EXPECT_THROW(parseExpr("sin(sin(sin(1 = 1)))"), InvalidInputException); - EXPECT_THROW(parseExpr("True/True"), InvalidInputException); - EXPECT_THROW(parseExpr("((1 == 1)) + ((1 == 2))"), InvalidInputException); - EXPECT_THROW(parseExpr("((1 == 1)) - ((1 == 1))"), InvalidInputException); - EXPECT_THROW(parseExpr("((1 == 1)) / ((1 == 1))"), InvalidInputException); - EXPECT_THROW(parseExpr("(5+5)=(2=5)"), InvalidInputException); - EXPECT_THROW(parseExpr("1+(sin(x)<2)"), InvalidInputException); - EXPECT_THROW(parseExpr("1/(sin(x)<2)"), InvalidInputException); - EXPECT_THROW(parseExpr("1+False"), InvalidInputException); - EXPECT_THROW(parseExpr("False+1"), InvalidInputException); - EXPECT_THROW(parseExpr("1=False"), InvalidInputException); - EXPECT_THROW(parseExpr("False=1"), InvalidInputException); - EXPECT_THROW(parseExpr("1&2"), InvalidInputException); - EXPECT_THROW(parseExpr("x+1&x+2"), InvalidInputException); - EXPECT_THROW(parseExpr("x+1&x"), InvalidInputException); - EXPECT_THROW(parseExpr("x&x+2"), InvalidInputException); - EXPECT_THROW(parseExpr("(x&y)=(y&z)"), InvalidInputException); - EXPECT_THROW(parseExpr("derivative(x=y, x)"), InvalidInputException); - EXPECT_THROW(parseExpr("derivative(x&y,x)"), InvalidInputException); - EXPECT_THROW(parseExpr("derivative(True,a)"), InvalidInputException); - EXPECT_THROW(parseExpr("(a+1)_(a>2)"), InvalidInputException); - EXPECT_THROW(parseExpr("(x+1)_1"), InvalidInputException); - EXPECT_THROW(parseExpr("(x*2)_1"), InvalidInputException); - EXPECT_THROW(parseExpr("(x*2)_((x+2)_x)"), InvalidInputException); - EXPECT_THROW(parseExpr("x^x_1"), InvalidInputException); - EXPECT_THROW(parseExpr("E&a"), InvalidInputException); - EXPECT_THROW(parseExpr("~Inf"), InvalidInputException); - EXPECT_THROW(parseExpr("~Undefined"), InvalidInputException); - EXPECT_THROW(parseExpr("a | Undefined"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr("(1 = 1) / 2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("2 + (1 = 2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(1 = 1)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(sin(1 = 1))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("sin(sin(sin(1 = 1)))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("True/True"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((1 == 1)) + ((1 == 2))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((1 == 1)) - ((1 == 1))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("((1 == 1)) / ((1 == 1))"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(5+5)=(2=5)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1+(sin(x)<2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1/(sin(x)<2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1+False"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("False+1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1=False"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("False=1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("1&2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("x+1&x+2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("x+1&x"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("x&x+2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(x&y)=(y&z)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("derivative(x=y, x)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("derivative(x&y,x)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("derivative(True,a)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(a+1)_(a>2)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(x+1)_1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(x*2)_1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("(x*2)_((x+2)_x)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("x^x_1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("E&a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("~Inf"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("~Undefined"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("a | Undefined"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(parseExpr("min()"), InvalidInputException); - EXPECT_THROW(parseExpr("min(True, False)"), InvalidInputException); - EXPECT_THROW(parseExpr("max()"), InvalidInputException); - EXPECT_THROW(parseExpr("max(True, False)"), InvalidInputException); + EXPECT_THAT( + [] { parseExpr("min()"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("min(True, False)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("max()"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { parseExpr("max(True, False)"); }, + testing::ThrowsMessage( + testing::StrEq(""))); } diff --git a/tests/src/expressions/ExpressionTests.cpp b/tests/src/expressions/ExpressionTests.cpp index c690d5d93..2fb09edaa 100644 --- a/tests/src/expressions/ExpressionTests.cpp +++ b/tests/src/expressions/ExpressionTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/Expression.hpp" @@ -36,8 +37,14 @@ TEST(ExpressionTests, stringConstructorTest) { } TEST(ExpressionTests, stringConstructorNegativeTest) { - EXPECT_THROW(Expression(""), InvalidInputException); - EXPECT_THROW(Expression("1+"), InvalidInputException); + EXPECT_THAT( + [] { Expression(""); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Expression("1+"); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(ExpressionTests, setChildrenTest) { @@ -49,7 +56,10 @@ TEST(ExpressionTests, setChildrenTest) { expr.setChildren({Expression("a-a").clone()}); EXPECT_EQ(expr.toString(), "0"); - EXPECT_THROW(expr.setChildren({Variable("a").clone(), Variable("b").clone()}), InvalidInputException); + EXPECT_THAT( + [&] { expr.setChildren({Variable("a").clone(), Variable("b").clone()}); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(ExpressionTests, getFunctionTest) { diff --git a/tests/src/expressions/IExpressionTests.cpp b/tests/src/expressions/IExpressionTests.cpp index 8ba023c3d..6b6bdde0f 100644 --- a/tests/src/expressions/IExpressionTests.cpp +++ b/tests/src/expressions/IExpressionTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/IExpression.hpp" @@ -65,7 +66,10 @@ TEST(IExpressionTests, setChildrenTest) { expr->setChildren({Variable("b").clone()}); EXPECT_EQ(expr->toString(), "b!"); - EXPECT_THROW(expr->setChildren({Variable("b").clone(), Variable("c").clone()}), InvalidInputException); + EXPECT_THAT( + [&] { expr->setChildren({Variable("b").clone(), Variable("c").clone()}); }, + testing::ThrowsMessage( + testing::StrEq(""))); // TODO: implement more tests } @@ -96,9 +100,24 @@ TEST(IExpressionTests, getTypeTest) { } TEST(IExpressionTests, arithmeticTest) { - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) + cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) - cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) * cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(cast(*sinExpr(Integer(1).clone())) / cast(*sinExpr(Integer(1).clone())), InvalidInputException); - EXPECT_THROW(-cast(*sinExpr(Integer(1).clone())), InvalidInputException); + EXPECT_THAT( + [] { cast(*sinExpr(Integer(1).clone())) + cast(*sinExpr(Integer(1).clone())); }, + testing::ThrowsMessage( + testing::StrEq("Arithmetic operations are not permitted for TrigExpression"))); + EXPECT_THAT( + [] { cast(*sinExpr(Integer(1).clone())) - cast(*sinExpr(Integer(1).clone())); }, + testing::ThrowsMessage( + testing::StrEq("Arithmetic operations are not permitted for TrigExpression"))); + EXPECT_THAT( + [] { cast(*sinExpr(Integer(1).clone())) * cast(*sinExpr(Integer(1).clone())); }, + testing::ThrowsMessage( + testing::StrEq("Arithmetic operations are not permitted for TrigExpression"))); + EXPECT_THAT( + [] { cast(*sinExpr(Integer(1).clone())) / cast(*sinExpr(Integer(1).clone())); }, + testing::ThrowsMessage( + testing::StrEq("Arithmetic operations are not permitted for TrigExpression"))); + EXPECT_THAT( + [] { -cast(*sinExpr(Integer(1).clone())); }, + testing::ThrowsMessage( + testing::StrEq("Arithmetic operations are not permitted for TrigExpression"))); } diff --git a/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp b/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp index 4b07788bd..74660f6dc 100644 --- a/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp +++ b/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/interfaces/IBinaryExpression.hpp" @@ -48,11 +49,18 @@ TEST(IBinaryExpressionTests, setChildren) { EXPECT_EQ(*expr.getChildren().front(), Integer(0)); EXPECT_EQ(*expr.getChildren().back(), Integer(0)); - EXPECT_THROW(expr.setChildren({}), InvalidInputFunctionException); - EXPECT_THROW(expr.setChildren({std::make_shared(1)}), InvalidInputFunctionException); - EXPECT_THROW( - expr.setChildren({std::make_shared(1), std::make_shared(1), std::make_shared(1)}), - InvalidInputFunctionException); + EXPECT_THAT( + [&] { expr.setChildren({}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { expr.setChildren({std::make_shared(1)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { expr.setChildren({std::make_shared(1), std::make_shared(1), std::make_shared(1)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IBinaryExpressionTests, toMinimalObjectTest) { diff --git a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp b/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp index 0185cef2f..60fcca71b 100644 --- a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp +++ b/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/interfaces/IPolynomExpression.hpp" @@ -63,7 +64,10 @@ TEST(IPolynomExpressionTests, setChildren) { EXPECT_EQ(*expr.getChildren()[1], Integer(0)); EXPECT_EQ(*expr.getChildren()[2], Integer(0)); - EXPECT_THROW(expr.setChildren({}), InvalidInputFunctionException); + EXPECT_THAT( + [&] { expr.setChildren({}); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IPolynomExpressionTests, toMinimalObjectTest) { diff --git a/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp b/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp index 74aacc033..d6fe3eb78 100644 --- a/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp +++ b/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/interfaces/IUnaryExpression.hpp" @@ -46,9 +47,14 @@ TEST(IUnaryExpressionTests, setChildren) { EXPECT_EQ(expr.getChildren().size(), 1); EXPECT_EQ(*expr.getChildren().front(), Integer(0)); - EXPECT_THROW(expr.setChildren({}), InvalidInputFunctionException); - EXPECT_THROW(expr.setChildren({std::make_shared(1), std::make_shared(1)}), - InvalidInputFunctionException); + EXPECT_THAT( + [&] { expr.setChildren({}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { expr.setChildren({std::make_shared(1), std::make_shared(1)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IUnaryExpressionTests, toMinimalObjectTest) { diff --git a/tests/src/functions/FunctionUtilsTests.cpp b/tests/src/functions/FunctionUtilsTests.cpp index 092b761cb..2a7c023e1 100644 --- a/tests/src/functions/FunctionUtilsTests.cpp +++ b/tests/src/functions/FunctionUtilsTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/Expression.hpp" @@ -27,10 +28,22 @@ TEST(FunctionUtilsTests, makeExpressionPtrsTest) { EXPECT_EQ(expr2->toString(), "cos(a)"); EXPECT_TRUE(is(expr2)); - EXPECT_THROW(makeExpr(Mul(), ArgumentPtrVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Mul(), ArgumentPtrVector{})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentPtrVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentPtrVector{})->toString(), InvalidInputException); + EXPECT_THAT( + [&] { makeExpr(Mul(), ArgumentPtrVector{var})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { makeExpr(Mul(), ArgumentPtrVector{})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { makeExpr(Pow(), ArgumentPtrVector{var})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { makeExpr(Pow(), ArgumentPtrVector{})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(FunctionUtilsTests, makeExpressionRefsTest) { @@ -45,10 +58,22 @@ TEST(FunctionUtilsTests, makeExpressionRefsTest) { EXPECT_EQ(expr2->toString(), "cos(a)"); EXPECT_TRUE(is(expr2)); - EXPECT_THROW(makeExpr(Mul(), ArgumentRefVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Mul(), ArgumentRefVector{})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentRefVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(Pow(), ArgumentRefVector{})->toString(), InvalidInputException); + EXPECT_THAT( + [&] { makeExpr(Mul(), ArgumentRefVector{var})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { makeExpr(Mul(), ArgumentRefVector{})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { makeExpr(Pow(), ArgumentRefVector{var})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { makeExpr(Pow(), ArgumentRefVector{})->toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(FunctionUtilsTests, makeExpressionAnyArgsRefTest) { diff --git a/tests/src/functions/IFunctionTests.cpp b/tests/src/functions/IFunctionTests.cpp index 4add7c030..138131454 100644 --- a/tests/src/functions/IFunctionTests.cpp +++ b/tests/src/functions/IFunctionTests.cpp @@ -27,10 +27,22 @@ TEST(IFunctionTests, callTest) { EXPECT_EQ((*f)(a, c)->toString(), "c + 3"); - EXPECT_THROW((*f)(), InvalidInputFunctionException); - EXPECT_THROW((*f)(a), InvalidInputFunctionException); - EXPECT_THROW((*f)(a, a, a), InvalidInputFunctionException); - EXPECT_THROW((*f)(a, a, a, a, a, a, a), InvalidInputFunctionException); + EXPECT_THAT( + [&] { (*f)(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { (*f)(a); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { (*f)(a, a, a); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { (*f)(a, a, a, a, a, a, a); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IFunctionTests, calVectTest) { @@ -46,10 +58,22 @@ TEST(IFunctionTests, calVectTest) { EXPECT_EQ((*f)({a, c})->toString(), "c + 3"); - EXPECT_THROW((*f)({}), InvalidInputFunctionException); - EXPECT_THROW((*f)({a}), InvalidInputFunctionException); - EXPECT_THROW((*f)({a, a, a}), InvalidInputFunctionException); - EXPECT_THROW((*f)({a, a, a, a, a, a, a}), InvalidInputFunctionException); + EXPECT_THAT( + [&] { (*f)({}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { (*f)({a}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { (*f)({a, a, a}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { (*f)({a, a, a, a, a, a, a}); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IFunctionTests, equalsTest) { diff --git a/tests/src/functions/arithmetic/AbsTests.cpp b/tests/src/functions/arithmetic/AbsTests.cpp index 818695d3b..ef3443395 100644 --- a/tests/src/functions/arithmetic/AbsTests.cpp +++ b/tests/src/functions/arithmetic/AbsTests.cpp @@ -2,6 +2,7 @@ #include #include "fintamath/functions/arithmetic/Abs.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" @@ -63,8 +64,31 @@ TEST(AbsTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "abs(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(1), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(1), Integer(3), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(AbsTests, exprTest) { diff --git a/tests/src/functions/arithmetic/AddTests.cpp b/tests/src/functions/arithmetic/AddTests.cpp index 2fe9654ea..edda7a36e 100644 --- a/tests/src/functions/arithmetic/AddTests.cpp +++ b/tests/src/functions/arithmetic/AddTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/arithmetic/Add.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -53,10 +54,31 @@ TEST(AddTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a + 3"); - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(1), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(1), Integer(3), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(AddTests, exprTest) { diff --git a/tests/src/literals/BooleanTests.cpp b/tests/src/literals/BooleanTests.cpp index 571b5fe98..ed6aae7b7 100644 --- a/tests/src/literals/BooleanTests.cpp +++ b/tests/src/literals/BooleanTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/exceptions/InvalidInputException.hpp" @@ -14,12 +15,26 @@ TEST(BooleanTests, stringConstructorTest) { EXPECT_EQ(Boolean(std::string("True")), true); EXPECT_EQ(Boolean(std::string("False")), false); - EXPECT_THROW(Boolean(std::string("true")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("false")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("10")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("i")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("")), InvalidInputException); - EXPECT_THROW(Boolean(std::string("")), InvalidInputException); + EXPECT_THAT( + [] { Boolean(std::string("true")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Boolean(std::string("false")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Boolean(std::string("10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Boolean(std::string("i")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Boolean(std::string("")); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(BooleanTests, boolConstructorTest) { diff --git a/tests/src/literals/VariableTests.cpp b/tests/src/literals/VariableTests.cpp index 1020fedfa..39fd6b1a0 100644 --- a/tests/src/literals/VariableTests.cpp +++ b/tests/src/literals/VariableTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/exceptions/InvalidInputException.hpp" @@ -16,26 +17,83 @@ TEST(VariableTest, stringIntegerConstructorTest) { EXPECT_EQ(Variable("a", 2).toString(), "a_2"); EXPECT_EQ(Variable("a", Integer("100000000000000000000000000000000000000")).toString(), "a_100000000000000000000000000000000000000"); - EXPECT_THROW(Variable(""), InvalidInputException); - EXPECT_THROW(Variable("A"), InvalidInputException); - EXPECT_THROW(Variable("B"), InvalidInputException); - EXPECT_THROW(Variable("C"), InvalidInputException); - EXPECT_THROW(Variable("1"), InvalidInputException); - EXPECT_THROW(Variable("+"), InvalidInputException); - EXPECT_THROW(Variable("!"), InvalidInputException); - EXPECT_THROW(Variable("["), InvalidInputException); - EXPECT_THROW(Variable("|"), InvalidInputException); - EXPECT_THROW(Variable("10"), InvalidInputException); - EXPECT_THROW(Variable("a1"), InvalidInputException); - EXPECT_THROW(Variable("ba"), InvalidInputException); - EXPECT_THROW(Variable("1e"), InvalidInputException); - EXPECT_THROW(Variable("A1"), InvalidInputException); - EXPECT_THROW(Variable("Bb"), InvalidInputException); - EXPECT_THROW(Variable("1C"), InvalidInputException); + EXPECT_THAT( + [] { Variable(""); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("A"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("B"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("C"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("+"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("!"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("["); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("|"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("10"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("a1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("ba"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("1e"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("A1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("Bb"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("1C"); }, + testing::ThrowsMessage( + testing::StrEq(""))); - EXPECT_THROW(Variable("a", -1), InvalidInputException); - EXPECT_THROW(Variable("a", -2), InvalidInputException); - EXPECT_THROW(Variable("a", Integer("-100000000000000000000000000000000000000")), InvalidInputException); + EXPECT_THAT( + [] { Variable("a", -1); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("a", -2); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Variable("a", Integer("-100000000000000000000000000000000000000")); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(VariableTest, getTypeTest) { diff --git a/tests/src/numbers/ComplexTests.cpp b/tests/src/numbers/ComplexTests.cpp index 1c0869d61..cbaf60f1b 100644 --- a/tests/src/numbers/ComplexTests.cpp +++ b/tests/src/numbers/ComplexTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/exceptions/InvalidInputException.hpp" @@ -54,25 +55,82 @@ TEST(ComplexTests, stringConstructorTest) { EXPECT_EQ(Complex(".1I").toString(), "1/10 I"); EXPECT_EQ(Complex("1.I").toString(), "I"); - EXPECT_THROW(Complex("--10"), InvalidInputException); - EXPECT_THROW(Complex("test"), InvalidInputException); - EXPECT_THROW(Complex(""), InvalidInputException); - EXPECT_THROW(Complex("+"), InvalidInputException); - EXPECT_THROW(Complex("939849.0-0023"), InvalidInputException); - EXPECT_THROW(Complex("a"), InvalidInputException); - EXPECT_THROW(Complex("a.1"), InvalidInputException); - EXPECT_THROW(Complex("1.a"), InvalidInputException); - EXPECT_THROW(Complex("1a.1"), InvalidInputException); - EXPECT_THROW(Complex("1.1a"), InvalidInputException); - EXPECT_THROW(Complex(".1."), InvalidInputException); - EXPECT_THROW(Complex("."), InvalidInputException); - EXPECT_THROW(Complex("--10.-1"), InvalidInputException); - EXPECT_THROW(Complex("10.-1"), InvalidInputException); - EXPECT_THROW(Complex("1-0.1"), InvalidInputException); - EXPECT_THROW(Complex("10-.1"), InvalidInputException); - EXPECT_THROW(Complex("10.--1"), InvalidInputException); - EXPECT_THROW(Complex("1.10.1"), InvalidInputException); - EXPECT_THROW(Complex("0II"), InvalidInputException); + EXPECT_THAT( + [] { Complex("--10"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("test"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(""); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("+"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("939849.0-0023"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("a.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("1.a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("1a.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("1.1a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(".1."); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("."); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("--10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("1-0.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("10-.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("10.--1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("1.10.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex("0II"); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(ComplexTests, intIntConstructorTest) { @@ -105,13 +163,34 @@ TEST(ComplexTests, numberNumberConstructorTest) { EXPECT_EQ(Complex(Real("2.2"), Rational(2, 3)).toString(), "2.2 + 2/3 I"); EXPECT_EQ(Complex(Rational(3, 2), Real("2.2")).toString(), "3/2 + 2.2 I"); - EXPECT_THROW(Complex(Complex(), Complex()), InvalidInputException); - EXPECT_THROW(Complex(Complex(), Integer()), InvalidInputException); - EXPECT_THROW(Complex(Integer(), Complex()), InvalidInputException); - EXPECT_THROW(Complex(Complex(), Rational()), InvalidInputException); - EXPECT_THROW(Complex(Rational(), Complex()), InvalidInputException); - EXPECT_THROW(Complex(Complex(), Real()), InvalidInputException); - EXPECT_THROW(Complex(Real(), Complex()), InvalidInputException); + EXPECT_THAT( + [] { Complex(Complex(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(Complex(), Integer()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(Integer(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(Complex(), Rational()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(Rational(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(Complex(), Real()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(Real(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(ComplexTests, integerConstructorTest) { @@ -441,8 +520,14 @@ TEST(ComplexTests, divideAssignmentOperatorTest) { EXPECT_EQ(Complex(-738, 10) /= Complex(5, 2), Complex(Rational(-3670, 29), Rational(1526, 29))); EXPECT_EQ(Complex(-738, 10) /= Complex(-5, 2), Complex(Rational(3710, 29), Rational(1426, 29))); - EXPECT_THROW(Complex(0, 0) /= Complex(0, 0), UndefinedException); - EXPECT_THROW(Complex(2, 3) /= Complex(0, 0), UndefinedException); + EXPECT_THAT( + [] { Complex(0, 0) /= Complex(0, 0); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Complex(2, 3) /= Complex(0, 0); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(ComplexTests, integerDivideAssignmentOperatorTest) { diff --git a/tests/src/numbers/IIntegerTests.cpp b/tests/src/numbers/IIntegerTests.cpp index 19000ad0c..fee2c7a9c 100644 --- a/tests/src/numbers/IIntegerTests.cpp +++ b/tests/src/numbers/IIntegerTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/numbers/IInteger.hpp" @@ -140,8 +141,14 @@ TEST(IIntegerTests, modTest) { EXPECT_TRUE(is(*m1 % TestIntegerConvertible())); EXPECT_TRUE(is(TestIntegerConvertible() % *m1)); - EXPECT_THROW(*m1 % TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() % *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 % TestInteger(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "%" operator (Integer "10" and TestInteger "test" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestInteger() % *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "%" operator (TestInteger "test" and Integer "10" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a %= 3).toString(), "0"); @@ -164,8 +171,14 @@ TEST(IIntegerTests, bitAndTest) { EXPECT_TRUE(is(*m1 & TestIntegerConvertible())); EXPECT_TRUE(is(TestIntegerConvertible() & *m1)); - EXPECT_THROW(*m1 & TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() & *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 & TestInteger(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "&" operator (Integer "10" and TestInteger "test" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestInteger() & *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "&" operator (TestInteger "test" and Integer "10" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a &= 3).toString(), "0"); @@ -188,8 +201,14 @@ TEST(IIntegerTests, bitOrTest) { EXPECT_TRUE(is(*m1 | TestIntegerConvertible())); EXPECT_TRUE(is(TestIntegerConvertible() | *m1)); - EXPECT_THROW(*m1 | TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() | *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 | TestInteger(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "|" operator (Integer "10" and TestInteger "test" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestInteger() | *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "|" operator (TestInteger "test" and Integer "10" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a |= 3).toString(), "3"); @@ -212,8 +231,14 @@ TEST(IIntegerTests, bitXorTest) { EXPECT_TRUE(is(*m1 ^ TestIntegerConvertible())); EXPECT_TRUE(is(TestIntegerConvertible() ^ *m1)); - EXPECT_THROW(*m1 ^ TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() ^ *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 ^ TestInteger(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "^" operator (Integer "10" and TestInteger "test" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestInteger() ^ *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "^" operator (TestInteger "test" and Integer "10" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a ^= 3).toString(), "3"); @@ -236,8 +261,14 @@ TEST(IIntegerTests, bitLeftShiftTest) { EXPECT_TRUE(is(*m1 << TestIntegerConvertible())); EXPECT_TRUE(is(TestIntegerConvertible() << *m1)); - EXPECT_THROW(*m1 << TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() << *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 << TestInteger(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "<<" operator (Integer "10" and TestInteger "test" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestInteger() << *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of "<<" operator (TestInteger "test" and Integer "10" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a <<= 3).toString(), "0"); @@ -260,8 +291,14 @@ TEST(IIntegerTests, bitRightShiftTest) { EXPECT_TRUE(is(*m1 >> TestIntegerConvertible())); EXPECT_TRUE(is(TestIntegerConvertible() >> *m1)); - EXPECT_THROW(*m1 >> TestInteger(), InvalidInputBinaryOperatorException); - EXPECT_THROW(TestInteger() >> *m1, InvalidInputBinaryOperatorException); + EXPECT_THAT( + [&] { *m1 >> TestInteger(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of ">>" operator (Integer "10" and TestInteger "test" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestInteger() >> *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of ">>" operator (TestInteger "test" and Integer "10" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a >>= 3).toString(), "0"); diff --git a/tests/src/numbers/IntegerFunctionsTests.cpp b/tests/src/numbers/IntegerFunctionsTests.cpp index 8767d4a0e..b3425dede 100644 --- a/tests/src/numbers/IntegerFunctionsTests.cpp +++ b/tests/src/numbers/IntegerFunctionsTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/numbers/Complex.hpp" @@ -83,7 +84,10 @@ TEST(IntegerFunctionsTests, sqrtTest) { EXPECT_EQ(sqrt(Integer("992188888888")), Integer(996086)); EXPECT_EQ(sqrt(Integer("68732648273642987365932706179432649827364")), Integer("262169121510606178721")); - EXPECT_THROW(sqrt(Integer(-9289)), UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(Integer(-9289)); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, sqrtWithRemainderTest) { @@ -113,7 +117,10 @@ TEST(IntegerFunctionsTests, sqrtWithRemainderTest) { EXPECT_EQ(sqrt(Integer("68732648273642987365932706179432649827364"), remainder), Integer("262169121510606178721")); EXPECT_EQ(remainder.toString(), "307087949370856631523"); - EXPECT_THROW(sqrt(Integer(-9289), remainder), UndefinedFunctionException); + EXPECT_THAT( + [&] { sqrt(Integer(-9289), remainder); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, powTest) { @@ -163,10 +170,22 @@ TEST(IntegerFunctionsTests, powTest) { EXPECT_EQ(pow(Complex(6789, 11), Integer(-4)).toString(), "531075666086959/1128212841481282934557153710724 - 860496245400/282053210370320733639288427681 I"); - EXPECT_THROW(pow(Integer(0), Integer(0)), UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Rational(0), Integer(0)), UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real(0), Integer(0)), UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Complex(0), Integer(0)), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { pow(Integer(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Rational(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Complex(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, factorialTest) { @@ -179,8 +198,14 @@ TEST(IntegerFunctionsTests, factorialTest) { EXPECT_EQ(factorial(Integer(10)), 3628800); EXPECT_EQ(factorial(Integer(25)).toString(), "15511210043330985984000000"); - EXPECT_THROW(factorial(Integer(-1)), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-2)), UndefinedUnaryOperatorException); + EXPECT_THAT( + [] { factorial(Integer(-1)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { factorial(Integer(-2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, nthFactorialTest) { @@ -220,10 +245,22 @@ TEST(IntegerFunctionsTests, nthFactorialTest) { EXPECT_EQ(factorial(Integer(10), 10), 10); EXPECT_EQ(factorial(Integer(25), 10).toString(), "1875"); - EXPECT_THROW(factorial(Integer(-1), 1), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-1), 20), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-2), 1), UndefinedUnaryOperatorException); - EXPECT_THROW(factorial(Integer(-2), 20), UndefinedUnaryOperatorException); + EXPECT_THAT( + [] { factorial(Integer(-1), 1); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { factorial(Integer(-1), 20); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { factorial(Integer(-2), 1); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { factorial(Integer(-2), 20); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, factorsTest) { @@ -269,9 +306,18 @@ TEST(IntegerFunctionsTests, factorsTest) { EXPECT_EQ(factorToCountMap[59], 1); EXPECT_EQ(factorToCountMap[Integer("7406060776921378681")], 1); - EXPECT_THROW(factors(-1), UndefinedFunctionException); - EXPECT_THROW(factors(0), UndefinedFunctionException); - EXPECT_THROW(factors(1), UndefinedFunctionException); + EXPECT_THAT( + [] { factors(-1); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { factors(0); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { factors(1); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, combinationsTest) { @@ -279,9 +325,18 @@ TEST(IntegerFunctionsTests, combinationsTest) { EXPECT_EQ(combinations(Integer(10), Integer(7)), 120); EXPECT_EQ(combinations(Integer(15), Integer(2)), 105); - EXPECT_THROW(combinations(Integer(20), Integer(40)), UndefinedFunctionException); - EXPECT_THROW(combinations(Integer(-3), Integer(-8)), UndefinedUnaryOperatorException); - EXPECT_THROW(combinations(Integer(5), Integer(-3)), UndefinedUnaryOperatorException); + EXPECT_THAT( + [] { combinations(Integer(20), Integer(40)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { combinations(Integer(-3), Integer(-8)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { combinations(Integer(5), Integer(-3)); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(IntegerFunctionsTests, multinomialCoefficientTest) { @@ -290,9 +345,24 @@ TEST(IntegerFunctionsTests, multinomialCoefficientTest) { EXPECT_EQ(multinomialCoefficient(Integer(5), {Integer(3), Integer(2)}), 10); EXPECT_EQ(multinomialCoefficient(Integer(12), {Integer(3), Integer(9), Integer(0)}), 220); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(3)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(3), Integer(19), Integer(0)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(0)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(-12), {Integer(3), Integer(9), Integer(0)}), UndefinedFunctionException); - EXPECT_THROW(multinomialCoefficient(Integer(12), {Integer(-3), Integer(9), Integer(0)}), UndefinedFunctionException); + EXPECT_THAT( + [] { multinomialCoefficient(Integer(12), {Integer(3)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { multinomialCoefficient(Integer(12), {Integer(3), Integer(19), Integer(0)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { multinomialCoefficient(Integer(12), {Integer(0)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { multinomialCoefficient(Integer(-12), {Integer(3), Integer(9), Integer(0)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { multinomialCoefficient(Integer(12), {Integer(-3), Integer(9), Integer(0)}); }, + testing::ThrowsMessage( + testing::StrEq(""))); } diff --git a/tests/src/numbers/IntegerTests.cpp b/tests/src/numbers/IntegerTests.cpp index 6642e65f5..1091db1cd 100644 --- a/tests/src/numbers/IntegerTests.cpp +++ b/tests/src/numbers/IntegerTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/numbers/Integer.hpp" @@ -23,10 +24,22 @@ TEST(IntegerTests, stringConstructorTest) { EXPECT_EQ(Integer("00"), 0); EXPECT_EQ(Integer("-00"), 0); - EXPECT_THROW(Integer("--10"), InvalidInputException); - EXPECT_THROW(Integer("test"), InvalidInputException); - EXPECT_THROW(Integer(""), InvalidInputException); - EXPECT_THROW(Integer("+"), InvalidInputException); + EXPECT_THAT( + [] { Integer(""); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Integer "")"))); + EXPECT_THAT( + [] { Integer("--10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Integer "--10")"))); + EXPECT_THAT( + [] { Integer("test"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Integer "test")"))); + EXPECT_THAT( + [] { Integer("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Integer "+")"))); } TEST(IntegerTests, templateConstructorTest) { @@ -439,7 +452,10 @@ TEST(IntegerTests, divideAssignmentOperatorTest) { "89266820855771268403147576567095701074005469808857005026436237359557162582162903447744543426516804" "1405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361")); - EXPECT_THROW(Integer(-25) /= Integer(0), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Integer(-25) /= Integer(0); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "-25" / "0" (division by zero))"))); } TEST(IntegerTests, intDivideAssignmentOperatorTest) { @@ -502,7 +518,10 @@ TEST(IntegerTests, moduloAssignmentOperatorTest) { "83893847267328724673874") %= Integer("1738383928837528673287446238746237943"), Integer("1186817955126284001426922341829394317")); - EXPECT_THROW(Integer(-25) %= Integer(0), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Integer(-25) %= Integer(0); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "-25" % "0" (modulo by zero))"))); } TEST(IntegerTests, intModuloAssignmentOperatorTest) { @@ -612,8 +631,14 @@ TEST(IntegerTests, bitLeftShiftAssignmentOperatorTest) { EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") <<= 5, Integer("386924570874476799999999999999999999775479354813708569600022752")); - EXPECT_THROW(Integer(192) <<= Integer(-5), UndefinedBinaryOperatorException); - EXPECT_THROW(Integer(-192) <<= Integer(-5), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Integer(192) <<= Integer(-5); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "192" / "-5" (negative shift))"))); + EXPECT_THAT( + [] { Integer(-192) <<= Integer(-5); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "-192" / "-5" (negative shift))"))); } TEST(IntegerTests, intBitLeftShiftAssignmentOperatorTest) { @@ -639,8 +664,14 @@ TEST(IntegerTests, bitRightShiftAssignmentOperatorTest) { EXPECT_EQ(Integer("12091392839827399999999999999999999992983729837928392800000711") >>= 5, Integer("377856026244606249999999999999999999780741557435262275000022")); - EXPECT_THROW(Integer(192) >>= Integer(-5), UndefinedBinaryOperatorException); - EXPECT_THROW(Integer(-192) >>= Integer(-5), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Integer(192) >>= Integer(-5); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "192" >> "-5" (negative shift))"))); + EXPECT_THAT( + [] { Integer(-192) >>= Integer(-5); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "-192" >> "-5" (negative shift))"))); } TEST(IntegerTests, intBitRightShiftAssignmentOperatorTest) { diff --git a/tests/src/numbers/NumberAbstractTests.cpp b/tests/src/numbers/NumberAbstractTests.cpp index c3fa499e0..2175f07dd 100644 --- a/tests/src/numbers/NumberAbstractTests.cpp +++ b/tests/src/numbers/NumberAbstractTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/exceptions/UndefinedException.hpp" @@ -17,8 +18,14 @@ TEST(NumberAbstractIntegerTests, divideTest) { EXPECT_EQ((Integer(0) / cast(Real(2)))->toString(), "0"); EXPECT_EQ((Integer(1) / cast(Real(2)))->toString(), "0.5"); - EXPECT_THROW((Integer(0) / cast(Integer(0)))->toString(), UndefinedException); - EXPECT_THROW((Integer(0) / cast(Real(0)))->toString(), UndefinedException); + EXPECT_THAT( + [] { Integer(0) / cast(Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "0" / "0" (division by zero))"))); + EXPECT_THAT( + [] { Integer(0) / cast(Real(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "0.0" / "0.0" (division by zero))"))); } //-------------------------------------------------------------------------------------// @@ -32,8 +39,14 @@ TEST(NumberAbstractRationalTests, divideTest) { EXPECT_EQ((Rational(0) / cast(Real(2)))->toString(), "0"); EXPECT_EQ((Rational(1) / cast(Real(2)))->toString(), "0.5"); - EXPECT_THROW((Rational(0) / cast(Integer(0)))->toString(), UndefinedException); - EXPECT_THROW((Rational(0) / cast(Real(0)))->toString(), UndefinedException); + EXPECT_THAT( + [] { Rational(0) / cast(Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "0" / "0" (division by zero))"))); + EXPECT_THAT( + [] { Rational(0) / cast(Real(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "0.0" / "0.0" (division by zero))"))); } //-------------------------------------------------------------------------------------// diff --git a/tests/src/numbers/RationalTests.cpp b/tests/src/numbers/RationalTests.cpp index f8c73e999..357713a82 100644 --- a/tests/src/numbers/RationalTests.cpp +++ b/tests/src/numbers/RationalTests.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -21,24 +22,78 @@ TEST(RationalTests, stringConstructorTest) { EXPECT_EQ(Rational(".1").toString(), "1/10"); EXPECT_EQ(Rational("1.").toString(), "1"); - EXPECT_THROW(Rational("--10"), InvalidInputException); - EXPECT_THROW(Rational("test"), InvalidInputException); - EXPECT_THROW(Rational(""), InvalidInputException); - EXPECT_THROW(Rational("+"), InvalidInputException); - EXPECT_THROW(Rational("939849.0-0023"), InvalidInputException); - EXPECT_THROW(Rational("a"), InvalidInputException); - EXPECT_THROW(Rational("a.1"), InvalidInputException); - EXPECT_THROW(Rational("1.a"), InvalidInputException); - EXPECT_THROW(Rational("1a.1"), InvalidInputException); - EXPECT_THROW(Rational("1.1a"), InvalidInputException); - EXPECT_THROW(Rational(".1."), InvalidInputException); - EXPECT_THROW(Rational("."), InvalidInputException); - EXPECT_THROW(Rational("--10.-1"), InvalidInputException); - EXPECT_THROW(Rational("10.-1"), InvalidInputException); - EXPECT_THROW(Rational("1-0.1"), InvalidInputException); - EXPECT_THROW(Rational("10-.1"), InvalidInputException); - EXPECT_THROW(Rational("10.--1"), InvalidInputException); - EXPECT_THROW(Rational("1.10.1"), InvalidInputException); + EXPECT_THAT( + [] { Rational(""); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "")"))); + EXPECT_THAT( + [] { Rational("--10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "--10")"))); + EXPECT_THAT( + [] { Rational("test"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "test")"))); + EXPECT_THAT( + [] { Rational("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "+")"))); + EXPECT_THAT( + [] { Rational("939849.0-0023"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "939849.0-0023")"))); + EXPECT_THAT( + [] { Rational("a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "a")"))); + EXPECT_THAT( + [] { Rational("a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "a.1")"))); + EXPECT_THAT( + [] { Rational("1.a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "1.a")"))); + EXPECT_THAT( + [] { Rational("1a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "1a.1")"))); + EXPECT_THAT( + [] { Rational("1.1a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "1.1a")"))); + EXPECT_THAT( + [] { Rational(".1."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational ".1.")"))); + EXPECT_THAT( + [] { Rational("."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational ".")"))); + EXPECT_THAT( + [] { Rational("--10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "--10.-1")"))); + EXPECT_THAT( + [] { Rational("10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "10.-1")"))); + EXPECT_THAT( + [] { Rational("1-0.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "1-0.1")"))); + EXPECT_THAT( + [] { Rational("10-.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "10-.1")"))); + EXPECT_THAT( + [] { Rational("10.--1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "10.--1")"))); + EXPECT_THAT( + [] { Rational("1.10.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid Rational "1.10.1")"))); } TEST(RationalTests, integerIntegerConstructorTest) { @@ -46,7 +101,10 @@ TEST(RationalTests, integerIntegerConstructorTest) { EXPECT_EQ(Rational(2849300, 18493).toString(), "2849300/18493"); EXPECT_EQ(Rational(2849300, -1893).toString(), "-2849300/1893"); - EXPECT_THROW(Rational(23070, 0), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Rational(23070, 0); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "23070" / "0" (division by zero))"))); } TEST(RationalTests, integerConstructorTest) { @@ -212,7 +270,10 @@ TEST(RationalTests, divideAssignmentOperatorTest) { EXPECT_EQ(Rational(738, 10) /= Rational(5, 2), Rational(738, 25)); EXPECT_EQ(Rational(-738, 10) /= Rational(-5, 2), Rational(738, 25)); - EXPECT_THROW(Rational(-738, -10) /= Rational("0"), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Rational(-738, -10) /= Rational("0"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "369/5" / "0" (division by zero))"))); } TEST(RationalTests, integerDivideAssignmentOperatorTest) { diff --git a/tests/src/numbers/RealFunctionsTests.cpp b/tests/src/numbers/RealFunctionsTests.cpp index cdc4be8d0..5a77b0295 100644 --- a/tests/src/numbers/RealFunctionsTests.cpp +++ b/tests/src/numbers/RealFunctionsTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/core/Cache.hpp" @@ -93,10 +94,14 @@ TEST(RealFunctionsTests, floorTest) { EXPECT_EQ(floor(-1 - 1 / getBottom()).toString(), "-2"); - EXPECT_THROW(floor(getTop()), - UndefinedFunctionException); - EXPECT_THROW(floor(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { floor(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { floor(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(floor(1 / getTop()).toString(), "0"); EXPECT_EQ(floor(-1 / getTop()).toString(), @@ -170,10 +175,14 @@ TEST(RealFunctionsTests, ceilTest) { EXPECT_EQ(ceil(-1 - 1 / getBottom()).toString(), "-1"); - EXPECT_THROW(ceil(getTop()), - UndefinedFunctionException); - EXPECT_THROW(ceil(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ceil(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ceil(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(ceil(1 / getTop()).toString(), "1"); EXPECT_EQ(ceil(-1 / getTop()).toString(), @@ -263,46 +272,68 @@ TEST(RealFunctionsTests, sqrtTest) { EXPECT_EQ(sqrt(Real("23525.32323")).toString(), "153.3796701978459725492204121512750781434647796772676747984731910025774620380353585873562153282468402449005481841073883419559395475898767906139439557306692737624706612235430876655932097400345746485358772717813443198131631030112210968228863289213224144876095410020617778466774885899344482470787465483347525492641579485905056875560330297592329863862879918845030254813451236241418098342383111584169389597987963419936486843277917396618643781613363643398613256282148482430926660270155657970283248756900848"); - EXPECT_THROW(sqrt(Real("-0")), - UndefinedFunctionException); - EXPECT_THROW(sqrt(Real(-1)), - UndefinedFunctionException); - EXPECT_THROW(sqrt(Real(-10)), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sqrt(Real(-1)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sqrt(Real(-10)); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sqrt(getBottom()).toString(), "7787033741169900729251715815485773693572833921585377451230548885066769607873479007659071982456633322947892066185977166857642583972097125178340595060116728563374256202600009698063524254105227036090331595060371028923930614245952174706617222746879926470.8510897821851530612877059206724864583284715928797081352754008253316368153779308877986149769954082553680155667453706957387521573664658902203158531980680861391512633677953799840216307772389412518628573193107066033055571314455053475570689817047532784603"); - EXPECT_THROW(sqrt(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sqrt(1 / getBottom()).toString(), "1.2841860369925185169195865952383508057123821807667332113965732899333735192964417864608252585218328774917153021280599859509786581786949635487347411625376722695975048418146219841266294120347267333021747448367685684705244150436777244265866727495790653942061720429576784243367046100069815963928689537008542761364333764862880204579607209976819485622074126185896863972614464760124406252414731669354556859013861276802795992857774887556800764918992498834454139271858853705219677109320158415550275924857185617*10^-250"); - EXPECT_THROW(sqrt(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sqrt(1 + 1 / getBottom()).toString(), "1.0"); EXPECT_EQ(sqrt(1 - 1 / getBottom()).toString(), "0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_THROW(sqrt(-1 + 1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(sqrt(-1 - 1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sqrt(-1 - 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sqrt(getTop()).toString(), "12838650304502567820342847439865633074310503792406078718470723550586214728557638663815746712937333587127496004640597516330302267248830820742443565086264610567153748278274474007832355643130116977702031439768479199109529814956630304548763269465384389756.52053975223085046502607341722170036312711000508017122016275623179708765814713563176019216943962531158532833134883846404994409109602478985370587448336374563571387052781900218402134345188878655222048458591611141484862841724667172384676656109304785616"); - EXPECT_THROW(sqrt(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sqrt(1 / getTop()).toString(), "7.7889807439439008591929713981619621881971392435573811385088347637072345211810942977255979201531668508482901835644432798800170069487225436142800834442509986034840508694607108858414951348906886898011055367223021346068786307215243194670694502011075788038186003443520210828144735797247891719537311773034898064286211749687166104322818682124309519595250930225768952588266953614018071794569009012215771558628143915625887558527587041384073595362951663610913990606444790659372759934196101320638736883335585609*10^-251"); - EXPECT_THROW(sqrt(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sqrt(1 + 1 / getTop()).toString(), "1.0"); EXPECT_EQ(sqrt(1 - 1 / getTop()).toString(), "1.0"); - EXPECT_THROW(sqrt(-1 + 1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(sqrt(-1 - 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sqrt(-1 - 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, powTest) { @@ -360,25 +391,43 @@ TEST(RealFunctionsTests, powTest) { EXPECT_EQ(pow(Real("10"), 1 / Real("-10000")).toString(), "0.99976976799815658635141604638981297541396466984477711459083930684685186989697929041213306336963649014516445226715342205456445791603567419530668529333352385821493766355725683790126843515237328825664519963335505490416683633603244426616970444670188624455993900745976147392132159517393443913064196380170053772066058092785778167974295533857824628460101843381416143605938274800210123785374166454561558791202253353388499943904479146244325732868900825077422806602517570895866818404904976261773431671253269019"); - EXPECT_THROW(pow(Real("0"), Real("0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("0"), Real("-0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-0"), Real("0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-0"), Real("-0")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("0"), Real("-10")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-10"), Real("1.5")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("-0"), Real("1.5")), - UndefinedBinaryOperatorException); - EXPECT_THROW(pow(Real("10"), Real("100000000000000000000")), - UndefinedBinaryOperatorException); - - EXPECT_THROW(pow(2, getBottom()), - UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { pow(Real("0"), Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("0"), Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("-0"), Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("-0"), Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("0"), Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("-10"), Real("1.5")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("-0"), Real("1.5")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { pow(Real("10"), Real("100000000000000000000")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { pow(2, getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(pow(2, -getBottom()).toString(), "0.0"); EXPECT_EQ(pow(2, 1 / getBottom()).toString(), @@ -394,8 +443,10 @@ TEST(RealFunctionsTests, powTest) { EXPECT_EQ(pow(2, -1 - 1 / getBottom()).toString(), "0.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - EXPECT_THROW(pow(2, getTop()), - UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { pow(2, getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(pow(2, -getTop()).toString(), "0.0"); EXPECT_EQ(pow(2, 1 / getTop()).toString(), @@ -430,8 +481,10 @@ TEST(RealFunctionsTests, expTest) { EXPECT_EQ(exp(Real("-10")).toString(), "4.5399929762484851535591515560550610237918088866564969259071305650999421614302281652525004545947782321708055089686028492945199117244520388837183347709414567560990909217007363970181059501783900762968517787030908824365171548448722293652332416020501168264360305604941570107729975354408079403994232932138270780520042710498960354486166066837009201707573208836344679390514026888603880832944976776162030390901503245487645114316303309520493125377657667740067564548767381252875056905722753776283821712841436637*10^-5"); - EXPECT_THROW(exp(getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { exp(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(exp(-getBottom()).toString(), "0.0"); EXPECT_EQ(exp(1 / getBottom()).toString(), @@ -447,8 +500,10 @@ TEST(RealFunctionsTests, expTest) { EXPECT_EQ(exp(-1 - 1 / getBottom()).toString(), "0.36787944117144232159552377016146086744581113103176783450783680169746149574489980335714727434591964374662732527684399520824697579279012900862665358949409878309219436737733811504863899112514561634498771997868447595793974730254989249545323936620796481051464752061229422308916492656660036507457728370553285373838810680478761195682989345449735073931859921661743300356993720820710227751802158499423378169071566767176233660823037612291562375720947000704050973342567757625252803037688616515709365379954274063"); - EXPECT_THROW(exp(getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { exp(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(exp(-getTop()).toString(), "0.0"); EXPECT_EQ(exp(1 / getTop()).toString(), @@ -495,50 +550,80 @@ TEST(RealFunctionsTests, logTest) { EXPECT_EQ(log(Real("0.2435"), Real("0.00000684")).toString(), "8.4188022648009447163225799145503253101352002864631415297742615181622921460652203893252135022820887001341319601850770875520110928757753272796499436866770185110234096367992828394100601687613288221555097697261899842957945949684413331136056597578143523418528905203613881861131482071992287714071407638448773005224414092163126495683427152060080881159486144871539822246244096502129174394529727345020839956353246490469480019902233480738616934001479599668640841126968042303450589052841035577354726797101205172"); - EXPECT_THROW(log(Real("0"), Real("0")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("1"), Real("66")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("-1"), Real("66")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("10"), Real("-10")), - UndefinedFunctionException); - EXPECT_THROW(log(Real("-10"), Real("10")), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(Real("0"), Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(Real("1"), Real("66")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(Real("-1"), Real("66")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(Real("10"), Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(Real("-10"), Real("10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(log(getBottom(), 2).toString(), "0.00060232170720148787335668247421703824233401793451907250732522916773385188954022906541837983996988431059094169862536414811557500495692329813203780906742857930168615297869764675322448206577626017712119000549151745205989997178535528834383829035005402069701450414530378257833776070969021526094444364816945235600935174058268565904524492686376745284448718663559682349198279109942125716899713858375086069625495195599080433207462875895090264590143184205942381892712807641877394970943778378340993960349468596485"); - EXPECT_THROW(log(-getBottom(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-getBottom(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(log(1 / getBottom(), 2).toString(), "-0.00060232170720148787335668247421703824233401793451907250732522916773385188954022906541837983996988431059094169862536414811557500495692329813203780906742857930168615297869764675322448206577626017712119000549151745205989997178535528834383829035005402069701450414530378257833776070969021526094444364816945235600935174058268565904524492686376745284448718663559682349198279109942125716899713858375086069625495195599080433207462875895090264590143184205942381892712807641877394970943778378340993960349468596485"); - EXPECT_THROW(log(-1 / getLogBottom(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-1 / getLogBottom(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(log(1 + 1 / getLogBottom(), 2).toString(), "14963154.342193243093712422680699151218039448432193587925035209260728038442025299193161011575994641480733267603410795076728690433584657628985768067584936488667559367158689971672050622879383900097405635209428211341951760557078825755420138867544380597591843358031587606341538450740374340818539759287918718630178509911678830554597975722879609294487135551363296720303098811247554495036254205298081533919450324265477298924474830320510074612511552543256262421158570339037070105389548400264147722652605567058"); EXPECT_EQ(log(1 - 1 / getLogBottom(), 2).toString(), "-14963153.649046062533766989312806358204380132571285775672422334025760220766251209439677029312401130838446029433818113410281395034922507978017975984060675629138377197348662974614554022611743937520407130897559671111307912059737145360364966233212630661876029704672607678956857740095364811145206406331320973952493609990097452764896860389596820154454690636445526725151914481416015887811174583083122205222815129307965002439358242471444513582333540499948851074193241291292412608104867497408832830908537979595"); - EXPECT_THROW(log(-1 + 1 / getLogBottom(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(-1 - 1 / getLogBottom(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-1 + 1 / getLogBottom(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(-1 - 1 / getLogBottom(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(log(getTop(), 2).toString(), "0.00060179876403741195722267317028855276394958413863600696746297947633334990788320974726870323010323169588434938957603948500307384601018276229818373404501474310740195421987299739513709619111109837324557071587494251284044564219729803312816295558386812381034330050678075348580043519249230961108398858937009744461829681015882625617053962800932198087109777009790513513968156196421213763732007888196867038077809114726287574264983420066015703482789580169600344172129477299815596840195855948016245613690226508255"); - EXPECT_THROW(log(-getTop(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-getTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(log(1 / getTop(), 2).toString(), "-0.00060179876403741195722267317028855276394958413863600696746297947633334990788320974726870323010323169588434938957603948500307384601018276229818373404501474310740195421987299739513709619111109837324557071587494251284044564219729803312816295558386812381034330050678075348580043519249230961108398858937009744461829681015882625617053962800932198087109777009790513513968156196421213763732007888196867038077809114726287574264983420066015703482789580169600344172129477299815596840195855948016245613690226508255"); - EXPECT_THROW(log(-1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(1 + 1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(1 - 1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(-1 + 1 / getLogTop(), 2), - UndefinedFunctionException); - EXPECT_THROW(log(-1 - 1 / getLogTop(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(1 + 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(1 - 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(-1 + 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { log(-1 - 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, lnTest) { @@ -549,44 +634,68 @@ TEST(RealFunctionsTests, lnTest) { EXPECT_EQ(ln(Real("66")).toString(), "4.1896547420264255448744209363458315725446975461204218810739420522614615391015403955545337898127855677446872359746665499983090936202844377734407750132034614375855322466924278989591414054061908800439205842378476964717818785535562556221481423253679976493420852339317987961870493593040854711141491246445359358373722644761959819863963576390829124879365541233265787258798046029241557202934580563944417723930344537189078848697331335312087479189786893021895715688916117667659732380841091142872749455090483267"); - EXPECT_THROW(ln(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(ln(Real("-1")), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ln(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(ln(getBottom()).toString(), "1150.7922963302310752589242362151479313201731416891692833911699400851637036457415027739371939670841652308917357020983836730332705230349503481680214714976474839209077565316325602764151150216708300128886161589992601482604232651461734619835153032025914096909878125883457082637067939111344489500238615160009909178260268499686021249686533307312007952386375303998821252181168668959796267869490105263893896521620725067223980718367681264027500730584855433248242010154290038201336903273791780223593743126300917"); - EXPECT_THROW(ln(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(ln(1 / getBottom()).toString(), "-1150.7922963302310752589242362151479313201731416891692833911699400851637036457415027739371939670841652308917357020983836730332705230349503481680214714976474839209077565316325602764151150216708300128886161589992601482604232651461734619835153032025914096909878125883457082637067939111344489500238615160009909178260268499686021249686533307312007952386375303998821252181168668959796267869490105263893896521620725067223980718367681264027500730584855433248242010154290038201336903273791780223593743126300917"); - EXPECT_THROW(ln(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(ln(1 + 1 / getLogBottom()).toString(), "4.6323600272263608359211448156691072758876883168532246396075018549197775864381748298765365178030226248931374034769820083630251670816629519619538771280826564142288757639085979249471768209927217584931411470222413930228246265766896137048119643681987110433036930098119342190809014298077854480927710521960607704530573579776137719257059197071981057875303104096646125993974912722187860475512221757680333935876388355834671077676526614466116968774936860874832197537416426668522106100035121945103848322706376739*10^-8"); EXPECT_EQ(ln(1 - 1 / getLogBottom()).toString(), "-4.6323602418139649948376866797514572995752197210491058307576641336724719216383352361062914663674587656808848656687346701431219655465277394329551348639843630422542096702434001605272127288895929327215751563898813796074182163877372714057313772012933040704156169358608742070625510148804860304660664175014151072551726215293399858991624334681638597053383486705746061983545762472894857379243882709348125599832720555810145898279618567784920213785469969120637225339355267781491799812225999918525565812072662816*10^-8"); - EXPECT_THROW(ln(-1 + 1 / getLogBottom()), - UndefinedFunctionException); - EXPECT_THROW(ln(-1 - 1 / getLogBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-1 + 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ln(-1 - 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(ln(getTop()).toString(), "1151.7922966635646085924004268024496095309282755109697640151737838982364673175055998951467299258996052465500220510896818993462124890472738694984769323698716068886745193057012811943430642366646091837561108162687936796823299767705815255181578427768061307290354919840683949388317852313255500361482131430137488582877970196536516803839211139492790968508269095773231100312182466822895779683752382008537434837173083611909767545379191434734806361489542919224380933936036537329432840742844554171617404889632642"); - EXPECT_THROW(ln(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(ln(1 / getTop()).toString(), "-1151.7922966635646085924004268024496095309282755109697640151737838982364673175055998951467299258996052465500220510896818993462124890472738694984769323698716068886745193057012811943430642366646091837561108162687936796823299767705815255181578427768061307290354919840683949388317852313255500361482131430137488582877970196536516803839211139492790968508269095773231100312182466822895779683752382008537434837173083611909767545379191434734806361489542919224380933936036537329432840742844554171617404889632642"); - EXPECT_THROW(ln(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(1 - 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(-1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(ln(-1 - 1 / getLogTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ln(1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ln(1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ln(-1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { ln(-1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, lbTest) { @@ -599,44 +708,68 @@ TEST(RealFunctionsTests, lbTest) { EXPECT_EQ(lb(Real("1024")).toString(), "10.0"); - EXPECT_THROW(lb(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(lb(Real("-1")), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lb(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lb(getBottom()).toString(), "1660.2423390088468152391910752389223371556027033502350030047043970665552604033557193348632239845183566271017417710501538215097901794377254202764363841871643747071564808438403849686328703846578940097114426960217287346753381210056644885659785581770910105170063280253795447247762538890216319599066790175392754544932873241866224231658503043157397318916028330680138739335892411716116576564640798839083902475693032164084479471776090955137972737315592315237578699070714960186770111882960267580469773996621113"); - EXPECT_THROW(lb(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lb(1 / getBottom()).toString(), "-1660.2423390088468152391910752389223371556027033502350030047043970665552604033557193348632239845183566271017417710501538215097901794377254202764363841871643747071564808438403849686328703846578940097114426960217287346753381210056644885659785581770910105170063280253795447247762538890216319599066790175392754544932873241866224231658503043157397318916028330680138739335892411716116576564640798839083902475693032164084479471776090955137972737315592315237578699070714960186770111882960267580469773996621113"); - EXPECT_THROW(lb(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lb(1 + 1 / getLogBottom()).toString(), "6.6830828388917342891547486506847285272697011778553511348949644332867998614145798830938470048136194213017431224868715797761885633680790132044146091615119170196741798630401321276786841802843498968365743316373147452925462901218524916301183034992001817086023359871860301036108309491023873401867078175761078204601368178509939844185624097243114009597752846308861275905256459124059713686286528167411921428262024218955687308981115116829854695701605260995123094905260651631487252496425326512975747703200977325*10^-8"); EXPECT_EQ(lb(1 - 1 / getLogBottom()).toString(), "-6.6830831484762066454675431422618825159987009233331409228534171430721783908516912969136729509928481419301908889301013133376453055787330828035242245174918370788506914927006846997402561569218574136561328101264573366071228147749489667517185452979226874060919022014009523263275164170543945098746986850351969607585674398333075312204333527471490256380337562966263984228239648580231885737336077106126682033590185973637834381756120060255959619721822463124707428302867531505814243457204894530719616210924893046*10^-8"); - EXPECT_THROW(lb(-1 + 1 / getLogBottom()), - UndefinedFunctionException); - EXPECT_THROW(lb(-1 - 1 / getLogBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-1 + 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lb(-1 - 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lb(getTop()).toString(), "1661.6850345306344141487530796177690746215158836948925002095220520038185509989931038272246710097629299710429990443367317181033697520479130844014839956432996829364738082384471341579821245656450941161111418270425586144696676643091196292534437222731085099151401430686452988712060138169216117489101036905404477911088920929597538663365923888861719817611791774685691023049143284296171501716483628778816866896852353629726107200682703242297950283551340834724294269534579127490555479536375902006763171420106197"); - EXPECT_THROW(lb(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lb(1 / getTop()).toString(), "-1661.6850345306344141487530796177690746215158836948925002095220520038185509989931038272246710097629299710429990443367317181033697520479130844014839956432996829364738082384471341579821245656450941161111418270425586144696676643091196292534437222731085099151401430686452988712060138169216117489101036905404477911088920929597538663365923888861719817611791774685691023049143284296171501716483628778816866896852353629726107200682703242297950283551340834724294269534579127490555479536375902006763171420106197"); - EXPECT_THROW(lb(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(1 - 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(-1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lb(-1 - 1 / getLogTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lb(1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lb(1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lb(-1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lb(-1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, lgTest) { @@ -649,44 +782,68 @@ TEST(RealFunctionsTests, lgTest) { EXPECT_EQ(lg(Real("25")).toString(), "1.3979400086720376095725222105510139464636202370757829173791450777457836214511509810261454957636276559186310456171380092418104642377329529880006153325906088498709940714916131946763605313767941129976321942036428347656911209362761419072922306009595213783007750749191994733748107570423083053634346546320353476069144129847373649032981457220701061644284621638984199848009038243690805708299360702447477550154183417636180970020056567602790446469998643589641748853427426633159991941589803258308555502090114049"); - EXPECT_THROW(lg(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(lg(Real("-1")), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lg(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lg(getBottom()).toString(), "499.78274411299115434676719965223768779167964136920007055363841585463644188622791943555370510164980964264750094313258593253768816086436746615232975204548281091270192678941451207329501545599209700116287734424296607709230395802024565114215533908757411944516763884090982261616328224420567778290181253387292750617933539643330552558518205798043923795251523923586037612283521406459121448490318126006960906308176149951008770475545170983614291254760922234519816329245038107624609046278865956610110296462324552"); - EXPECT_THROW(lg(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lg(1 / getBottom()).toString(), "-499.78274411299115434676719965223768779167964136920007055363841585463644188622791943555370510164980964264750094313258593253768816086436746615232975204548281091270192678941451207329501545599209700116287734424296607709230395802024565114215533908757411944516763884090982261616328224420567778290181253387292750617933539643330552558518205798043923795251523923586037612283521406459121448490318126006960906308176149951008770475545170983614291254760922234519816329245038107624609046278865956610110296462324552"); - EXPECT_THROW(lg(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lg(1 + 1 / getLogBottom()).toString(), "2.0118083980136059096853434888142725109436709718011389861452655487998101335198937186475792783475983528667713471278999353571427318335463536665832676784887325437368177755415090648923706314921768803261907182208662223893200401867605259641745584319375168426834845475247780539274153193313255028313714813446321763442399999146370680777253992458317214084017722141404310604446853968438354712208344696034596216350581382476247785306793448540127788042183387871859234405690320319579913363050300456144355260913054575*10^-8"); EXPECT_EQ(lg(1 - 1 / getLogBottom()).toString(), "-2.0118084912078182807420902078090487438954699922096761156253211468848051193024573881935808149245464415884943909535208439584744424064895057343999409001554072702232573612470198517753848891829489035460711247341029104077303724685445729129086771709504291590342477175777030466488750254387650200689200176200847160261425426622753483111550954791817472467095433096890416721603648181690701011424585813302233944898337824051565095996050613509755257069316927468635539620462707852017840963058700239856708772770957763*10^-8"); - EXPECT_THROW(lg(-1 + 1 / getLogBottom()), - UndefinedFunctionException); - EXPECT_THROW(lg(-1 - 1 / getLogBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-1 + 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lg(-1 - 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lg(getTop()).toString(), "500.21703873965932033446069388899443301000188758874338645068247369777978188276137722252688424605970600893853927714983535582557236730510225838524295217100484539293318342301289243646059775923458762067839867333175852316509178327044942829214965210822082429417197201185525689704910240757839537066890081621757756380437386048194814809511491445030505791198598921869543591521133770911428148229663487063107650428872664624111572569774068160311266584524855638648630118535214458717640520183965265359385275880778024"); - EXPECT_THROW(lg(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(lg(1 / getTop()).toString(), "-500.21703873965932033446069388899443301000188758874338645068247369777978188276137722252688424605970600893853927714983535582557236730510225838524295217100484539293318342301289243646059775923458762067839867333175852316509178327044942829214965210822082429417197201185525689704910240757839537066890081621757756380437386048194814809511491445030505791198598921869543591521133770911428148229663487063107650428872664624111572569774068160311266584524855638648630118535214458717640520183965265359385275880778024"); - EXPECT_THROW(lg(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(1 - 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(-1 + 1 / getLogTop()), - UndefinedFunctionException); - EXPECT_THROW(lg(-1 - 1 / getLogTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lg(1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lg(1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lg(-1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { lg(-1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, sinTest) { @@ -701,14 +858,22 @@ TEST(RealFunctionsTests, sinTest) { EXPECT_EQ(sin(Real("360")).toString(), "0.95891572341430650775887594775378440067396475320176419597230510239310187233155216762469333666238341968877803078186966928960032096690227561941454486085366726260909801244212617791982769634387261903781883823531474415994524980397676039997066747095237475703837143800063095336626267981859128776133587943412648564335693073303454697354580361100438284186802625914881351877222107015824075695678302538013095447706197595852901261436701189763894410700471281462208671109751813776339466816838916499612073892989487919"); - EXPECT_THROW(sin(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(sin(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(sin(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(sin(Real(-getPi())), - UndefinedFunctionException); + EXPECT_THAT( + [] { sin(Real(2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sin(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sin(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sin(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sin(Real(getPi() / 2)).toString(), "1.0"); EXPECT_EQ(sin(Real(-getPi() / 2)).toString(), @@ -735,14 +900,22 @@ TEST(RealFunctionsTests, sinTest) { EXPECT_EQ(sin(-1 - 1 / getBottom()).toString(), "-0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); - EXPECT_THROW(sin(getTop()), - UndefinedFunctionException); - EXPECT_THROW(sin(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(sin(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(sin(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sin(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sin(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sin(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sin(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sin(1 + 1 / getTop()).toString(), "0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); EXPECT_EQ(sin(1 - 1 / getTop()).toString(), @@ -773,10 +946,14 @@ TEST(RealFunctionsTests, cosTest) { "-1.0"); EXPECT_EQ(cos(Real(-getPi())).toString(), "-1.0"); - EXPECT_THROW(cos(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(cos(Real(-getPi() / 2)), - UndefinedFunctionException); + EXPECT_THAT( + [] { cos(Real(getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cos(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(cos(Real(getPi() / 4)).toString(), "0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028573505477998580298513726729843100736425870932044459930477616461524215435716072541988130181399762570399484362669827316590441482031030762917619752737287514387998086491778761016876592850567718730170424942358019344998534950240751527201389515822712391153424646845931079028923155579833435650650780928449361862"); EXPECT_EQ(cos(Real(-getPi() / 4)).toString(), @@ -799,10 +976,14 @@ TEST(RealFunctionsTests, cosTest) { EXPECT_EQ(cos(-1 - 1 / getBottom()).toString(), "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443917"); - EXPECT_THROW(cos(getTop()), - UndefinedFunctionException); - EXPECT_THROW(cos(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { cos(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cos(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(cos(1 / getTop()).toString(), "1.0"); EXPECT_EQ(cos(-1 / getTop()).toString(), @@ -831,18 +1012,30 @@ TEST(RealFunctionsTests, tanTest) { EXPECT_EQ(tan(Real("1.5")).toString(), "14.101419947171719387646083651987756445659543577235861866123267586089696270414155268648702926309442287045867838594565919691699004491669865025264248980039061351918594865941647830085172090316199132420462962006307262522713747887816074895835112885636990533301440984006371447953191752413056040636010883158885875789200937415934573118249197536454626507188777255849020779992691101711887207194991636234000277717211545383470167900668346883508414041371529451749917009685422130690021955751283209276658434501266213"); - EXPECT_THROW(tan(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(-getPi())), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(tan(Real(-getPi() / 2)), - UndefinedFunctionException); + EXPECT_THAT( + [] { tan(Real(2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(Real(getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(tan(Real(getPi() / 4)).toString(), "1.0"); EXPECT_EQ(tan(Real(-getPi() / 4)).toString(), @@ -865,14 +1058,22 @@ TEST(RealFunctionsTests, tanTest) { EXPECT_EQ(tan(-1 - 1 / getBottom()).toString(), "-1.557407724654902230506974807458360173087250772381520038383946605698861397151727289555099965202242983804633821411748166613323554618124558937606071684548904439293586043167147908036824613274706955597341640610775535247302506796850507041352385144917621481627570027886022450772014016185772130673941664322369016675671795096261088233022485213114835059162969258761611173265010045945634821564335385053259780863154982428906189221075884887892422138520905365610443447236286192544657877827351485077390888070037216"); - EXPECT_THROW(tan(getTop()), - UndefinedFunctionException); - EXPECT_THROW(tan(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(tan(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(tan(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { tan(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tan(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(tan(1 + 1 / getTop()).toString(), "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); EXPECT_EQ(tan(1 - 1 / getTop()).toString(), @@ -895,21 +1096,35 @@ TEST(RealFunctionsTests, cotTest) { EXPECT_EQ(cot(Real("0.001")).toString(), "999.99966666664444444232804211640209502431508213496869579304205077674381954644639520634408395164810974790187059748663056319413799052324462182627171056687766083031520368701013112433153015271276878401509116019338890857459742077956424095491422840422498363560795969002271508729354091645914312319141941002918853623649271992390238327218620139099559359347286220707598821816371457779702994485393706092219607511288539620817165843202653888983899420142454517047661478883062764207608764656613887179725266038933487"); - EXPECT_THROW(cot(Real("0")), - UndefinedFunctionException); - - EXPECT_THROW(cot(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(-getPi())), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(cot(Real(-getPi() / 2)), - UndefinedFunctionException); + EXPECT_THAT( + [] { cot(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { cot(Real(2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(Real(getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(cot(Real(getPi() / 4)).toString(), "1.0"); EXPECT_EQ(cot(Real(-getPi() / 4)).toString(), @@ -932,14 +1147,22 @@ TEST(RealFunctionsTests, cotTest) { EXPECT_EQ(cot(-1 - 1 / getBottom()).toString(), "-0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451217"); - EXPECT_THROW(cot(getTop()), - UndefinedFunctionException); - EXPECT_THROW(cot(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(cot(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(cot(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { cot(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cot(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(cot(1 + 1 / getTop()).toString(), "0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451218"); EXPECT_EQ(cot(1 - 1 / getTop()).toString(), @@ -972,10 +1195,14 @@ TEST(RealFunctionsTests, secTest) { "-1.0"); EXPECT_EQ(sec(Real(-getPi())).toString(), "-1.0"); - EXPECT_THROW(sec(Real(getPi() / 2)), - UndefinedFunctionException); - EXPECT_THROW(sec(Real(-getPi() / 2)), - UndefinedFunctionException); + EXPECT_THAT( + [] { sec(Real(getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sec(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sec(Real(getPi() / 4)).toString(), "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); EXPECT_EQ(sec(Real(-getPi() / 4)).toString(), @@ -998,10 +1225,14 @@ TEST(RealFunctionsTests, secTest) { EXPECT_EQ(sec(-1 - 1 / getBottom()).toString(), "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958767"); - EXPECT_THROW(sec(getTop()), - UndefinedFunctionException); - EXPECT_THROW(sec(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sec(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sec(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sec(1 / getTop()).toString(), "1.0"); EXPECT_EQ(sec(-1 / getTop()).toString(), @@ -1030,17 +1261,27 @@ TEST(RealFunctionsTests, cscTest) { EXPECT_EQ(csc(Real("-1")).toString(), "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101737"); - EXPECT_THROW(csc(Real("0")), - UndefinedFunctionException); - - EXPECT_THROW(csc(Real(2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(csc(Real(-2 * getPi())), - UndefinedFunctionException); - EXPECT_THROW(csc(Real(getPi())), - UndefinedFunctionException); - EXPECT_THROW(csc(Real(-getPi())), - UndefinedFunctionException); + EXPECT_THAT( + [] { csc(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { csc(Real(2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csc(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csc(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csc(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(csc(Real(getPi() / 2)).toString(), "1.0"); EXPECT_EQ(csc(Real(-getPi() / 2)).toString(), @@ -1067,14 +1308,22 @@ TEST(RealFunctionsTests, cscTest) { EXPECT_EQ(csc(-1 - 1 / getBottom()).toString(), "-1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); - EXPECT_THROW(csc(getTop()), - UndefinedFunctionException); - EXPECT_THROW(csc(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(csc(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(csc(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { csc(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csc(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csc(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csc(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(csc(1 + 1 / getTop()).toString(), "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); EXPECT_EQ(csc(1 - 1 / getTop()).toString(), @@ -1099,44 +1348,68 @@ TEST(RealFunctionsTests, asinTest) { EXPECT_EQ(asin(Real("-0.84")).toString(), "-0.99728322237179986604941509532521395934714998516818417157450478882243040040739064902926893714026459287035064571130233073211754382793258492775437715855004671674889185623000769840763429304713098716629852727968827073908276636401276048204827877385901902774150173708596546031159844406856310972438478179578175951803710882156311730333179191202945257138910105504820794989813222587723991409775037600465013785958465561810434613925198365489052649647827967461192622015741352528579453326828887043801608108051477269"); - EXPECT_THROW(asin(Real("10")), - UndefinedFunctionException); - EXPECT_THROW(asin(Real("-10")), - UndefinedFunctionException); - - EXPECT_THROW(asin(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(asin(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asin(Real("10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asin(Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { asin(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asin(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asin(1 / getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); EXPECT_EQ(asin(-1 / getBottom()).toString(), "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(asin(1 + 1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asin(1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asin(1 - 1 / getBottom()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); EXPECT_EQ(asin(-1 + 1 / getBottom()).toString(), "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - EXPECT_THROW(asin(-1 - 1 / getBottom()), - UndefinedFunctionException); - - EXPECT_THROW(asin(getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(-1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asin(1 + 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asin(-1 - 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { asin(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asin(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asin(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asin(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asin(1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asin(1 - 1 / getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); EXPECT_EQ(asin(-1 + 1 / getTop()).toString(), "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); - EXPECT_THROW(asin(-1 - 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asin(-1 - 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, acosTest) { @@ -1151,44 +1424,64 @@ TEST(RealFunctionsTests, acosTest) { EXPECT_EQ(acos(Real("0.54")).toString(), "1.0003592173949747118791376298435469512885913377969497906049204887187423921567895177976022221907050335650845132822965716649845600735516029413986139650461173550128803998067400065310353542792427835105916184592623138459755250330281624455815464611629996440114260012860252020183567009333702645210375334263809552895280288326212717942179665352569519572762060481581698696284766538229040683728130641302999291849537143100925393941523072142724992850232516181797925495768215872066743637596358371283895797058420554"); - EXPECT_THROW(acos(Real("10")), - UndefinedFunctionException); - EXPECT_THROW(acos(Real("-10")), - UndefinedFunctionException); - - EXPECT_THROW(acos(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(acos(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acos(Real("10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acos(Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { acos(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acos(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acos(1 / getBottom()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); EXPECT_EQ(acos(-1 / getBottom()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(acos(1 + 1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acos(1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acos(1 - 1 / getBottom()).toString(), "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); EXPECT_EQ(acos(-1 + 1 / getBottom()).toString(), "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019089640372359109626654798566502707211319370946985199183116327206111697941832567456673383308341695687723186584254926079042617489189536693145085156626317645923939786002762119455196396275564077376997598528804471407147463811172732950453025794670761851619242"); - EXPECT_THROW(acos(-1 - 1 / getBottom()), - UndefinedFunctionException); - - EXPECT_THROW(acos(getTop()), - UndefinedFunctionException); - EXPECT_THROW(acos(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acos(-1 - 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { acos(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acos(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acos(1 / getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(acos(-1 / getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(acos(1 + 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acos(1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acos(1 - 1 / getTop()).toString(), "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); EXPECT_EQ(acos(-1 + 1 / getTop()).toString(), "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019090354957448719769074801411670258845675317644354427277390187470669184627578520053124031899893789647494905415565915303073780628489595150764963580672492560980997155307017069219383588763138881564237000138811161903252708963375042846593538538373681532259612"); - EXPECT_THROW(acos(-1 - 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acos(-1 - 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, atanTest) { @@ -1224,10 +1517,14 @@ TEST(RealFunctionsTests, atanTest) { "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(atan(-getTop()).toString(), "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(atan(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(atan(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { atan(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atan(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(atan(1 + 1 / getTop()).toString(), "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); EXPECT_EQ(atan(1 - 1 / getTop()).toString(), @@ -1248,8 +1545,10 @@ TEST(RealFunctionsTests, acotTest) { EXPECT_EQ(acot(Real("999.9996666666444444423280421164020950243150821349686957930420507767438195464464")).toString(), "0.00099999999999999999999999999999999999999999999999999999999999999999999999999999999520634568183674040783970331582554073275320346626391287599441844855329139555995768197166058821093605951741769596479352976180441333074229850093543964493443860640600490586849713950251489092715413226533897754456153271726325985194450173733913611757889318251097033681593161211552378778014959359303764665491769639631227095346657170959640829846817771528191249797072531699834783539726035526166348364413613552480681028846378824925"); - EXPECT_THROW(acot(Real("0")), - UndefinedFunctionException); + EXPECT_THAT( + [] { acot(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acot(getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); @@ -1268,10 +1567,14 @@ TEST(RealFunctionsTests, acotTest) { EXPECT_EQ(acot(-1 - 1 / getBottom()).toString(), "-0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298727"); - EXPECT_THROW(acot(getTop()), - UndefinedFunctionException); - EXPECT_THROW(acot(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acot(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acot(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acot(1 / getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(acot(-1 / getTop()).toString(), @@ -1298,27 +1601,41 @@ TEST(RealFunctionsTests, asecTest) { EXPECT_EQ(asec(Real("-10")).toString(), "1.670963747956456415576844871092444760667260671917182451878496151190310876793967050967955277030562988946734134176737739291829990877833759136140587878535056524058956706576764088322420219334399421939192714470055959265395299736976094988871700052211659618789403459380175132202886777407283297893841109249077369000993428242193341002075242778034695067183281503984647497682025462516942323899967180141448103403423650549303602217381181878196941943974698615972920812149134256269952350202231220792042427298220536"); - EXPECT_THROW(asec(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(asec(Real("0.54")), - UndefinedFunctionException); - EXPECT_THROW(asec(Real("-0.54")), - UndefinedFunctionException); + EXPECT_THAT( + [] { asec(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asec(Real("0.54")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asec(Real("-0.54")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asec(getBottom()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059745"); EXPECT_EQ(asec(-getBottom()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(asec(1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asec(1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asec(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asec(1 + 1 / getBottom()).toString(), "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_THROW(asec(1 - 1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 + 1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asec(1 - 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asec(-1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asec(-1 - 1 / getBottom()).toString(), "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019089640372359109626654798566502707211319370946985199183116327206111697941832567456673383308341695687723186584254926079042617489189536693145085156626317645923939786002762119455196396275564077376997598528804471407147463811172732950453025794670761851619242"); @@ -1326,16 +1643,24 @@ TEST(RealFunctionsTests, asecTest) { "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(asec(-getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); - EXPECT_THROW(asec(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asec(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asec(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asec(1 + 1 / getTop()).toString(), "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_THROW(asec(1 - 1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(asec(-1 + 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { asec(1 - 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asec(-1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asec(-1 - 1 / getTop()).toString(), "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019090354957448719769074801411670258845675317644354427277390187470669184627578520053124031899893789647494905415565915303073780628489595150764963580672492560980997155307017069219383588763138881564237000138811161903252708963375042846593538538373681532259612"); } @@ -1354,44 +1679,70 @@ TEST(RealFunctionsTests, acscTest) { EXPECT_EQ(acsc(Real("-10")).toString(), "-0.10016742116155979634552317945269331856867597222962954139102385503640267365086255165393786435950445495566009092009658596828306857305846802027790817447081596533381465522579482776964039702292494447400173225565047143242857667273827087197830846957605866421657917591844495789765961408317660109021098467844050670749012508439925356131478229662006802132559932003835231767636019724253209063927510666547734759870712191412072242140463578513825097766880206341364677491794427489516867425935485834642845820671456144"); - EXPECT_THROW(acsc(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(acsc(Real("0.54")), - UndefinedFunctionException); - EXPECT_THROW(acsc(Real("-0.54")), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsc(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(Real("0.54")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(Real("-0.54")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsc(getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); EXPECT_EQ(acsc(-getBottom()).toString(), "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(acsc(1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsc(1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsc(1 + 1 / getBottom()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - EXPECT_THROW(acsc(1 - 1 / getBottom()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 + 1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsc(1 - 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(-1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsc(-1 - 1 / getBottom()).toString(), "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009543912129524492324911746294869466144351334645739492814493392173080120000958159852068569162071237110901347121303126022389964745087204086224350396918759598758653434173964159689735465688654414318032072936064099095247650063335973521689401338531070936559496"); - EXPECT_THROW(acsc(getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsc(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsc(1 + 1 / getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); - EXPECT_THROW(acsc(1 - 1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(acsc(-1 + 1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsc(1 - 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsc(-1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsc(-1 - 1 / getTop()).toString(), "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); } @@ -1412,10 +1763,14 @@ TEST(RealFunctionsTests, sinhTest) { EXPECT_EQ(sinh(Real("-1000000")).toString(), "-1.5166076984010437725432010707090571635419868974067387048030974998931132315932118262378896014238733712231453572791977727160648924261330240557869860774850358098312131563768360829761690407034195827198088986937033466934046726913218958947601036565089018349581925436647068674894225777805207965238477572592464354499304442433954381395399968367300979907629021482576602691540020197706252822827022193134154228496566284261501675246544829778210486724753160797320622498901320808395701922250790368495099757883193218*10^434294"); - EXPECT_THROW(sinh(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(sinh(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sinh(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sinh(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sinh(1 / getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); EXPECT_EQ(sinh(-1 / getBottom()).toString(), @@ -1429,14 +1784,22 @@ TEST(RealFunctionsTests, sinhTest) { EXPECT_EQ(sinh(-1 - 1 / getBottom()).toString(), "-1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); - EXPECT_THROW(sinh(getTop()), - UndefinedFunctionException); - EXPECT_THROW(sinh(-getTop()), - UndefinedFunctionException); - EXPECT_THROW(sinh(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(sinh(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sinh(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sinh(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sinh(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sinh(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sinh(1 + 1 / getTop()).toString(), "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); EXPECT_EQ(sinh(1 - 1 / getTop()).toString(), @@ -1463,10 +1826,14 @@ TEST(RealFunctionsTests, coshTest) { EXPECT_EQ(cosh(Real("-1000000")).toString(), "1.5166076984010437725432010707090571635419868974067387048030974998931132315932118262378896014238733712231453572791977727160648924261330240557869860774850358098312131563768360829761690407034195827198088986937033466934046726913218958947601036565089018349581925436647068674894225777805207965238477572592464354499304442433954381395399968367300979907629021482576602691540020197706252822827022193134154228496566284261501675246544829778210486724753160797320622498901320808395701922250790368495099757883193218*10^434294"); - EXPECT_THROW(cosh(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(cosh(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { cosh(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cosh(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(cosh(1 / getBottom()).toString(), "1.0"); EXPECT_EQ(cosh(-1 / getBottom()).toString(), @@ -1480,10 +1847,14 @@ TEST(RealFunctionsTests, coshTest) { EXPECT_EQ(cosh(-1 - 1 / getBottom()).toString(), "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); - EXPECT_THROW(cosh(getTop()), - UndefinedFunctionException); - EXPECT_THROW(cosh(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { cosh(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { cosh(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(cosh(1 / getTop()).toString(), "1.0"); EXPECT_EQ(cosh(-1 / getTop()).toString(), @@ -1537,10 +1908,14 @@ TEST(RealFunctionsTests, tanhTest) { "1.0"); EXPECT_EQ(tanh(-getTop()).toString(), "-1.0"); - EXPECT_THROW(tanh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(tanh(-1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { tanh(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tanh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(tanh(1 + 1 / getTop()).toString(), "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); EXPECT_EQ(tanh(1 - 1 / getTop()).toString(), @@ -1567,8 +1942,10 @@ TEST(RealFunctionsTests, cothTest) { EXPECT_EQ(coth(Real("-1000000")).toString(), "-1.0"); - EXPECT_THROW(coth(Real("0")), - UndefinedFunctionException); + EXPECT_THAT( + [] { coth(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(coth(getBottom()).toString(), "1.0"); @@ -1591,10 +1968,14 @@ TEST(RealFunctionsTests, cothTest) { "1.0"); EXPECT_EQ(coth(-getTop()).toString(), "-1.0"); - EXPECT_THROW(coth(1 / getTop()), - UndefinedFunctionException); - EXPECT_THROW(coth(-1 / getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { coth(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { coth(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(coth(1 + 1 / getTop()).toString(), "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); EXPECT_EQ(coth(1 - 1 / getTop()).toString(), @@ -1621,10 +2002,14 @@ TEST(RealFunctionsTests, sechTest) { EXPECT_EQ(sech(Real("-1000000")).toString(), "6.5936629561771171579378159382154484171228030133167403192941769797906985007591094541101544505266576590003136623166279624437072289948914410518596660796372850144818311771718689218961756235736614332305572015788134843142823987619684063908579723392812450600316769828831818379538015455924132128248931752957164658625567427893359723762484980284103878781196254875345414062804199987764098081657081303453035863381229295149281777943984386777373544544747833870835791847918279021119342276015780078343555344003180895*10^-434295"); - EXPECT_THROW(sech(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(sech(-getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { sech(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sech(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sech(1 / getBottom()).toString(), "1.0"); EXPECT_EQ(sech(-1 / getBottom()).toString(), @@ -1638,10 +2023,14 @@ TEST(RealFunctionsTests, sechTest) { EXPECT_EQ(sech(-1 - 1 / getBottom()).toString(), "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629435"); - EXPECT_THROW(sech(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(sech(-getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { sech(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { sech(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(sech(1 / getTop()).toString(), "1.0"); EXPECT_EQ(sech(-1 / getTop()).toString(), @@ -1670,13 +2059,19 @@ TEST(RealFunctionsTests, cschTest) { EXPECT_EQ(csch(Real("-1000000")).toString(), "-6.5936629561771171579378159382154484171228030133167403192941769797906985007591094541101544505266576590003136623166279624437072289948914410518596660796372850144818311771718689218961756235736614332305572015788134843142823987619684063908579723392812450600316769828831818379538015455924132128248931752957164658625567427893359723762484980284103878781196254875345414062804199987764098081657081303453035863381229295149281777943984386777373544544747833870835791847918279021119342276015780078343555344003180895*10^-434295"); - EXPECT_THROW(csch(Real("0")), - UndefinedFunctionException); - - EXPECT_THROW(csch(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(-getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { csch(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { csch(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csch(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(csch(1 / getBottom()).toString(), "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); EXPECT_EQ(csch(-1 / getBottom()).toString(), @@ -1690,14 +2085,22 @@ TEST(RealFunctionsTests, cschTest) { EXPECT_EQ(csch(-1 - 1 / getBottom()).toString(), "-0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161073"); - EXPECT_THROW(csch(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(csch(-1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { csch(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csch(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csch(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { csch(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(csch(1 + 1 / getTop()).toString(), "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161074"); EXPECT_EQ(csch(1 - 1 / getTop()).toString(), @@ -1743,10 +2146,14 @@ TEST(RealFunctionsTests, asinhTest) { "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); EXPECT_EQ(asinh(-getTop()).toString(), "-1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_THROW(asinh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asinh(-1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { asinh(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asinh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asinh(1 + 1 / getTop()).toString(), "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); EXPECT_EQ(asinh(1 - 1 / getTop()).toString(), @@ -1771,48 +2178,80 @@ TEST(RealFunctionsTests, acoshTest) { EXPECT_EQ(acosh(Real("10000")).toString(), "9.9034875500361280361141978881122997233496952946044950260923836567032304913473953953515725690020423830616528288365523258767489061828343586434808328114258581397841702325146629897292350467756349150430346767665607862477177574083345392634284879969502968285783359747240559839678639708801405512480837902804708295990543604809597201948371269987208380244777001464587545463324020220343935621295486955507859950839246805950189125008128131560856033583621613460499389134966397916170999800412590099260076143420325062"); - EXPECT_THROW(acosh(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(acosh(Real("-1")), - UndefinedFunctionException); - EXPECT_THROW(acosh(Real("0.5")), - UndefinedFunctionException); - EXPECT_THROW(acosh(Real("-0.5")), - UndefinedFunctionException); + EXPECT_THAT( + [] { acosh(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(Real("0.5")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(Real("-0.5")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acosh(getBottom()).toString(), "1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_THROW(acosh(-getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 / getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acosh(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(-1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acosh(1 + 1 / getBottom()).toString(), "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_THROW(acosh(1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 - 1 / getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acosh(1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(-1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(-1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acosh(getTop()).toString(), "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_THROW(acosh(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acosh(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acosh(1 + 1 / getTop()).toString(), "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_THROW(acosh(1 - 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acosh(-1 - 1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acosh(1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(-1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acosh(-1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, atanhTest) { @@ -1829,44 +2268,68 @@ TEST(RealFunctionsTests, atanhTest) { EXPECT_EQ(atanh(Real("-0.5")).toString(), "-0.54930614433405484569762261846126285232374527891137472586734716681874714660930448343680787740686604439398501453297893287118400211296525991052640093538363870530158138459169068358968684942218047995187128515839795576057279595887533567352747008338779011110158512647344878034505326075282143406901815868664928889118349582739606590907451001505191181506112432637409911299554872624544822902673350442298254287422205950942854382374743353980654291470580108306059200070491275719597438444683992471511278657676648427"); - EXPECT_THROW(atanh(Real("-1")), - UndefinedFunctionException); - EXPECT_THROW(atanh(Real("1")), - UndefinedFunctionException); - - EXPECT_THROW(atanh(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(-getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { atanh(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atanh(Real("1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { atanh(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atanh(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(atanh(1 / getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); EXPECT_EQ(atanh(-1 / getBottom()).toString(), "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(atanh(1 + 1 / getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { atanh(1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(atanh(1 - 1 / getBottom()).toString(), "575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); EXPECT_EQ(atanh(-1 + 1 / getBottom()).toString(), "-575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - EXPECT_THROW(atanh(-1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - - EXPECT_THROW(atanh(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(atanh(1 + 1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { atanh(-1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { atanh(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atanh(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atanh(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atanh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { atanh(1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(atanh(1 - 1 / getTop()).toString(), "576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); EXPECT_EQ(atanh(-1 + 1 / getTop()).toString(), "-576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); - EXPECT_THROW(atanh(-1 - 1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { atanh(-1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, acothTest) { @@ -1883,44 +2346,70 @@ TEST(RealFunctionsTests, acothTest) { EXPECT_EQ(acoth(Real("-1000000")).toString(), "-1.0000000000003333333333335333333333334761904761905873015873016782106782107551337551338218004218004806239512122391378831007790169926393271392163571860919690829874095283975828022345212989041356330600528686215480517790976833658290967943214330423945771447901567838740949898923463959982926831592832320699731200327474460887158676102648452426732872099468392344630693121604911565633353193154827823840273775285323654539196982943585718028584123194242214521410447558728089475965531459210710507581093455074511807*10^-6"); - EXPECT_THROW(acoth(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(acoth(Real("1")), - UndefinedFunctionException); - EXPECT_THROW(acoth(Real("-1")), - UndefinedFunctionException); + EXPECT_THAT( + [] { acoth(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(Real("1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acoth(getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); EXPECT_EQ(acoth(-getBottom()).toString(), "-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); - EXPECT_THROW(acoth(1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 / getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acoth(1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(-1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acoth(1 + 1 / getBottom()).toString(), "575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - EXPECT_THROW(acoth(1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 + 1 / getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acoth(1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(-1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acoth(-1 - 1 / getBottom()).toString(), "-575.74272175539551028417073416830305394412432091176476932264531004732854863385559874477152864704029195921686859155947717938347802163535423936252707112464127994141924205123046585580271103014736084317986975455731232310783119281067307177922368417905807191525684776939935767951658027689427659459083823402236567410576382595638638332008598772202038170521103867845419842459070652311841709471532414988951410142866658753176767285524552767962181004212409771184194710869703118744919681708641622745350352879067105"); - EXPECT_THROW(acoth(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acoth(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acoth(1 + 1 / getTop()).toString(), "576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); - EXPECT_THROW(acoth(1 - 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acoth(-1 + 1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acoth(1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acoth(-1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acoth(-1 - 1 / getTop()).toString(), "-576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); } @@ -1937,44 +2426,72 @@ TEST(RealFunctionsTests, asechTest) { EXPECT_EQ(asech(Real("0.8")).toString(), "0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335011536449795523912047517268157493206515552473413952588295045300709532636664265410423915781495204374043038550080194417064167151864471283996817178454695702627163106454615025720740248163777338963855069526066834113727387372292895649354702576265209885969320196505855476470330679365443254763274495125040607"); - EXPECT_THROW(asech(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(asech(Real("-1")), - UndefinedFunctionException); - - EXPECT_THROW(asech(getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { asech(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { asech(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asech(1 / getBottom()).toString(), "1151.4854435107910205683414683366061078882486418235295386452906200946570972677111974895430572940805839184337371831189543587669560432707084787250541422492825598828384841024609317116054220602947216863597395091146246462156623856213461435584473683581161438305136955387987153590331605537885531891816764680447313482115276519127727666401719754440407634104220773569083968491814130462368341894306482997790282028573331750635353457104910553592436200842481954236838942173940623748983936341728324549070070575813421"); - EXPECT_THROW(asech(-1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(1 + 1 / getBottom()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { asech(-1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asech(1 - 1 / getBottom()).toString(), "1.8161133101249768313059767637749226167016555062135541295428599514579399162477525362449841992214659204923416486740342626879990151285206963843627887984484066329176548338000757254648982552487409334526566762732166521636845007859070742231176086199785002494824233671741808993871471604475449814991979005026904466371335432200684754360612792364909810664574323876073450385968843689808751624105899580384533574694605556028984635741348186918197680661361994642285426418712562403143105149802614347742290494321962424*10^-250"); - EXPECT_THROW(asech(-1 + 1 / getBottom()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-1 - 1 / getBottom()).toString(), - UndefinedFunctionException); - - EXPECT_THROW(asech(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { asech(-1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(-1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { asech(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asech(1 / getTop()).toString(), "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); - EXPECT_THROW(asech(-1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(1 + 1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { asech(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(asech(1 - 1 / getTop()).toString(), "1.1015282205148344113031315962232882607549581369854598556825953939712541702951560855963926471275061487735103376848102315248597150700630765059387426235333495755483505788503115382724106804445536940510466695827205469185322984760109337103739057002978598795971390260446685983828095271655143299592980169999703367652156688155730814358165398832394569722569002490431507814481217842691057439436763109599092031344149400752025936592695703741466909450253591955614422574626565454002410396637850800605126854091903233*10^-250"); - EXPECT_THROW(asech(-1 + 1 / getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(asech(-1 - 1 / getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { asech(-1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { asech(-1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealFunctionsTests, acschTest) { @@ -1993,8 +2510,10 @@ TEST(RealFunctionsTests, acschTest) { EXPECT_EQ(acsch(Real("-10")).toString(), "-0.099834078899207563327303124704769443267712911708825010742382695651591768393613465106348449276903206188498406124677873226665835008446207400450999534936293675240929453784224661129186765218330354629955675698152652769815825877645487030185349956435110130012981123752137217672920058387798058093768737175840538375257997368850237548539261911564149546535903638541338513727379764043253416619589358627380617415202311544469434044730284747059064635906989915828599615256664129116822263249491427784753934869133607176"); - EXPECT_THROW(acsch(Real("0")), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsch(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsch(getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); @@ -2013,10 +2532,14 @@ TEST(RealFunctionsTests, acschTest) { EXPECT_EQ(acsch(-1 - 1 / getBottom()).toString(), "-0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957212"); - EXPECT_THROW(acsch(getTop()).toString(), - UndefinedFunctionException); - EXPECT_THROW(acsch(-getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { acsch(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { acsch(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(acsch(1 / getTop()).toString(), "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); EXPECT_EQ(acsch(-1 / getTop()).toString(), @@ -2066,26 +2589,44 @@ TEST(RealFunctionsTests, tgammaTest) { EXPECT_EQ(tgamma(Real("-10.888")).toString(), "-3.0005493180448293721869822512345553711440749496581172835311328514510130843563454159410327449904102534962687933580402601136163144286923729599616329109973278889155036400167226010992532533509025591412102006858233580038908845631422707177405401193989133451023586269917939276976357523808049579203927948328610335908936407429428225823028618009800997924455338572712470543931305206282199854307120672911338853112757794177468305728016425719152016898292004791645737323685134147712344090181049164725937814247506367*10^-7"); - EXPECT_THROW(tgamma(Real("0")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-1")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-2")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-3")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-32352")), - UndefinedFunctionException); - - EXPECT_THROW(tgamma(Real("1000000000")), - UndefinedFunctionException); - EXPECT_THROW(tgamma(Real("-1000000000")), - UndefinedFunctionException); - - EXPECT_THROW(tgamma(getBottom()), - UndefinedFunctionException); - EXPECT_THROW(tgamma(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { tgamma(Real("0")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(Real("-2")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(Real("-3")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(Real("-32352")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { tgamma(Real("1000000000")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(Real("-1000000000")); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { tgamma(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(tgamma(1 / getBottom()).toString(), "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532.0"); EXPECT_EQ(tgamma(-1 / getBottom()).toString(), @@ -2099,10 +2640,14 @@ TEST(RealFunctionsTests, tgammaTest) { EXPECT_EQ(tgamma(-1 - 1 / getBottom()).toString(), "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532.0"); - EXPECT_THROW(tgamma(getTop()), - UndefinedFunctionException); - EXPECT_THROW(tgamma(-getTop()).toString(), - UndefinedFunctionException); + EXPECT_THAT( + [] { tgamma(getTop()); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { tgamma(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq(""))); EXPECT_EQ(tgamma(1 / getTop()).toString(), "1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500"); EXPECT_EQ(tgamma(-1 / getTop()).toString(), diff --git a/tests/src/numbers/RealTests.cpp b/tests/src/numbers/RealTests.cpp index d13c7a9c3..a12f56be8 100644 --- a/tests/src/numbers/RealTests.cpp +++ b/tests/src/numbers/RealTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/numbers/Real.hpp" @@ -35,30 +36,91 @@ TEST(RealTests, stringConstructorTest) { EXPECT_EQ(Real("0.123456*10^-1000").toString(), "1.23456*10^-1001"); EXPECT_EQ(Real("-0.123456*10^-1000").toString(), "-1.23456*10^-1001"); - EXPECT_THROW(Real("--10"), InvalidInputException); - EXPECT_THROW(Real("test"), InvalidInputException); - EXPECT_THROW(Real(""), InvalidInputException); - EXPECT_THROW(Real("+"), InvalidInputException); - EXPECT_THROW(Real("939849.0-0023"), InvalidInputException); - EXPECT_THROW(Real("a"), InvalidInputException); - EXPECT_THROW(Real("a.1"), InvalidInputException); - EXPECT_THROW(Real("1.a"), InvalidInputException); - EXPECT_THROW(Real("1a.1"), InvalidInputException); - EXPECT_THROW(Real("1.1a"), InvalidInputException); - EXPECT_THROW(Real("--10.-1"), InvalidInputException); - EXPECT_THROW(Real("10.-1"), InvalidInputException); - EXPECT_THROW(Real("1-0.1"), InvalidInputException); - EXPECT_THROW(Real("10-.1"), InvalidInputException); - EXPECT_THROW(Real("10.--1"), InvalidInputException); - EXPECT_THROW(Real("."), InvalidInputException); - EXPECT_THROW(Real("1.2.1"), InvalidInputException); - EXPECT_THROW(Real("2*10^2.2"), InvalidInputException); - EXPECT_THROW(Real("0*10^0"), InvalidInputException); - - EXPECT_THROW(Real("10*10^100000000000000000000"), UndefinedException); + EXPECT_THAT( + [] { Real("--10"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("test"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real(""); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("+"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("939849.0-0023"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("a.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("1.a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("1a.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("1.1a"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("--10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("1-0.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("10-.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("10.--1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("."); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("1.2.1"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("2*10^2.2"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + EXPECT_THAT( + [] { Real("0*10^0"); }, + testing::ThrowsMessage( + testing::StrEq(""))); + + EXPECT_THAT( + [] { Real("10*10^100000000000000000000"); }, + testing::ThrowsMessage( + testing::StrEq(""))); } TEST(RealTests, rationalConstructorTest) { + EXPECT_EQ(Real(Rational(0)).toString(), "0.0"); EXPECT_EQ(Real(Rational(2, 5)).toString(), "0.4"); EXPECT_EQ(Real(Rational(-2, 5)).toString(), "-0.4"); EXPECT_EQ(Real(Rational(30, 10)).toString(), "3.0"); @@ -73,8 +135,11 @@ TEST(RealTests, rationalAssignmentOperatorConstructorTest) { } TEST(RealTests, integerConstructorTest) { + EXPECT_EQ(Real(Integer(0)).toString(), "0.0"); EXPECT_EQ(Real(Integer(2)).toString(), "2.0"); + EXPECT_EQ(Real(Integer(-2)).toString(), "-2.0"); EXPECT_EQ(Real(Integer(10)).toString(), "10.0"); + EXPECT_EQ(Real(Integer(-10)).toString(), "-10.0"); } TEST(RealTests, integerAssignmentOperatorTest) { @@ -866,7 +931,10 @@ TEST(RealTests, toStringPrecisionPrecisionTest) { Real::ScopedSetPrecision setPrecision(10); val = Real("1.3"); - EXPECT_THROW(val.toString(20), InvalidInputException); + EXPECT_THAT( + [&] { val.toString(20); }, + testing::ThrowsMessage( + testing::StrEq("Precision must be <= 10"))); } TEST(RealTests, getOutputPrecisionTest) { @@ -886,8 +954,14 @@ TEST(RealTests, setOutputPrecisionTest) { a.setOutputPrecision(5); EXPECT_EQ(a.getOutputPrecision(), 5); - EXPECT_THROW(a.setOutputPrecision(6), InvalidInputException); - EXPECT_THROW(a.setOutputPrecision(10), InvalidInputException); + EXPECT_THAT( + [&] { a.setOutputPrecision(6); }, + testing::ThrowsMessage( + testing::StrEq("Precision must be <= 5"))); + EXPECT_THAT( + [&] { a.setOutputPrecision(10); }, + testing::ThrowsMessage( + testing::StrEq("Precision must be <= 5"))); } TEST(RealTests, updatePrecisionTest) {