From 7d7f79245e92bd2c0f035e0d7a47ec514003c009 Mon Sep 17 00:00:00 2001 From: fintarin Date: Tue, 9 Apr 2024 12:40:43 +0400 Subject: [PATCH] Rework all exceptions and fix negative zeroes in RealFunctions --- 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 | 9 +- .../exceptions/InvalidInputException.hpp | 64 +- .../exceptions/UndefinedException.hpp | 64 +- include/fintamath/expressions/Expression.hpp | 18 +- .../expressions/ExpressionParser.hpp | 12 - include/fintamath/literals/Boolean.hpp | 9 +- include/fintamath/literals/Variable.hpp | 4 +- include/fintamath/numbers/Integer.hpp | 3 +- .../fintamath/numbers/IntegerFunctions.hpp | 9 +- include/fintamath/numbers/Rational.hpp | 2 +- include/fintamath/numbers/Real.hpp | 13 +- src/fintamath/config/ExpressionConfig.cpp | 4 - src/fintamath/expressions/Expression.cpp | 204 +- .../expressions/FunctionExpression.cpp | 4 +- src/fintamath/expressions/binary/PowExpr.cpp | 2 +- .../interfaces/IBinaryExpression.cpp | 4 +- .../interfaces/IPolynomExpression.cpp | 4 +- .../interfaces/IUnaryExpression.cpp | 4 +- src/fintamath/functions/IFunction.cpp | 5 +- src/fintamath/functions/ntheory/Ceil.cpp | 6 +- src/fintamath/functions/ntheory/Floor.cpp | 6 +- src/fintamath/functions/other/Comma.cpp | 11 +- src/fintamath/literals/Boolean.cpp | 19 +- src/fintamath/literals/Variable.cpp | 28 +- src/fintamath/numbers/Complex.cpp | 43 +- src/fintamath/numbers/Integer.cpp | 57 +- src/fintamath/numbers/IntegerFunctions.cpp | 46 +- src/fintamath/numbers/NumberAbstract.cpp | 4 +- src/fintamath/numbers/NumberUtils.cpp | 3 +- src/fintamath/numbers/Rational.cpp | 55 +- src/fintamath/numbers/Real.cpp | 127 +- src/fintamath/numbers/RealFunctions.cpp | 555 ++--- tests/src/core/IArithmeticTests.cpp | 41 +- tests/src/core/IComparableTests.cpp | 41 +- tests/src/exceptions/ExceptionTests.cpp | 4 +- ...validInputBinaryOperatorExceptionTests.cpp | 13 - .../exceptions/InvalidInputExceptionTests.cpp | 8 +- .../InvalidInputFunctionExceptionTests.cpp | 17 - ...nvalidInputUnaryOperatorExceptionTests.cpp | 17 - .../UndefinedBinaryOperatorExceptionTests.cpp | 13 - .../exceptions/UndefinedExceptionTests.cpp | 8 +- .../UndefinedFunctionExceptionTests.cpp | 17 - .../UndefinedUnaryOperatorExceptionTests.cpp | 17 - .../expressions/ExpressionComparatorTests.cpp | 11 +- .../expressions/ExpressionFunctionsTests.cpp | 26 +- .../src/expressions/ExpressionParserTests.cpp | 621 ++++-- tests/src/expressions/ExpressionTests.cpp | 16 +- .../src/expressions/ExpressionUtilsTests.cpp | 19 +- tests/src/expressions/IExpressionTests.cpp | 5 +- .../interfaces/IBinaryExpressionTests.cpp | 22 +- .../interfaces/IPolynomExpressionTests.cpp | 10 +- .../interfaces/IUnaryExpressionTests.cpp | 16 +- tests/src/functions/FunctionUtilsTests.cpp | 42 +- tests/src/functions/IFunctionTests.cpp | 64 +- tests/src/functions/arithmetic/AbsTests.cpp | 24 +- .../src/functions/arithmetic/AddOperTests.cpp | 30 +- tests/src/functions/arithmetic/AddTests.cpp | 35 +- tests/src/functions/arithmetic/DivTests.cpp | 30 +- .../functions/arithmetic/FracMixedTests.cpp | 34 +- tests/src/functions/arithmetic/FracTests.cpp | 30 +- .../src/functions/arithmetic/MulOperTests.cpp | 30 +- tests/src/functions/arithmetic/MulTests.cpp | 34 +- tests/src/functions/arithmetic/NegTests.cpp | 25 +- tests/src/functions/arithmetic/SignTests.cpp | 24 +- tests/src/functions/arithmetic/SubTests.cpp | 30 +- .../functions/arithmetic/UnaryPlusTests.cpp | 25 +- .../functions/calculus/DerivativeTests.cpp | 33 +- .../src/functions/calculus/IntegralTests.cpp | 31 +- tests/src/functions/calculus/MaxTests.cpp | 40 +- tests/src/functions/calculus/MinTests.cpp | 40 +- tests/src/functions/comparison/EqvTests.cpp | 29 +- .../src/functions/comparison/LessEqvTests.cpp | 29 +- tests/src/functions/comparison/LessTests.cpp | 29 +- .../src/functions/comparison/MoreEqvTests.cpp | 29 +- tests/src/functions/comparison/MoreTests.cpp | 29 +- tests/src/functions/comparison/NeqvTests.cpp | 29 +- tests/src/functions/hyperbolic/AcoshTests.cpp | 24 +- tests/src/functions/hyperbolic/AcothTests.cpp | 24 +- tests/src/functions/hyperbolic/AcschTests.cpp | 24 +- tests/src/functions/hyperbolic/AsechTests.cpp | 24 +- tests/src/functions/hyperbolic/AsinhTests.cpp | 24 +- tests/src/functions/hyperbolic/AtanhTests.cpp | 24 +- tests/src/functions/hyperbolic/CoshTests.cpp | 24 +- tests/src/functions/hyperbolic/CothTests.cpp | 24 +- tests/src/functions/hyperbolic/CschTests.cpp | 24 +- tests/src/functions/hyperbolic/SechTests.cpp | 24 +- tests/src/functions/hyperbolic/SinhTests.cpp | 24 +- tests/src/functions/hyperbolic/TanhTests.cpp | 24 +- tests/src/functions/logarithms/LbTests.cpp | 24 +- tests/src/functions/logarithms/LgTests.cpp | 24 +- tests/src/functions/logarithms/LnTests.cpp | 24 +- tests/src/functions/logarithms/LogTests.cpp | 29 +- tests/src/functions/logic/AndOperTests.cpp | 28 +- tests/src/functions/logic/AndTests.cpp | 34 +- tests/src/functions/logic/EquivTests.cpp | 28 +- tests/src/functions/logic/ImplTests.cpp | 28 +- tests/src/functions/logic/NequivTests.cpp | 28 +- tests/src/functions/logic/NotTests.cpp | 24 +- tests/src/functions/logic/OrOperTests.cpp | 28 +- tests/src/functions/logic/OrTests.cpp | 34 +- tests/src/functions/ntheory/CeilTests.cpp | 24 +- tests/src/functions/ntheory/FloorTests.cpp | 24 +- tests/src/functions/ntheory/ModTests.cpp | 30 +- tests/src/functions/other/CommaTests.cpp | 24 +- tests/src/functions/other/DegTests.cpp | 24 +- tests/src/functions/other/FactorialTests.cpp | 30 +- tests/src/functions/other/IndexTests.cpp | 36 +- tests/src/functions/other/PercentTests.cpp | 24 +- tests/src/functions/powers/ExpTests.cpp | 24 +- tests/src/functions/powers/PowOperTests.cpp | 30 +- tests/src/functions/powers/PowTests.cpp | 30 +- tests/src/functions/powers/RootTests.cpp | 28 +- tests/src/functions/powers/SqrTests.cpp | 24 +- tests/src/functions/powers/SqrtTests.cpp | 24 +- .../src/functions/trigonometry/AcosTests.cpp | 24 +- .../src/functions/trigonometry/AcotTests.cpp | 24 +- .../src/functions/trigonometry/AcscTests.cpp | 27 +- .../src/functions/trigonometry/AsecTests.cpp | 24 +- .../src/functions/trigonometry/AsinTests.cpp | 24 +- .../src/functions/trigonometry/AtanTests.cpp | 24 +- tests/src/functions/trigonometry/CosTests.cpp | 24 +- tests/src/functions/trigonometry/CotTests.cpp | 24 +- tests/src/functions/trigonometry/CscTests.cpp | 24 +- tests/src/functions/trigonometry/SecTests.cpp | 24 +- tests/src/functions/trigonometry/SinTests.cpp | 24 +- tests/src/functions/trigonometry/TanTests.cpp | 24 +- tests/src/literals/BooleanTests.cpp | 27 +- tests/src/literals/VariableTests.cpp | 104 +- tests/src/numbers/ComplexTests.cpp | 141 +- tests/src/numbers/IntegerFunctionsTests.cpp | 106 +- tests/src/numbers/IntegerTests.cpp | 51 +- tests/src/numbers/NumberAbstractTests.cpp | 21 +- tests/src/numbers/RationalTests.cpp | 101 +- tests/src/numbers/RealFunctionsTests.cpp | 1785 +++++++++++------ tests/src/numbers/RealTests.cpp | 137 +- thirdparty/boost-config | 1 + thirdparty/boost-container-hash | 1 + thirdparty/boost-describe | 1 + thirdparty/boost-mp11 | 1 + 143 files changed, 4981 insertions(+), 1919 deletions(-) delete mode 100644 include/fintamath/expressions/ExpressionParser.hpp 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 create mode 160000 thirdparty/boost-config create mode 160000 thirdparty/boost-container-hash create mode 160000 thirdparty/boost-describe create mode 160000 thirdparty/boost-mp11 diff --git a/include/fintamath/core/IArithmetic.hpp b/include/fintamath/core/IArithmetic.hpp index 7d5375a48..fa86386cc 100644 --- a/include/fintamath/core/IArithmetic.hpp +++ b/include/fintamath/core/IArithmetic.hpp @@ -5,10 +5,13 @@ #include #include +#include + #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectClass.hpp" #include "fintamath/core/MathObjectUtils.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..7a0fa91b4 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 the {} operator ({} "{}" and {} "{}" are unconvertible to each other))", + operStr, + this->getClass()->getName(), + this->toString(), + rhs.getClass()->getName(), + rhs.toString())); } private: diff --git a/include/fintamath/core/IComparable.hpp b/include/fintamath/core/IComparable.hpp index 8a630f8bd..dfe3a0c6f 100644 --- a/include/fintamath/core/IComparable.hpp +++ b/include/fintamath/core/IComparable.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include "fintamath/core/IArithmetic.hpp" #include "fintamath/core/MathObjectClass.hpp" #include "fintamath/core/MathObjectUtils.hpp" diff --git a/include/fintamath/core/IComparableCRTP.hpp b/include/fintamath/core/IComparableCRTP.hpp index 2f04164da..98a0dfb4e 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 the comparison operator ({} "{}" and {} "{}" are unconvertible to each other))", + this->getClass()->getName(), + this->toString(), + rhs.getClass()->getName(), + rhs.toString())); } private: diff --git a/include/fintamath/exceptions/Exception.hpp b/include/fintamath/exceptions/Exception.hpp index 9605e835e..6609db4bc 100644 --- a/include/fintamath/exceptions/Exception.hpp +++ b/include/fintamath/exceptions/Exception.hpp @@ -1,14 +1,21 @@ #pragma once #include +#include +#include namespace fintamath { class Exception : public std::exception { public: + explicit Exception(std::string inMessage) noexcept : message(std::move(inMessage)) {} + const char *what() const noexcept override { - return "Something went wrong..."; + return message.data(); } + +private: + std::string message; }; } diff --git a/include/fintamath/exceptions/InvalidInputException.hpp b/include/fintamath/exceptions/InvalidInputException.hpp index 2fb93e578..b80347b83 100644 --- a/include/fintamath/exceptions/InvalidInputException.hpp +++ b/include/fintamath/exceptions/InvalidInputException.hpp @@ -1,8 +1,7 @@ #pragma once -#include #include -#include +#include #include "fintamath/exceptions/Exception.hpp" @@ -10,66 +9,7 @@ namespace fintamath { class InvalidInputException : public Exception { public: - InvalidInputException() noexcept = default; - - explicit InvalidInputException(const std::string &input) noexcept { - content += ": " + input; - } - - const char *what() const noexcept override { - return content.c_str(); - } - -protected: - std::string content = "Invalid input"; -}; - -class InvalidInputFunctionException final : public InvalidInputException { -public: - explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) noexcept { - 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(); - } -}; - -class InvalidInputBinaryOperatorException final : public InvalidInputException { -public: - explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) noexcept { - content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; - } -}; - -class InvalidInputUnaryOperatorException final : public InvalidInputException { -public: - enum class Type : uint8_t { - Prefix, - Postfix, - }; - -public: - explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) noexcept { - switch (type) { - case Type::Prefix: - content += ": " + oper + "(" + rhs + ")"; - break; - case Type::Postfix: - content += ": (" + rhs + ")" + oper; - break; - } - } + explicit InvalidInputException(std::string inMessage) noexcept : Exception(std::move(inMessage)) {} }; } diff --git a/include/fintamath/exceptions/UndefinedException.hpp b/include/fintamath/exceptions/UndefinedException.hpp index 213fb16ea..5c706fbc3 100644 --- a/include/fintamath/exceptions/UndefinedException.hpp +++ b/include/fintamath/exceptions/UndefinedException.hpp @@ -1,8 +1,7 @@ #pragma once -#include #include -#include +#include #include "fintamath/exceptions/Exception.hpp" @@ -10,66 +9,7 @@ namespace fintamath { class UndefinedException : public Exception { public: - UndefinedException() noexcept = default; - - explicit UndefinedException(const std::string &input) noexcept { - content += ": " + input; - } - - const char *what() const noexcept override { - return content.c_str(); - } - -protected: - std::string content = "Undefined"; -}; - -class UndefinedFunctionException final : public UndefinedException { -public: - explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) noexcept { - 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(); - } -}; - -class UndefinedBinaryOperatorException final : public UndefinedException { -public: - explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) noexcept { - content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; - } -}; - -class UndefinedUnaryOperatorException final : public UndefinedException { -public: - enum class Type : uint8_t { - Prefix, - Postfix, - }; - -public: - explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) noexcept { - switch (type) { - case Type::Prefix: - content += ": " + oper + "(" + rhs + ")"; - break; - case Type::Postfix: - content += ": (" + rhs + ")" + oper; - break; - } - } + explicit UndefinedException(std::string inMessage) noexcept : Exception(std::move(inMessage)) {} }; } diff --git a/include/fintamath/expressions/Expression.hpp b/include/fintamath/expressions/Expression.hpp index 181b5ce6d..822a9e25d 100644 --- a/include/fintamath/expressions/Expression.hpp +++ b/include/fintamath/expressions/Expression.hpp @@ -56,7 +56,7 @@ using TermVector = std::vector; using FunctionTermStack = std::stack; -using OperandStack = std::stack>; +using ObjectStack = std::stack>; } @@ -103,17 +103,17 @@ class Expression : public IExpressionCRTP { static detail::TermVector tokensToTerms(detail::TokenVector &tokens); - static detail::OperandStack termsToOperands(detail::TermVector &terms); + static detail::ObjectStack termsToObjects(detail::TermVector &terms); - static std::unique_ptr operandsToObject(detail::OperandStack &operands); + static std::unique_ptr objectsToExpr(detail::ObjectStack &objects); - static std::unique_ptr parseFunction(const std::string &str, size_t argNum); + static std::unique_ptr findFunction(const std::string &str, size_t argNum); - static std::unique_ptr parseOperator(const std::string &str, IOperator::Priority priority); + static std::unique_ptr findOperator(const std::string &str, IOperator::Priority priority); static detail::Term parseTerm(const std::string &str); - static void moveFunctionTermsToOperands(detail::OperandStack &operands, detail::FunctionTermStack &functions, const IOperator *nextOper); + static void moveFunctionTermsToObjects(detail::ObjectStack &objects, detail::FunctionTermStack &functions, const IOperator *nextOper); static void insertMultiplications(detail::TermVector &terms); @@ -135,7 +135,7 @@ class Expression : public IExpressionCRTP { static void validateFunctionArgs(const IFunction &func, const ArgumentPtrVector &args); - static bool doesArgMatch(const MathObjectClass &expectedType, const ArgumentPtr &arg); + static std::pair doesArgMatch(const MathObjectClass &expectedClass, const ArgumentPtr &arg); static ArgumentPtrVector unwrapComma(const ArgumentPtr &child); @@ -143,7 +143,7 @@ class Expression : public IExpressionCRTP { friend std::unique_ptr detail::makeExpr(const IFunction &func, ArgumentPtrVector args); - friend std::unique_ptr parseExpr(const std::string &str); + friend std::unique_ptr parseRawExpr(const std::string &str); friend Expression approximate(const Expression &rhs, unsigned precision); @@ -159,6 +159,8 @@ class Expression : public IExpressionCRTP { mutable bool isSimplified = false; }; +std::unique_ptr parseRawExpr(const std::string &str); + template void Expression::registerExpressionConstructor(ExpressionConstructor constructor) { getExpressionMaker()[Function::getClassStatic()] = [maker = std::move(constructor)](ArgumentPtrVector &&args) { diff --git a/include/fintamath/expressions/ExpressionParser.hpp b/include/fintamath/expressions/ExpressionParser.hpp deleted file mode 100644 index 2be6f27ae..000000000 --- a/include/fintamath/expressions/ExpressionParser.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -#include "fintamath/core/IMathObject.hpp" - -namespace fintamath { - -std::unique_ptr parseExpr(const std::string &str); - -} diff --git a/include/fintamath/literals/Boolean.hpp b/include/fintamath/literals/Boolean.hpp index 41bb81c78..45cb1023a 100644 --- a/include/fintamath/literals/Boolean.hpp +++ b/include/fintamath/literals/Boolean.hpp @@ -13,18 +13,17 @@ class Boolean : public ILiteralCRTP { public: Boolean(); - explicit Boolean(const std::string &str); - template Bool> - Boolean(const Bool val) : name(val ? trueStr : falseStr) { - } + Boolean(const Bool rhs) : val(rhs) {} + + explicit Boolean(std::string_view str); std::string toString() const override; explicit operator bool() const; private: - std::string name; + bool val; static constexpr std::string_view trueStr = "True"; diff --git a/include/fintamath/literals/Variable.hpp b/include/fintamath/literals/Variable.hpp index 9fbfa4dd1..7c7f1c503 100644 --- a/include/fintamath/literals/Variable.hpp +++ b/include/fintamath/literals/Variable.hpp @@ -12,9 +12,9 @@ class Variable : public ILiteralCRTP { FINTAMATH_CLASS_BODY(Variable, ILiteral) public: - explicit Variable(std::string inName); + explicit Variable(std::string_view inName); - explicit Variable(std::string inName, Integer inIndex); + explicit Variable(std::string_view inName, Integer inIndex); std::string toString() const override; diff --git a/include/fintamath/numbers/Integer.hpp b/include/fintamath/numbers/Integer.hpp index 22767819e..5a78aff68 100644 --- a/include/fintamath/numbers/Integer.hpp +++ b/include/fintamath/numbers/Integer.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,7 @@ class Integer : public INumberCRTP { Integer(Backend inBackend); - explicit Integer(std::string str); + explicit Integer(std::string_view str); std::string toString() const override; diff --git a/include/fintamath/numbers/IntegerFunctions.hpp b/include/fintamath/numbers/IntegerFunctions.hpp index bf3dea845..79d51351f 100644 --- a/include/fintamath/numbers/IntegerFunctions.hpp +++ b/include/fintamath/numbers/IntegerFunctions.hpp @@ -13,18 +13,19 @@ namespace fintamath { using FactorToCountMap = std::unordered_map; -// Use exponentiation by squaring with constant auxiliary memory (iterative version). -// https://en.wikipedia.org/wiki/Exponentiation_by_squaring#With_constant_auxiliary_memory. template Lhs> Lhs pow(const Lhs &lhs, Integer rhs) { if (lhs == 0 && rhs == 0) { - throw UndefinedBinaryOperatorException("^", lhs.toString(), rhs.toString()); + throw UndefinedException("pow({}, {}) is undefined (zero to the power of zero)"); } if (rhs < 0) { return pow(1 / lhs, -rhs); } + // Use exponentiation by squaring with constant auxiliary memory (iterative version). + // https://en.wikipedia.org/wiki/Exponentiation_by_squaring#With_constant_auxiliary_memory. + Lhs res(1); Lhs sqr = lhs; @@ -60,6 +61,6 @@ FactorToCountMap factors(Integer rhs, Integer limit = -1); Integer combinations(const Integer &totalNumber, const Integer &choosedNumber); -Integer multinomialCoefficient(const Integer &totalNumber, const std::vector &groupNumbers); +Integer multinomialCoefficient(const std::vector &groupNumbers); } diff --git a/include/fintamath/numbers/Rational.hpp b/include/fintamath/numbers/Rational.hpp index a90b69155..b0e678466 100644 --- a/include/fintamath/numbers/Rational.hpp +++ b/include/fintamath/numbers/Rational.hpp @@ -26,7 +26,7 @@ class Rational : public INumberCRTP { explicit Rational(Integer inNumer, Integer inDenom); - explicit Rational(const std::string &str); + explicit Rational(std::string_view str); std::string toString() const override; diff --git a/include/fintamath/numbers/Real.hpp b/include/fintamath/numbers/Real.hpp index 9f5905627..2cf26ca5b 100644 --- a/include/fintamath/numbers/Real.hpp +++ b/include/fintamath/numbers/Real.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -43,15 +44,13 @@ class Real : public INumberCRTP { Real(Backend inBackend); - Real(std::integral auto rhs) - : backend(rhs), - isNegative(rhs < 0) {} + Real(std::integral auto rhs) : backend(rhs) {} Real(const Rational &rhs); Real(const Integer &rhs); - explicit Real(std::string str); + explicit Real(std::string_view str); std::string toString() const override; @@ -63,6 +62,10 @@ class Real : public INumberCRTP { bool isZero() const; + bool isPosZero() const; + + bool isNegZero() const; + const Backend &getBackend() const noexcept; unsigned getOutputPrecision() const noexcept; @@ -105,8 +108,6 @@ class Real : public INumberCRTP { Backend backend; unsigned outputPrecision = getPrecision(); - - bool isNegative = false; }; } diff --git a/src/fintamath/config/ExpressionConfig.cpp b/src/fintamath/config/ExpressionConfig.cpp index 6474b7b2e..c92adc579 100644 --- a/src/fintamath/config/ExpressionConfig.cpp +++ b/src/fintamath/config/ExpressionConfig.cpp @@ -196,10 +196,6 @@ ExpressionConfig::ExpressionConfig() { const ArgumentPtr &lhs = args.front(); const ArgumentPtr &rhs = args.back(); - if (!indexFunc.doArgsMatch({*lhs, *rhs})) { - throw InvalidInputBinaryOperatorException(indexFunc.toString(), lhs->toString(), rhs->toString()); - } - return Expression(indexFunc(*lhs, *rhs)).clone(); // TODO: looks weird }); diff --git a/src/fintamath/expressions/Expression.cpp b/src/fintamath/expressions/Expression.cpp index f9416cb70..c44b35c4a 100644 --- a/src/fintamath/expressions/Expression.cpp +++ b/src/fintamath/expressions/Expression.cpp @@ -8,16 +8,18 @@ #include #include #include +#include #include #include +#include + #include "fintamath/core/Cache.hpp" #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectClass.hpp" #include "fintamath/core/MathObjectUtils.hpp" #include "fintamath/core/Tokenizer.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" -#include "fintamath/expressions/ExpressionParser.hpp" #include "fintamath/expressions/ExpressionUtils.hpp" #include "fintamath/expressions/FunctionExpression.hpp" #include "fintamath/expressions/IExpression.hpp" @@ -47,7 +49,7 @@ using namespace detail; Expression::Expression() : child(Integer(0).clone()) { } -Expression::Expression(const std::string &str) : child(parseExpr(str)) { +Expression::Expression(const std::string &str) : child(parseRawExpr(str)) { } Expression::Expression(const ArgumentPtr &obj) : child(compress(obj)) { @@ -93,7 +95,10 @@ const ArgumentPtrVector &Expression::getChildren() const { void Expression::setChildren(const ArgumentPtrVector &childVect) { if (childVect.size() != 1) { - throw InvalidInputFunctionException("", argumentVectorToStringVector(childVect)); + throw InvalidInputException(fmt::format( + R"(Unable to set {} {} children (expected 1))", + childVect.size(), + getClassStatic()->getName())); } *this = Expression(childVect.front()); @@ -134,22 +139,26 @@ void Expression::updateStringMutable() const { stringCached = child->toString(); } -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; - } - catch (const InvalidInputException &) { - throw InvalidInputException(str); - } +std::unique_ptr parseRawExpr(const std::string &str) try { + auto tokens = Tokenizer::tokenize(str); + auto terms = Expression::tokensToTerms(tokens); + auto objects = Expression::termsToObjects(terms); + auto expr = Expression::objectsToExpr(objects); + return expr; +} +catch (const InvalidInputException &exc) { + std::string message = exc.what(); + message[0] = static_cast(std::tolower(message[0])); + + throw InvalidInputException(fmt::format( + R"(Unable to parse an expression from "{}" ({}))", + str, + message)); } TermVector Expression::tokensToTerms(TokenVector &tokens) { if (tokens.empty()) { - throw InvalidInputException(""); + throw InvalidInputException("empty input"); } TermVector terms(tokens.size()); @@ -167,8 +176,8 @@ TermVector Expression::tokensToTerms(TokenVector &tokens) { // Use the shunting yard algorithm // https://en.m.wikipedia.org/wiki/Shunting_yard_algorithm -OperandStack Expression::termsToOperands(TermVector &terms) { - OperandStack operands; +ObjectStack Expression::termsToObjects(TermVector &terms) { + ObjectStack objects; FunctionTermStack functions; for (auto &term : terms) { @@ -177,66 +186,72 @@ OperandStack Expression::termsToOperands(TermVector &terms) { functions.emplace(std::move(term), std::optional{}); } else if (term.name == ")") { - moveFunctionTermsToOperands(operands, functions, {}); + moveFunctionTermsToObjects(objects, functions, {}); if (functions.empty()) { - throw InvalidInputException(""); + throw InvalidInputException("bracket mismatch"); } functions.pop(); } else { - throw InvalidInputException(""); + throw InvalidInputException( + fmt::format(R"(invalid term "{}")", + term.name)); } } else if (is(term.value)) { std::optional priority; if (const auto *oper = cast(term.value.get())) { - moveFunctionTermsToOperands(operands, functions, oper); + moveFunctionTermsToObjects(objects, functions, oper); priority = oper->getPriority(); } functions.emplace(std::move(term), priority); } else { - operands.emplace(std::move(term.value)); + objects.emplace(std::move(term.value)); } } - moveFunctionTermsToOperands(operands, functions, {}); + moveFunctionTermsToObjects(objects, functions, {}); if (!functions.empty()) { - throw InvalidInputException(""); + throw InvalidInputException("bracket mismatch"); } - return operands; + return objects; } -std::unique_ptr Expression::operandsToObject(OperandStack &operands) { - if (operands.empty()) { - throw InvalidInputException(""); +std::unique_ptr Expression::objectsToExpr(ObjectStack &objects) { + if (objects.empty()) { + throw InvalidInputException("incomplete expression inside brackets"); } - std::unique_ptr arg = std::move(operands.top()); - operands.pop(); + std::unique_ptr arg = std::move(objects.top()); + objects.pop(); if (is(arg)) { auto func = cast(std::move(arg)); - const ArgumentPtr rhsChild = operandsToObject(operands); + const ArgumentPtr rhsChild = objectsToExpr(objects); if (isBinaryOperator(func.get())) { - const ArgumentPtr lhsChild = operandsToObject(operands); + const ArgumentPtr lhsChild = objectsToExpr(objects); return makeExpr(*func, {lhsChild, rhsChild}); } ArgumentPtrVector children = unwrapComma(rhsChild); if (!func->isVariadic() && func->getArgumentClasses().size() != children.size()) { - func = parseFunction(func->toString(), children.size()); + std::string funcStr = func->toString(); + func = findFunction(funcStr, children.size()); if (!func) { - throw InvalidInputException(""); + throw InvalidInputException(fmt::format( + R"(function "{}" with {} arguments not found)", + funcStr, + children.size())); } } @@ -246,7 +261,7 @@ std::unique_ptr Expression::operandsToObject(OperandStack &operands return arg; } -std::unique_ptr Expression::parseFunction(const std::string &str, const size_t argNum) { +std::unique_ptr Expression::findFunction(const std::string &str, const size_t argNum) { for (auto &func : IFunction::parse(str)) { if (func->getArgumentClasses().size() == argNum) { return std::move(func); @@ -256,7 +271,7 @@ std::unique_ptr Expression::parseFunction(const std::string &str, con return {}; } -auto Expression::parseOperator(const std::string &str, const IOperator::Priority priority) -> std::unique_ptr { +auto Expression::findOperator(const std::string &str, const IOperator::Priority priority) -> std::unique_ptr { for (auto &oper : IOperator::parse(str)) { if (oper->getPriority() == priority) { return std::move(oper); @@ -284,7 +299,7 @@ Term Expression::parseTerm(const std::string &str) { return term; } -void Expression::moveFunctionTermsToOperands(OperandStack &operands, std::stack &functions, const IOperator *nextOper) { +void Expression::moveFunctionTermsToObjects(ObjectStack &objects, std::stack &functions, const IOperator *nextOper) { if (isPrefixOperator(nextOper)) { return; } @@ -295,7 +310,7 @@ void Expression::moveFunctionTermsToOperands(OperandStack &operands, std::stack< !functions.top().priority || *functions.top().priority <= nextOper->getPriority())) { - operands.emplace(std::move(functions.top().term.value)); + objects.emplace(std::move(functions.top().term.value)); functions.pop(); } } @@ -315,26 +330,30 @@ void Expression::insertMultiplications(TermVector &terms) { } void Expression::fixOperatorTypes(TermVector &terms) { - bool isFixed = true; - if (auto &term = terms.front(); is(term.value) && !isPrefixOperator(term.value.get())) { - term.value = parseOperator(term.name, IOperator::Priority::PrefixUnary); - isFixed = static_cast(term.value); + term.value = findOperator(term.name, IOperator::Priority::PrefixUnary); + + if (!term.value) { + throw InvalidInputException(fmt::format( + R"(incomplite expression with operator "{}")", + term.name)); + } } if (auto &term = terms.back(); is(term.value) && !isPostfixOperator(term.value.get())) { - term.value = parseOperator(term.name, IOperator::Priority::PostfixUnary); - isFixed = isFixed && static_cast(term.value); - } + term.value = findOperator(term.name, IOperator::Priority::PostfixUnary); - if (!isFixed) { - throw InvalidInputException(""); + if (!term.value) { + throw InvalidInputException(fmt::format( + R"(incomplite expression with operator "{}")", + term.name)); + } } if (terms.size() < 3) { @@ -349,8 +368,13 @@ void Expression::fixOperatorTypes(TermVector &terms) { !isPrefixOperator(term.value.get()) && !canNextTermBeBinaryOperator(termPrev)) { - term.value = parseOperator(term.name, IOperator::Priority::PrefixUnary); - isFixed = isFixed && term.value; + term.value = findOperator(term.name, IOperator::Priority::PrefixUnary); + + if (!term.value) { + throw InvalidInputException(fmt::format( + R"(incomplite expression with operator "{}")", + term.name)); + } } } @@ -362,13 +386,14 @@ void Expression::fixOperatorTypes(TermVector &terms) { !isPostfixOperator(term.value.get()) && !canPrevTermBeBinaryOperator(termNext)) { - term.value = parseOperator(term.name, IOperator::Priority::PostfixUnary); - isFixed = isFixed && term.value; - } - } + term.value = findOperator(term.name, IOperator::Priority::PostfixUnary); - if (!isFixed) { - throw InvalidInputException(""); + if (!term.value) { + throw InvalidInputException(fmt::format( + R"(incomplite expression with operator "{}")", + term.name)); + } + } } } @@ -453,54 +478,77 @@ Expression::ExpressionMaker &Expression::getExpressionMaker() { void Expression::validateFunctionArgs(const IFunction &func, const ArgumentPtrVector &args) { const ArgumentTypeVector &expectedArgTypes = func.getArgumentClasses(); - if (args.empty() || (!func.isVariadic() && args.size() != expectedArgTypes.size())) { - throw InvalidInputFunctionException(func.toString(), argumentVectorToStringVector(args)); + if (args.size() != expectedArgTypes.size()) { + if (!func.isVariadic()) { + throw InvalidInputException(fmt::format( + R"(Unable to call {} "{}" with {} argument{} (expected {}))", + func.getClass()->getName(), + func.toString(), + args.size(), + args.size() != 1 ? "s" : "", + func.getArgumentClasses().size())); + } + + if (args.empty()) { + throw InvalidInputException(fmt::format( + R"(Unable to call {} "{}" with 0 arguments (expected > 0))", + func.getClass()->getName(), + func.toString())); + } } const bool doesArgSizeMatch = !func.isVariadic() && args.size() == expectedArgTypes.size(); - MathObjectClass expectedType = expectedArgTypes.front(); + MathObjectClass expectedClass = expectedArgTypes.front(); for (size_t i = 0; i < args.size(); i++) { + const ArgumentPtr &arg = args[i]; + if (doesArgSizeMatch) { - expectedType = expectedArgTypes[i]; + expectedClass = expectedArgTypes[i]; } - if (const ArgumentPtr &arg = args[i]; !doesArgMatch(expectedType, arg)) { - throw InvalidInputFunctionException(func.toString(), argumentVectorToStringVector(args)); + if (auto [argClass, doesMatch] = doesArgMatch(expectedClass, arg); !doesMatch) { + throw InvalidInputException(fmt::format( + R"(Unable to call {} "{}" with argument #{} {} "{}" (expected {}))", + func.getClass()->getName(), + func.toString(), + i, + argClass->getName(), + arg->toString(), + expectedClass->getName())); } } } -bool Expression::doesArgMatch(const MathObjectClass &expectedType, const ArgumentPtr &arg) { +std::pair Expression::doesArgMatch(const MathObjectClass &expectedClass, const ArgumentPtr &arg) { if (const auto childExpr = cast(arg)) { - const std::shared_ptr &childFunc = childExpr->getFunction(); - const MathObjectClass childType = childFunc->getReturnClass(); + const MathObjectClass argReturnClass = childExpr->getFunction()->getReturnClass(); - if (childType != Variable::getClassStatic() && - !is(expectedType, childType) && - !is(childType, expectedType)) { + if (argReturnClass != Variable::getClassStatic() && + !is(expectedClass, argReturnClass) && + !is(argReturnClass, expectedClass)) { - return false; + return {argReturnClass, false}; } } - else if (const auto childConst = cast(arg)) { - if (const MathObjectClass childType = childConst->getReturnClass(); - !is(expectedType, childType) && - !is(childType, expectedType)) { + else if (const auto argConst = cast(arg)) { + if (const MathObjectClass argReturnClass = argConst->getReturnClass(); + !is(expectedClass, argReturnClass) && + !is(argReturnClass, expectedClass)) { - return false; + return {argReturnClass, false}; } } else { - if (const MathObjectClass childType = arg->getClass(); - childType != Variable::getClassStatic() && - !is(expectedType, childType)) { + if (const MathObjectClass argClass = arg->getClass(); + argClass != Variable::getClassStatic() && + !is(expectedClass, argClass)) { - return false; + return {argClass, false}; } } - return true; + return {arg->getClass(), true}; } namespace detail { diff --git a/src/fintamath/expressions/FunctionExpression.cpp b/src/fintamath/expressions/FunctionExpression.cpp index 8736acab1..599c88139 100644 --- a/src/fintamath/expressions/FunctionExpression.cpp +++ b/src/fintamath/expressions/FunctionExpression.cpp @@ -79,9 +79,7 @@ ArgumentPtr FunctionExpression::simplifyRec(bool isPostSimplify) const { } void FunctionExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != func->getArgumentClasses().size()) { - throw InvalidInputFunctionException(func->toString(), argumentVectorToStringVector(childVect)); - } + (void)makeExpr(*func, childVect); children = childVect; } diff --git a/src/fintamath/expressions/binary/PowExpr.cpp b/src/fintamath/expressions/binary/PowExpr.cpp index 0be2aa51a..f6ced41af 100644 --- a/src/fintamath/expressions/binary/PowExpr.cpp +++ b/src/fintamath/expressions/binary/PowExpr.cpp @@ -191,7 +191,7 @@ ArgumentPtr PowExpr::sumPolynomSimplify(const ArgumentPtr &expr, const Integer & bitNumber = generateNextNumber(bitNumber); ArgumentPtrVector mulExprChildren; - mulExprChildren.emplace_back(multinomialCoefficient(power, vectOfPows).clone()); + mulExprChildren.emplace_back(multinomialCoefficient(vectOfPows).clone()); for (size_t i = 0; i < variableCount; i++) { ArgumentPtr powExprChild = powExpr(polynom[i], vectOfPows[i].clone()); diff --git a/src/fintamath/expressions/interfaces/IBinaryExpression.cpp b/src/fintamath/expressions/interfaces/IBinaryExpression.cpp index 64333a0ef..1157ea05b 100644 --- a/src/fintamath/expressions/interfaces/IBinaryExpression.cpp +++ b/src/fintamath/expressions/interfaces/IBinaryExpression.cpp @@ -98,9 +98,7 @@ IBinaryExpression::SimplifyFunctionVector IBinaryExpression::getFunctionsForPost } void IBinaryExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != 2) { - throw InvalidInputFunctionException(toString(), argumentVectorToStringVector(childVect)); - } + (void)makeExpr(*func, childVect); lhsChild = childVect[0]; rhsChild = childVect[1]; diff --git a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp index 9a7b48cf7..0df3b042f 100644 --- a/src/fintamath/expressions/interfaces/IPolynomExpression.cpp +++ b/src/fintamath/expressions/interfaces/IPolynomExpression.cpp @@ -40,9 +40,7 @@ const ArgumentPtrVector &IPolynomExpression::getChildren() const { } void IPolynomExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.empty()) { - throw InvalidInputFunctionException(toString(), {}); - } + (void)makeExpr(*func, childVect); children = childVect; } diff --git a/src/fintamath/expressions/interfaces/IUnaryExpression.cpp b/src/fintamath/expressions/interfaces/IUnaryExpression.cpp index e8a12afcc..3b28593a2 100644 --- a/src/fintamath/expressions/interfaces/IUnaryExpression.cpp +++ b/src/fintamath/expressions/interfaces/IUnaryExpression.cpp @@ -96,9 +96,7 @@ ArgumentPtr IUnaryExpression::simplifyRec(const bool isPostSimplify) const { } void IUnaryExpression::setChildren(const ArgumentPtrVector &childVect) { - if (childVect.size() != 1) { - throw InvalidInputFunctionException(toString(), argumentVectorToStringVector(childVect)); - } + (void)makeExpr(*func, childVect); child = childVect.front(); } diff --git a/src/fintamath/functions/IFunction.cpp b/src/fintamath/functions/IFunction.cpp index 4ada3680b..2ae2f63c1 100644 --- a/src/fintamath/functions/IFunction.cpp +++ b/src/fintamath/functions/IFunction.cpp @@ -1,9 +1,8 @@ #include "fintamath/functions/IFunction.hpp" -#include -#include -#include +#include +#include "fintamath/exceptions/InvalidInputException.hpp" #include "fintamath/functions/FunctionArguments.hpp" namespace fintamath { diff --git a/src/fintamath/functions/ntheory/Ceil.cpp b/src/fintamath/functions/ntheory/Ceil.cpp index 17cf98501..04d5559e5 100644 --- a/src/fintamath/functions/ntheory/Ceil.cpp +++ b/src/fintamath/functions/ntheory/Ceil.cpp @@ -41,9 +41,13 @@ std::unique_ptr Ceil::multiCeilSimplify(const INumber &rhs) { }); outMultiCeil.add([](const Real &inRhs) { + if (inRhs.isZero()) { + return std::unique_ptr{}; + } + Integer res = ceil(inRhs); - if (abs(inRhs) == Real(abs(res))) { + if (inRhs == res) { return std::unique_ptr{}; } diff --git a/src/fintamath/functions/ntheory/Floor.cpp b/src/fintamath/functions/ntheory/Floor.cpp index 93af1aa48..c78f620c5 100644 --- a/src/fintamath/functions/ntheory/Floor.cpp +++ b/src/fintamath/functions/ntheory/Floor.cpp @@ -41,9 +41,13 @@ std::unique_ptr Floor::multiFloorSimplify(const INumber &rhs) { }); outMultiFloor.add([](const Real &inRhs) { + if (inRhs.isZero()) { + return std::unique_ptr{}; + } + Integer res = floor(inRhs); - if (abs(inRhs) == Real(abs(res))) { + if (inRhs == res) { return std::unique_ptr{}; } diff --git a/src/fintamath/functions/other/Comma.cpp b/src/fintamath/functions/other/Comma.cpp index 5c277c80e..9c93c372b 100644 --- a/src/fintamath/functions/other/Comma.cpp +++ b/src/fintamath/functions/other/Comma.cpp @@ -2,6 +2,8 @@ #include +#include + #include "fintamath/core/IMathObject.hpp" #include "fintamath/functions/FunctionArguments.hpp" @@ -9,11 +11,10 @@ namespace fintamath { FINTAMATH_CLASS_IMPLEMENTATION(Comma) -std::unique_ptr Comma::call(const ArgumentRefVector &argVect) const { - const auto &lhs = argVect.front().get(); - const auto &rhs = argVect.back().get(); - - throw InvalidInputBinaryOperatorException(toString(), lhs.toString(), rhs.toString()); +std::unique_ptr Comma::call(const ArgumentRefVector & /*argVect*/) const { + throw InvalidInputException(fmt::format( + R"(Calling {} directly is not allowed)", + getClassStatic()->getName())); } } diff --git a/src/fintamath/literals/Boolean.cpp b/src/fintamath/literals/Boolean.cpp index 3b4869cc3..e9b7ff32f 100644 --- a/src/fintamath/literals/Boolean.cpp +++ b/src/fintamath/literals/Boolean.cpp @@ -1,28 +1,35 @@ #include "fintamath/literals/Boolean.hpp" +#include + +#include + #include "fintamath/exceptions/InvalidInputException.hpp" namespace fintamath { FINTAMATH_CLASS_IMPLEMENTATION(Boolean) -Boolean::Boolean() : name(falseStr) { +Boolean::Boolean() : val(false) { } -Boolean::Boolean(const std::string &str) { +Boolean::Boolean(const std::string_view str) { if (str != trueStr && str != falseStr) { - throw InvalidInputException(str); + throw InvalidInputException(fmt::format( + R"(Unable to parse {} from "{}" (expected "True" or "False"))", + getClassStatic()->getName(), + str)); } - name = str; + val = str == trueStr; } std::string Boolean::toString() const { - return name; + return val ? std::string(trueStr) : std::string(falseStr); } Boolean::operator bool() const { - return name == trueStr; + return val; } } diff --git a/src/fintamath/literals/Variable.cpp b/src/fintamath/literals/Variable.cpp index 4de6f9071..3984b3b05 100644 --- a/src/fintamath/literals/Variable.cpp +++ b/src/fintamath/literals/Variable.cpp @@ -1,8 +1,11 @@ #include "fintamath/literals/Variable.hpp" #include +#include #include +#include + #include "fintamath/exceptions/InvalidInputException.hpp" #include "fintamath/numbers/Integer.hpp" @@ -10,28 +13,31 @@ namespace fintamath { FINTAMATH_CLASS_IMPLEMENTATION(Variable) -Variable::Variable(std::string inName) { - if (inName.size() != 1) { - throw InvalidInputException(inName); - } - - if (const char ch = inName.front(); ch < 'a' || ch > 'z') { - throw InvalidInputException(inName); +Variable::Variable(std::string_view inName) { + if (inName.size() != 1 || inName.front() < 'a' || inName.front() > 'z') { + throw InvalidInputException(fmt::format( + R"(Unable to parse {} name from "{}" (expected single English lowercase letter))", + getClassStatic()->getName(), + inName)); } - name = std::move(inName); + name = std::string(inName); } -Variable::Variable(std::string inName, Integer inIndex) : Variable(std::move(inName)) { +Variable::Variable(std::string_view inName, Integer inIndex) : Variable(inName) { if (inIndex < 0) { - throw InvalidInputException(name + "_" + inIndex.toString()); + throw InvalidInputException(fmt::format( + R"(Negative {} index {} is not allowed)", + getClassStatic()->getName(), + inIndex.toString())); } index = std::move(inIndex); } std::string Variable::toString() const { - return name + (index != -1 ? "_" + index.toString() : ""); + std::string indexStr = index != -1 ? fmt::format("_{}", index.toString()) : ""; + return fmt::format("{}{}", name, indexStr); } } diff --git a/src/fintamath/numbers/Complex.cpp b/src/fintamath/numbers/Complex.cpp index ddc4a3d2f..42c67a77a 100644 --- a/src/fintamath/numbers/Complex.cpp +++ b/src/fintamath/numbers/Complex.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "fintamath/core/Converter.hpp" #include "fintamath/core/IMathObject.hpp" #include "fintamath/core/MathObjectUtils.hpp" @@ -31,17 +33,15 @@ Complex &Complex::operator=(const Complex &rhs) { return *this; } -Complex::Complex(const std::string &str) { - if (!str.empty() && str.back() == 'I') { - im = parseNonComplexNumber(str.substr(0, str.size() - 1)); - } - else { - re = parseNonComplexNumber(str); +Complex::Complex(const INumber &inRe, const INumber &inIm) { + if (is(inRe) || is(inIm)) { + throw InvalidInputException(fmt::format( + R"(Nested {} numbers are not allowed)", + getClassStatic()->getName())); } - if (!re || !im) { - throw InvalidInputException(str); - } + re = cast(inRe.toMinimalObject()); + im = cast(inIm.toMinimalObject()); } Complex::Complex(const Integer &rhs) : re(cast(rhs.toMinimalObject())) { @@ -53,13 +53,23 @@ Complex::Complex(const Rational &rhs) : re(cast(rhs.toMinimalObject())) Complex::Complex(const Real &rhs) : re(cast(rhs.toMinimalObject())) { } -Complex::Complex(const INumber &inReal, const INumber &inImag) { - if (is(inReal) || is(inImag)) { - throw InvalidInputException("Nested complex numbers are not allowed"); +Complex::Complex(const std::string &str) try { + if (!str.empty() && str.back() == 'I') { + im = parseNonComplexNumber(str.substr(0, str.size() - 1)); + } + else { + re = parseNonComplexNumber(str); } - re = cast(inReal.toMinimalObject()); - im = cast(inImag.toMinimalObject()); + if (!re || !im) { + throw InvalidInputException(""); + } +} +catch (const InvalidInputException &) { + throw InvalidInputException(fmt::format( + R"(Unable to parse {} from "{}")", + getClassStatic()->getName(), + str)); } std::string Complex::toString() const { @@ -187,7 +197,10 @@ Complex &Complex::divide(const Complex &rhs) { im = *(*(y * u) - *(x * v)) / *divisor; } catch (const UndefinedException &) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); + throw UndefinedException(fmt::format( + R"(div({}, {}) is undefined (division by zero))", + toString(), + rhs.toString())); } return *this; diff --git a/src/fintamath/numbers/Integer.cpp b/src/fintamath/numbers/Integer.cpp index d095e3537..439df0c25 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" @@ -19,20 +22,24 @@ using namespace detail; Integer::Integer(Backend inBackend) : backend(std::move(inBackend)) { } -Integer::Integer(std::string str) { +Integer::Integer(const std::string_view str) try { if (str.empty()) { - throw InvalidInputException(str); + throw InvalidInputException(""); } - 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(""); } } +catch (const InvalidInputException &) { + throw InvalidInputException(fmt::format( + R"(Unable to parse {} from "{}")", + getClassStatic()->getName(), + str)); +} std::string Integer::toString() const { return backend.str(); @@ -71,7 +78,10 @@ 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"(div({}, {}) is undefined (division by zero))", + toString(), + rhs.toString())); } backend /= rhs.backend; @@ -85,7 +95,10 @@ Integer &Integer::negate() { Integer &Integer::mod(const Integer &rhs) { if (rhs == 0) { - throw UndefinedBinaryOperatorException("mod", toString(), rhs.toString()); + throw UndefinedException(fmt::format( + R"(mod({}, {}) is undefined (modulo by zero))", + toString(), + rhs.toString())); } backend %= rhs.backend; @@ -108,23 +121,27 @@ Integer &Integer::bitXor(const Integer &rhs) { } Integer &Integer::bitLeftShift(const Integer &rhs) { - try { - backend <<= static_cast(rhs.backend); - return *this; - } - catch (...) { - throw UndefinedBinaryOperatorException("<<", toString(), rhs.toString()); + if (rhs < 0) { + throw UndefinedException(fmt::format( + R"(bitLeftShift({}, {}) is undefined (negative shift))", + toString(), + rhs.toString())); } + + backend <<= static_cast(rhs.backend); + return *this; } Integer &Integer::bitRightShift(const Integer &rhs) { - try { - backend >>= static_cast(rhs.backend); - return *this; - } - catch (...) { - throw UndefinedBinaryOperatorException(">>", toString(), rhs.toString()); + if (rhs < 0) { + throw UndefinedException(fmt::format( + R"(bitRightShift({}, {}) is undefined (negative shift))", + toString(), + rhs.toString())); } + + backend >>= static_cast(rhs.backend); + return *this; } Integer &Integer::bitNot() { diff --git a/src/fintamath/numbers/IntegerFunctions.cpp b/src/fintamath/numbers/IntegerFunctions.cpp index b43f7492b..b4ff96d51 100644 --- a/src/fintamath/numbers/IntegerFunctions.cpp +++ b/src/fintamath/numbers/IntegerFunctions.cpp @@ -33,7 +33,9 @@ Integer sqrt(const Integer &rhs) { Integer sqrt(const Integer &rhs, Integer &remainder) { if (rhs < 0) { - throw UndefinedFunctionException("sqrt", {rhs.toString()}); + throw UndefinedException(fmt::format( + R"(sqrt({}) is undefined (expected argument >= 0))", + rhs.toString())); } Integer::Backend remainderBackend; @@ -59,7 +61,9 @@ Integer factorialRec(const Integer &left, const Integer &right) { Integer factorial(const Integer &rhs) { if (rhs < 0) { - throw UndefinedUnaryOperatorException("!", rhs.toString(), UndefinedUnaryOperatorException::Type::Postfix); + throw UndefinedException(fmt::format( + R"(factorial({}) is undefined (expected argument >= 0))", + rhs.toString())); } if (rhs < 2) { @@ -73,8 +77,10 @@ Integer factorial(const Integer &rhs, const size_t order) { assert(order > 0); if (rhs < 0) { - throw UndefinedUnaryOperatorException(std::string(order, '!'), rhs.toString(), - UndefinedUnaryOperatorException::Type::Postfix); + throw UndefinedException(fmt::format( + R"(factorial({}, {}) is undefined (expected first argument >= 0))", + rhs.toString(), + order)); } if (order == 1) { @@ -94,7 +100,9 @@ Integer factorial(const Integer &rhs, const size_t order) { FactorToCountMap factors(Integer rhs, Integer limit) { if (rhs < 2) { - throw UndefinedFunctionException("factors", {rhs.toString()}); + throw UndefinedException(fmt::format( + R"(factors({}) is undefined (expected argument >= 2))", + rhs.toString())); } FactorToCountMap factorToCountMap; @@ -129,24 +137,30 @@ FactorToCountMap factors(Integer rhs, Integer limit) { // Use number of combinations formula. // https://en.wikipedia.org/wiki/Combination#Number_of_k-combinations. Integer combinations(const Integer &totalNumber, const Integer &choosedNumber) { - if (choosedNumber > totalNumber) { - throw UndefinedFunctionException("combinations", {totalNumber.toString()}); + if (totalNumber <= choosedNumber) { + throw UndefinedException(fmt::format( + R"(combinations({}, {}) is undefined (expected totalNumber > choosedNumber))", + totalNumber.toString(), + choosedNumber.toString())); } - return factorial(totalNumber) / (factorial(choosedNumber) * factorial(totalNumber - choosedNumber)); + try { + return factorial(totalNumber) / (factorial(choosedNumber) * factorial(totalNumber - choosedNumber)); + } + catch (const UndefinedException &) { + throw UndefinedException(fmt::format( + R"(combinations({}, {}) is undefined (expected totalNumber >= 0 and choosedNumber >= 0))", + totalNumber.toString(), + choosedNumber.toString())); + } } // Use multinomial coefficients formula. // https://en.wikipedia.org/wiki/Multinomial_theorem#Multinomial_coefficients. -Integer multinomialCoefficient(const Integer &totalNumber, const std::vector &groupNumbers) { - Integer checkValue; - +Integer multinomialCoefficient(const std::vector &groupNumbers) { + Integer totalNumber; for (const auto &groupNumber : groupNumbers) { - checkValue += groupNumber; - } - - if (checkValue != totalNumber) { - throw UndefinedFunctionException("split", {totalNumber.toString()}); + totalNumber += groupNumber; } Integer res = factorial(totalNumber); diff --git a/src/fintamath/numbers/NumberAbstract.cpp b/src/fintamath/numbers/NumberAbstract.cpp index bb48f1413..df5cf4655 100644 --- a/src/fintamath/numbers/NumberAbstract.cpp +++ b/src/fintamath/numbers/NumberAbstract.cpp @@ -27,9 +27,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 INumberCRTP::divideAbstract(rhs); diff --git a/src/fintamath/numbers/NumberUtils.cpp b/src/fintamath/numbers/NumberUtils.cpp index d83cc19a1..1c9784d48 100644 --- a/src/fintamath/numbers/NumberUtils.cpp +++ b/src/fintamath/numbers/NumberUtils.cpp @@ -1,5 +1,6 @@ #include "fintamath/numbers/NumberUtils.hpp" +#include #include #include @@ -13,7 +14,7 @@ std::string removeLeadingZeroes(std::string str) { const size_t firstNonZeroDigit = str.find_first_not_of('0', firstDigit); - if (firstNonZeroDigit == std::string::npos) { + if (firstNonZeroDigit == std::string::npos || !std::isdigit(str[firstNonZeroDigit])) { str.insert(firstDigit, "0"); } else if (firstNonZeroDigit > firstDigit) { diff --git a/src/fintamath/numbers/Rational.cpp b/src/fintamath/numbers/Rational.cpp index c7ce3ecf3..db6c2ac7f 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" @@ -26,16 +29,23 @@ Rational::Rational(Integer inNumer, Integer inDenom) : numer(std::move(inNumer)), denom(std::move(inDenom)) { + if (denom == 0) { + throw UndefinedException(fmt::format( + R"(div({}, {}) is undefined (division by zero))", + numer.toString(), + denom.toString())); + } + toIrreducibleRational(); } -Rational::Rational(const std::string &str) { +Rational::Rational(const std::string_view str) try { if (str.empty()) { - throw InvalidInputException(str); + throw InvalidInputException(""); } if (str.empty() || str == ".") { - throw InvalidInputException(str); + throw InvalidInputException(""); } int64_t firstDigitNum = 0; @@ -47,8 +57,8 @@ 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()) { @@ -57,7 +67,7 @@ Rational::Rational(const std::string &str) { } if (firstDotNum + 1 < std::ssize(str)) { - const std::string numeratorStr = str.substr(static_cast(firstDotNum) + 1); + const std::string numeratorStr(str.substr(static_cast(firstDotNum) + 1)); std::string denominatorStr(numeratorStr.size() + 1, '0'); denominatorStr.front() = '1'; numer = Integer(numeratorStr); @@ -65,7 +75,7 @@ Rational::Rational(const std::string &str) { } if (intPart < 0 || numer < 0) { - throw InvalidInputException(str); + throw InvalidInputException(""); } toIrreducibleRational(); @@ -75,13 +85,11 @@ Rational::Rational(const std::string &str) { numer *= -1; } } - -const Integer &Rational::numerator() const noexcept { - return numer; -} - -const Integer &Rational::denominator() const noexcept { - return denom; +catch (const InvalidInputException &) { + throw InvalidInputException(fmt::format( + R"(Unable to parse {} from "{}")", + getClassStatic()->getName(), + str)); } std::string Rational::toString() const { @@ -105,6 +113,14 @@ int Rational::sign() const { return numer.sign(); } +const Integer &Rational::numerator() const noexcept { + return numer; +} + +const Integer &Rational::denominator() const noexcept { + return denom; +} + bool Rational::equals(const Rational &rhs) const { return numer == rhs.numer && denom == rhs.denom; } @@ -140,6 +156,13 @@ Rational &Rational::multiply(const Rational &rhs) { } Rational &Rational::divide(const Rational &rhs) { + if (rhs == 0) { + throw UndefinedException(fmt::format( + R"(div({}, {}) is undefined (division by zero))", + toString(), + rhs.toString())); + } + numer *= rhs.denom; denom *= rhs.numer; toIrreducibleRational(); @@ -152,10 +175,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 6955105ba..571f850b3 100644 --- a/src/fintamath/numbers/Real.cpp +++ b/src/fintamath/numbers/Real.cpp @@ -8,10 +8,13 @@ #include #include #include +#include #include #include +#include + #include "fintamath/exceptions/InvalidInputException.hpp" #include "fintamath/exceptions/UndefinedException.hpp" #include "fintamath/numbers/Integer.hpp" @@ -27,61 +30,57 @@ using namespace detail; constexpr unsigned precisionMultiplier = 2; constexpr unsigned precisionDelta = 10; -Real::Real(Backend inBackend) : backend(std::move(inBackend)), - isNegative(backend < 0) { +Real::Real(Backend inBackend) : backend(std::move(inBackend)) { if (!isFinite()) { - throw UndefinedException(backend.str()); + throw UndefinedException(fmt::format( + R"(Undefined backend {})", + backend.str())); } } -Real::Real(std::string str) : Real() { - if (str.empty() || str == ".") { - throw InvalidInputException(str); - } +Real::Real(const Rational &rhs) : Real(Real(rhs.numerator()) / Real(rhs.denominator())) {} - str = removeLeadingZeroes(std::move(str)); +Real::Real(const Integer &rhs) : backend(rhs.getBackend()) {} - if (str.front() == '-') { - isNegative = true; +Real::Real(const std::string_view str) try : Real() { + if (str.empty() || str == ".") { + throw InvalidInputException(""); } + std::string mutableStr = removeLeadingZeroes(std::string(str)); + { 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(""); } if (!isFinite()) { - throw UndefinedException(str); + throw UndefinedException(fmt::format( + R"(Undefined "{}" (overflow))", + str)); } } - -Real::Real(const Rational &rhs) - : Real(Real(rhs.numerator()) / Real(rhs.denominator())) {} - -Real::Real(const Integer &rhs) - : backend(rhs.getBackend()), - isNegative(rhs < 0) {} +catch (const InvalidInputException &) { + throw InvalidInputException(fmt::format( + R"(Unable to parse {} from "{}")", + getClassStatic()->getName(), + str)); +} std::string Real::toString() const { - std::string res = toString(outputPrecision); - - if (isNegative && res.front() != '-') { - res.insert(res.begin(), '-'); - } - - return res; + return toString(outputPrecision); } std::string Real::toString(unsigned precision) const { @@ -130,7 +129,7 @@ bool Real::isPrecise() const noexcept { } int Real::sign() const { - if (isNegative) { + if (mpfr_signbit(backend.backend().data())) { return -1; } @@ -141,6 +140,14 @@ bool Real::isZero() const { return backend.is_zero(); } +bool Real::isPosZero() const { + return isZero() && sign() >= 0; +} + +bool Real::isNegZero() const { + return isZero() && sign() < 0; +} + const Real::Backend &Real::getBackend() const noexcept { return backend; } @@ -171,16 +178,12 @@ void Real::setPrecision(unsigned precision) { } bool Real::equals(const Real &rhs) const { - return backend == rhs.backend && isNegative == rhs.isNegative; + return backend == rhs.backend && sign() == rhs.sign(); } std::strong_ordering Real::compare(const Real &rhs) const { - if (isNegative && !rhs.isNegative) { - return std::strong_ordering::less; - } - - if (!isNegative && rhs.isNegative) { - return std::strong_ordering::greater; + if (sign() != rhs.sign()) { + return sign() <=> rhs.sign(); } return backend.compare(rhs.backend) <=> 0; @@ -189,11 +192,17 @@ std::strong_ordering Real::compare(const Real &rhs) const { Real &Real::add(const Real &rhs) { updatePrecision(rhs); - const bool isResNegZero = backend.is_zero() && - rhs.backend.is_zero() && - (isNegative || rhs.isNegative); - backend += rhs.backend; - isNegative = isResNegZero || backend < 0; + bool isResultNegZero = isZero() && + rhs.isZero() && + (sign() < 0 || rhs.sign() < 0); + + if (!isResultNegZero) { + backend += rhs.backend; + } + else { + backend = 0; + backend = -backend; + } return *this; } @@ -201,39 +210,41 @@ Real &Real::add(const Real &rhs) { Real &Real::substract(const Real &rhs) { updatePrecision(rhs); - const bool isResNegZero = backend.is_zero() && - rhs.backend.is_zero() && - (isNegative || !rhs.isNegative); - backend -= rhs.backend; - isNegative = isResNegZero || backend < 0; + bool isResultNegZero = isZero() && + rhs.isZero() && + (sign() < 0 || rhs.sign() >= 0); + + if (!isResultNegZero) { + backend -= rhs.backend; + } + else { + backend = 0; + backend = -backend; + } return *this; } Real &Real::multiply(const Real &rhs) { updatePrecision(rhs); - - isNegative = isNegative != rhs.isNegative; backend *= rhs.backend; - return *this; } Real &Real::divide(const Real &rhs) { - updatePrecision(rhs); - - isNegative = isNegative != rhs.isNegative; - backend /= rhs.backend; - - if (!isFinite()) { - throw UndefinedBinaryOperatorException("/", toString(), rhs.toString()); + if (rhs.isZero()) { + throw UndefinedException(fmt::format( + R"(div({}, {}) is undefined (division by zero))", + toString(), + rhs.toString())); } + updatePrecision(rhs); + backend /= rhs.backend; return *this; } Real &Real::negate() { - isNegative = !isNegative; backend = -backend; return *this; } diff --git a/src/fintamath/numbers/RealFunctions.cpp b/src/fintamath/numbers/RealFunctions.cpp index f978b009e..2da70899b 100644 --- a/src/fintamath/numbers/RealFunctions.cpp +++ b/src/fintamath/numbers/RealFunctions.cpp @@ -2,6 +2,8 @@ #include +#include + #include #include #include @@ -15,6 +17,12 @@ namespace fintamath { using namespace detail; +constexpr std::string_view backendIsInfException = "Undefined backend inf"; +constexpr std::string_view backendIsNegInfException = "Undefined backend -inf"; +constexpr std::string_view backendIsNanException = "Undefined backend nan"; + +namespace { + bool isOverflow(const Real &rhs) { static Cache cache([](const unsigned precision) { static const Real::Backend powBase = 10; @@ -30,7 +38,7 @@ bool isUnderflow(const Real &rhs) { return 1 / pow(powBase, precision); }); - return rhs != 0 && abs(rhs) < cache[Real::getPrecision()]; + return !rhs.isZero() && abs(rhs) < cache[Real::getPrecision()]; } bool isLogUnderflow(const Real &rhs) { @@ -38,12 +46,30 @@ bool isLogUnderflow(const Real &rhs) { return 1 / pow(precision, getE().getBackend()); }); - return rhs != 0 && abs(rhs) < cache[Real::getPrecision()]; + return !rhs.isZero() && abs(rhs) < cache[Real::getPrecision()]; +} + +std::string getExceptionMessage(const std::string_view message) { + if (message == backendIsInfException || message == backendIsNegInfException) { + return "result overflow"; + } + + if (message == backendIsNanException) { + return "argument out of range"; + } + + return std::string(message); +} + } const Real &trigResultChecked(const Real &rhs) { - if (isUnderflow(rhs) || isOverflow(rhs)) { - throw UndefinedException(""); + if (isUnderflow(rhs)) { + throw UndefinedException("result underflow"); + } + + if (isOverflow(rhs)) { + throw UndefinedException("result overflow"); } return rhs; @@ -51,368 +77,436 @@ const Real &trigResultChecked(const Real &rhs) { const Real &hyperbResultChecked(const Real &rhs) { if (isUnderflow(rhs)) { - throw UndefinedException(""); + throw UndefinedException("result underflow"); } return rhs; } const Real &tgammaResultChecked(const Real &rhs) { - if (rhs == 0) { - throw UndefinedException(""); + if (rhs.isZero()) { + throw UndefinedException("result overflow"); } return rhs; } -Integer floor(const Real &rhs) { +Integer floor(const Real &rhs) try { if (isOverflow(rhs)) { - throw UndefinedFunctionException("floor", {rhs.toString()}); + throw UndefinedException("argument overflow"); + } + + if (rhs.isNegZero()) { + return -1; } const Real::Backend res = boost::multiprecision::floor(rhs.getBackend()); return res.convert_to(); } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "floor({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} -Integer ceil(const Real &rhs) { +Integer ceil(const Real &rhs) try { if (isOverflow(rhs)) { - throw UndefinedFunctionException("ceil", {rhs.toString()}); + throw UndefinedException("argument overflow"); } const Real::Backend res = boost::multiprecision::ceil(rhs.getBackend()); return res.convert_to(); } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "ceil({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} Real abs(const Real &rhs) { return rhs < 0 ? -rhs : rhs; } -Real sqrt(const Real &rhs) { +Real sqrt(const Real &rhs) try { if (rhs < 0) { - throw UndefinedFunctionException("sqrt", {rhs.toString()}); + throw UndefinedException("expected argument >= 0"); } return {sqrt(rhs.getBackend())}; } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "sqrt({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} -Real pow(const Real &lhs, const Real &rhs) { - if (abs(lhs) == 0 && abs(rhs) == 0) { - throw UndefinedBinaryOperatorException("^", lhs.toString(), rhs.toString()); +Real pow(const Real &lhs, const Real &rhs) try { + if (lhs.isZero() && rhs.isZero()) { + throw UndefinedException("zero to the power of zero"); } - try { - if (lhs == Real("-0")) { - // Use (-1)^rhs to validate (-0)^rhs - Real(pow(-1, rhs.getBackend())); - } - - return {pow(lhs.getBackend(), rhs.getBackend())}; - } - catch (const UndefinedException &) { - throw UndefinedBinaryOperatorException("^", lhs.toString(), rhs.toString()); + if (lhs.isNegZero()) { + return Real(0) * pow(Real(-1), rhs); } + + return {pow(lhs.getBackend(), rhs.getBackend())}; +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "pow({}, {}) is undefined ({})", + lhs.toString(), + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real exp(const Real &rhs) { - try { - return {exp(rhs.getBackend())}; - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("exp", {rhs.toString()}); - } +Real exp(const Real &rhs) try { + return {exp(rhs.getBackend())}; +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "exp({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real log(const Real &lhs, const Real &rhs) { - try { - return ln(rhs) / ln(lhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("log", {lhs.toString(), rhs.toString()}); - } +Real log(const Real &lhs, const Real &rhs) try { + return ln(rhs) / ln(lhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "log({}, {}) is undefined ({})", + lhs.toString(), + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real ln(const Real &rhs) { +Real ln(const Real &rhs) try { if (rhs <= 0) { - throw UndefinedFunctionException("ln", {rhs.toString()}); + throw UndefinedException("expected argument > 0"); } Real res = {log(rhs.getBackend())}; if (isLogUnderflow(res)) { - throw UndefinedFunctionException("ln", {rhs.toString()}); + throw UndefinedException("underflow"); } return res; } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "ln({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} -Real lb(const Real &rhs) { - try { - static const Real logBase = 2; - return log(logBase, rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("lb", {rhs.toString()}); - } +Real lb(const Real &rhs) try { + static const Real divisor = ln(2); + return ln(rhs) / divisor; +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "lb({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real lg(const Real &rhs) { - try { - static const Real logBase = 10; - return log(logBase, rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("lg", {rhs.toString()}); - } +Real lg(const Real &rhs) try { + static const Real divisor = ln(10); + return ln(rhs) / divisor; +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "lg({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real sin(const Real &rhs) { +Real sin(const Real &rhs) try { if (isOverflow(rhs)) { - throw UndefinedFunctionException("sin", {rhs.toString()}); + throw UndefinedException("argument overflow"); } - try { - return trigResultChecked({sin(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sin", {rhs.toString()}); - } + return trigResultChecked({sin(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "sin({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real cos(const Real &rhs) { +Real cos(const Real &rhs) try { if (isOverflow(rhs)) { - throw UndefinedFunctionException("cos", {rhs.toString()}); + throw UndefinedException("argument overflow"); } - try { - return trigResultChecked({cos(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("cos", {rhs.toString()}); - } + return trigResultChecked({cos(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "cos({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real tan(const Real &rhs) { +Real tan(const Real &rhs) try { if (isOverflow(rhs)) { - throw UndefinedFunctionException("tan", {rhs.toString()}); + throw UndefinedException("argument overflow"); } - try { - return trigResultChecked({tan(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("tan", {rhs.toString()}); - } + return trigResultChecked({tan(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "tan({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real cot(const Real &rhs) { - try { - return 1 / tan(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("cot", {rhs.toString()}); - } +Real cot(const Real &rhs) try { + return 1 / tan(rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "cot({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real sec(const Real &rhs) { - try { - return 1 / cos(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sec", {rhs.toString()}); - } +Real sec(const Real &rhs) try { + return 1 / cos(rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "sec({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real csc(const Real &rhs) { - try { - return 1 / sin(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("csc", {rhs.toString()}); - } +Real csc(const Real &rhs) try { + return 1 / sin(rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "csc({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real asin(const Real &rhs) { - try { - return trigResultChecked({asin(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asin", {rhs.toString()}); - } +Real asin(const Real &rhs) try { + return trigResultChecked({asin(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "asin({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real acos(const Real &rhs) { - try { - return trigResultChecked({acos(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acos", {rhs.toString()}); - } +Real acos(const Real &rhs) try { + return trigResultChecked({acos(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "acos({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real atan(const Real &rhs) { - try { - return trigResultChecked({atan(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("atan", {rhs.toString()}); - } +Real atan(const Real &rhs) try { + return trigResultChecked({atan(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "atan({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real acot(const Real &rhs) { - try { - return atan(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acot", {rhs.toString()}); - } +Real acot(const Real &rhs) try { + return atan(1 / rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "acot({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real asec(const Real &rhs) { - try { - return acos(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asec", {rhs.toString()}); - } +Real asec(const Real &rhs) try { + return acos(1 / rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "asec({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real acsc(const Real &rhs) { - try { - return asin(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acsc", {rhs.toString()}); - } +Real acsc(const Real &rhs) try { + return asin(1 / rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "acsc({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real sinh(const Real &rhs) { - try { - return hyperbResultChecked({sinh(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sinh", {rhs.toString()}); - } +Real sinh(const Real &rhs) try { + return hyperbResultChecked({sinh(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "sinh({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real cosh(const Real &rhs) { - try { - return hyperbResultChecked({cosh(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("cosh", {rhs.toString()}); - } +Real cosh(const Real &rhs) try { + return hyperbResultChecked({cosh(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "cosh({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real tanh(const Real &rhs) { - try { - return hyperbResultChecked({tanh(rhs.getBackend())}); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("tanh", {rhs.toString()}); - } +Real tanh(const Real &rhs) try { + return hyperbResultChecked({tanh(rhs.getBackend())}); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "tanh({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real coth(const Real &rhs) { - try { - return 1 / tanh(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("coth", {rhs.toString()}); - } +Real coth(const Real &rhs) try { + return 1 / tanh(rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "coth({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real sech(const Real &rhs) { - try { - return 1 / cosh(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("sech", {rhs.toString()}); - } +Real sech(const Real &rhs) try { + return 1 / cosh(rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "sech({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real csch(const Real &rhs) { - try { - return 1 / sinh(rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("csch", {rhs.toString()}); - } +Real csch(const Real &rhs) try { + return 1 / sinh(rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "csch({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real asinh(const Real &rhs) { - try { - return hyperbResultChecked(boost::math::asinh(rhs.getBackend())); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asinh", {rhs.toString()}); - } +Real asinh(const Real &rhs) try { + return hyperbResultChecked(boost::math::asinh(rhs.getBackend())); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "asinh({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real acosh(const Real &rhs) { +Real acosh(const Real &rhs) try { try { return boost::math::acosh(rhs.getBackend()); } catch (const boost::math::evaluation_error &) { - throw UndefinedFunctionException("acosh", {rhs.toString()}); + throw UndefinedException("argument out of range"); } } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "acosh({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} -Real atanh(const Real &rhs) { +Real atanh(const Real &rhs) try { try { return hyperbResultChecked(boost::math::atanh(rhs.getBackend())); } - catch (const UndefinedException &) { - throw UndefinedFunctionException("atanh", {rhs.toString()}); - } catch (const std::overflow_error &) { - throw UndefinedFunctionException("atanh", {rhs.toString()}); + throw UndefinedException("result overflow"); } catch (const boost::math::evaluation_error &) { - throw UndefinedFunctionException("atanh", {rhs.toString()}); + throw UndefinedException("argument out of range"); } } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "atanh({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} -Real acoth(const Real &rhs) { - try { - return atanh(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acoth", {rhs.toString()}); - } +Real acoth(const Real &rhs) try { + return atanh(1 / rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "acoth({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real asech(const Real &rhs) { - try { - return acosh(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("asech", {rhs.toString()}); - } +Real asech(const Real &rhs) try { + return acosh(1 / rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "asech({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real acsch(const Real &rhs) { - try { - return asinh(1 / rhs); - } - catch (const UndefinedException &) { - throw UndefinedFunctionException("acsch", {rhs.toString()}); - } +Real acsch(const Real &rhs) try { + return asinh(1 / rhs); +} +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "acsch({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); } -Real tgamma(const Real &rhs) { +Real tgamma(const Real &rhs) try { try { return tgammaResultChecked(boost::math::tgamma(rhs.getBackend())); } - catch (const UndefinedException &) { - throw UndefinedFunctionException("tgamma", {rhs.toString()}); - } catch (const std::overflow_error &) { - throw UndefinedFunctionException("tgamma", {rhs.toString()}); + throw UndefinedException("result overflow"); } catch (const boost::math::evaluation_error &) { - throw UndefinedFunctionException("tgamma", {rhs.toString()}); + throw UndefinedException("argument out of range"); } } +catch (const UndefinedException &exc) { + throw UndefinedException(fmt::format( + "tgamma({}) is undefined ({})", + rhs.toString(), + getExceptionMessage(exc.what()))); +} const Real &getE() { static Cache cache([](const unsigned precision) { @@ -433,5 +527,4 @@ const Real &getPi() { return cache[Real::getCalculationPrecision()]; } - } diff --git a/tests/src/core/IArithmeticTests.cpp b/tests/src/core/IArithmeticTests.cpp index 092501e6f..35928e802 100644 --- a/tests/src/core/IArithmeticTests.cpp +++ b/tests/src/core/IArithmeticTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/core/IArithmetic.hpp" @@ -76,8 +77,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 the + operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() + *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the + operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a += 3).toString(), "3"); @@ -112,8 +119,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 the - operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() - *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the - operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a; EXPECT_EQ((a -= 3).toString(), "-3"); @@ -148,8 +161,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 the * operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() * *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the * operator (TestArithmetic "TestArithmetic" and Integer "1" are unconvertible to each other))"))); Integer a = 2; EXPECT_EQ((a *= 3).toString(), "6"); @@ -184,8 +203,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 the / operator (Integer "1" and TestArithmetic "TestArithmetic" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestArithmetic() / *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the / 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 5631f136e..bce3f6c07 100644 --- a/tests/src/core/IComparableTests.cpp +++ b/tests/src/core/IComparableTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/core/IComparable.hpp" @@ -67,8 +68,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 the comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() < *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_TRUE(Integer() < 1); EXPECT_TRUE(-1 < Integer()); @@ -92,8 +99,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 the comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() < *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_FALSE(Integer() > 1); EXPECT_FALSE(-1 > Integer()); @@ -117,8 +130,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 the comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() <= *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the comparison operator (TestComparable "TestComparable" and Integer "1" are unconvertible to each other))"))); EXPECT_TRUE(Integer() <= 1); EXPECT_TRUE(-1 <= Integer()); @@ -142,8 +161,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 the comparison operator (Integer "1" and TestComparable "TestComparable" are unconvertible to each other))"))); + EXPECT_THAT( + [&] { TestComparable() >= *m1; }, + testing::ThrowsMessage( + testing::StrEq(R"(Invalid arguments of the 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..ffb10d1f7 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("Invalid input"); }, testing::ThrowsMessage( testing::StrEq("Invalid input"))); - EXPECT_THAT( - [] { throw InvalidInputException("123"); }, - testing::ThrowsMessage( - testing::StrEq("Invalid input: 123"))); -} \ No newline at end of file +} 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..2c3add660 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"); }, testing::ThrowsMessage( testing::StrEq("Undefined"))); - EXPECT_THAT( - [] { throw UndefinedException("123"); }, - testing::ThrowsMessage( - testing::StrEq("Undefined: 123"))); -} \ No newline at end of file +} 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/ExpressionComparatorTests.cpp b/tests/src/expressions/ExpressionComparatorTests.cpp index 78209c2fa..09b0b406a 100644 --- a/tests/src/expressions/ExpressionComparatorTests.cpp +++ b/tests/src/expressions/ExpressionComparatorTests.cpp @@ -3,7 +3,6 @@ #include "fintamath/expressions/ExpressionComparator.hpp" #include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionParser.hpp" using namespace fintamath; using namespace detail; @@ -26,10 +25,10 @@ TEST(ExpressionComparatorTests, comparatorTest) { EXPECT_EQ(compare(Expression("a^b").clone(), Expression("a b c").clone()), std::strong_ordering::greater); EXPECT_EQ(compare(Expression("x^x").clone(), Expression("x^y").clone()), std::strong_ordering::greater); - EXPECT_EQ(compare(parseExpr("sqrt(11)"), parseExpr("root(2022369065670411386760301914510907000742418, 4)")), std::strong_ordering::greater); - EXPECT_EQ(compare(parseExpr("x^x ln(x)"), parseExpr("x^x")), std::strong_ordering::greater); - EXPECT_EQ(compare(parseExpr("~a & c"), parseExpr("a & b & ~c")), std::strong_ordering::greater); + EXPECT_EQ(compare(parseRawExpr("sqrt(11)"), parseRawExpr("root(2022369065670411386760301914510907000742418, 4)")), std::strong_ordering::greater); + EXPECT_EQ(compare(parseRawExpr("x^x ln(x)"), parseRawExpr("x^x")), std::strong_ordering::greater); + EXPECT_EQ(compare(parseRawExpr("~a & c"), parseRawExpr("a & b & ~c")), std::strong_ordering::greater); - EXPECT_EQ(compare(parseExpr("x"), parseExpr("ln(x)"), {.termOrderInversed = false}), std::strong_ordering::less); - EXPECT_EQ(compare(parseExpr("x"), parseExpr("ln(x)"), {.termOrderInversed = true}), std::strong_ordering::greater); + EXPECT_EQ(compare(parseRawExpr("x"), parseRawExpr("ln(x)"), {.termOrderInversed = false}), std::strong_ordering::less); + EXPECT_EQ(compare(parseRawExpr("x"), parseRawExpr("ln(x)"), {.termOrderInversed = true}), std::strong_ordering::greater); } \ No newline at end of file diff --git a/tests/src/expressions/ExpressionFunctionsTests.cpp b/tests/src/expressions/ExpressionFunctionsTests.cpp index fee472f95..523533c57 100644 --- a/tests/src/expressions/ExpressionFunctionsTests.cpp +++ b/tests/src/expressions/ExpressionFunctionsTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/ExpressionFunctions.hpp" @@ -333,9 +334,24 @@ TEST(ExpressionFunctionsTests, complexInfTest) { } TEST(ExpressionFunctionsTests, negativeTest) { - EXPECT_THROW(Boolean(true) + Boolean(false), InvalidInputException); - EXPECT_THROW(Add() / Mul(), InvalidInputException); - EXPECT_THROW(sin(Boolean(true)), InvalidInputException); - EXPECT_THROW(eqv(Boolean(true), Boolean(false)), InvalidInputException); - EXPECT_THROW(orL(Integer(1), Integer(2)), InvalidInputException); + EXPECT_THAT( + [&] { Boolean(true) + Boolean(false); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { Add() / Mul(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with argument #0 Add "add" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { sin(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sin "sin" with argument #0 Boolean "True" (expected INumber))"))); + EXPECT_THAT( + [&] { eqv(Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { orL(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #0 Integer "1" (expected Boolean))"))); } diff --git a/tests/src/expressions/ExpressionParserTests.cpp b/tests/src/expressions/ExpressionParserTests.cpp index 8957645c3..45f0a8145 100644 --- a/tests/src/expressions/ExpressionParserTests.cpp +++ b/tests/src/expressions/ExpressionParserTests.cpp @@ -1,156 +1,485 @@ +#include #include -#include "fintamath/expressions/ExpressionParser.hpp" +#include "fintamath/expressions/Expression.hpp" #include using namespace fintamath; -TEST(ExpressionParserTests, parseExprTest) { - EXPECT_EQ(parseExpr("36/(8-6)3")->toString(), "36/(8 - 6) 3"); - EXPECT_EQ(parseExpr("2%")->toString(), "2/100"); - EXPECT_EQ(parseExpr("2.35%")->toString(), "(47/20)/100"); - EXPECT_EQ(parseExpr("1100*4.76%")->toString(), "1100 (119/25)/100"); - EXPECT_EQ(parseExpr("2.35%%%%")->toString(), "((((47/20)/100)/100)/100)/100"); - EXPECT_EQ(parseExpr("1100*4.76%1100*4.76%")->toString(), "1100 (119/25)/100*1100 (119/25)/100"); - EXPECT_EQ(parseExpr("((((((5)/(8)))/(1)))/(((((((9)/(4)))/(0)))/(5))))")->toString(), "((5/8)/1)/(((9/4)/0)/5)"); - EXPECT_EQ(parseExpr("2%a")->toString(), "2/100 a"); - EXPECT_EQ(parseExpr("2!!!!a!!!")->toString(), "2!!!! a!!!"); - EXPECT_EQ(parseExpr("sin a")->toString(), "sin(a)"); - EXPECT_EQ(parseExpr("s i n a")->toString(), "s i n a"); - EXPECT_EQ(parseExpr("a(2)")->toString(), "a 2"); - EXPECT_EQ(parseExpr("(2)a")->toString(), "2 a"); - EXPECT_EQ(parseExpr("Ea")->toString(), "E a"); - EXPECT_EQ(parseExpr("aE")->toString(), "a E"); - EXPECT_EQ(parseExpr("aEE")->toString(), "a E E"); - EXPECT_EQ(parseExpr("EEa")->toString(), "E E a"); - EXPECT_EQ(parseExpr("x123")->toString(), "x 123"); - EXPECT_EQ(parseExpr("x^y!")->toString(), "(x^y)!"); - EXPECT_EQ(parseExpr("lnE")->toString(), "ln(E)"); - EXPECT_EQ(parseExpr("lncossinE")->toString(), "ln(cos(sin(E)))"); - EXPECT_EQ(parseExpr("ln cos sin a")->toString(), "ln(cos(sin(a)))"); - EXPECT_EQ(parseExpr("log((Pi),(E)^((Pi)))")->toString(), "log(Pi, E^Pi)"); - EXPECT_EQ(parseExpr("lb100")->toString(), "log(2, 100)"); - EXPECT_EQ(parseExpr("log(4/9, 2/3)")->toString(), "log(4/9, 2/3)"); - EXPECT_EQ(parseExpr("60deg")->toString(), "60 Pi/180"); - EXPECT_EQ(parseExpr("adeg")->toString(), "a Pi/180"); +TEST(ExpressionParserTests, parseRawExprTest) { + EXPECT_EQ(parseRawExpr("36/(8-6)3")->toString(), "36/(8 - 6) 3"); + EXPECT_EQ(parseRawExpr("2%")->toString(), "2/100"); + EXPECT_EQ(parseRawExpr("2.35%")->toString(), "(47/20)/100"); + EXPECT_EQ(parseRawExpr("1100*4.76%")->toString(), "1100 (119/25)/100"); + EXPECT_EQ(parseRawExpr("2.35%%%%")->toString(), "((((47/20)/100)/100)/100)/100"); + EXPECT_EQ(parseRawExpr("1100*4.76%1100*4.76%")->toString(), "1100 (119/25)/100*1100 (119/25)/100"); + EXPECT_EQ(parseRawExpr("((((((5)/(8)))/(1)))/(((((((9)/(4)))/(0)))/(5))))")->toString(), "((5/8)/1)/(((9/4)/0)/5)"); + EXPECT_EQ(parseRawExpr("2%a")->toString(), "2/100 a"); + EXPECT_EQ(parseRawExpr("2!!!!a!!!")->toString(), "2!!!! a!!!"); + EXPECT_EQ(parseRawExpr("sin a")->toString(), "sin(a)"); + EXPECT_EQ(parseRawExpr("s i n a")->toString(), "s i n a"); + EXPECT_EQ(parseRawExpr("a(2)")->toString(), "a 2"); + EXPECT_EQ(parseRawExpr("(2)a")->toString(), "2 a"); + EXPECT_EQ(parseRawExpr("Ea")->toString(), "E a"); + EXPECT_EQ(parseRawExpr("aE")->toString(), "a E"); + EXPECT_EQ(parseRawExpr("aEE")->toString(), "a E E"); + EXPECT_EQ(parseRawExpr("EEa")->toString(), "E E a"); + EXPECT_EQ(parseRawExpr("x123")->toString(), "x 123"); + EXPECT_EQ(parseRawExpr("x^y!")->toString(), "(x^y)!"); + EXPECT_EQ(parseRawExpr("lnE")->toString(), "ln(E)"); + EXPECT_EQ(parseRawExpr("lncossinE")->toString(), "ln(cos(sin(E)))"); + EXPECT_EQ(parseRawExpr("ln cos sin a")->toString(), "ln(cos(sin(a)))"); + EXPECT_EQ(parseRawExpr("log((Pi),(E)^((Pi)))")->toString(), "log(Pi, E^Pi)"); + EXPECT_EQ(parseRawExpr("lb100")->toString(), "log(2, 100)"); + EXPECT_EQ(parseRawExpr("log(4/9, 2/3)")->toString(), "log(4/9, 2/3)"); + EXPECT_EQ(parseRawExpr("60deg")->toString(), "60 Pi/180"); + EXPECT_EQ(parseRawExpr("adeg")->toString(), "a Pi/180"); } -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_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_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_THROW(parseExpr("esin()"), InvalidInputException); - EXPECT_THROW(parseExpr("(a+b)*()"), InvalidInputException); - - 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_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_THROW(parseExpr("min()"), InvalidInputException); - EXPECT_THROW(parseExpr("min(True, False)"), InvalidInputException); - EXPECT_THROW(parseExpr("max()"), InvalidInputException); - EXPECT_THROW(parseExpr("max(True, False)"), InvalidInputException); +TEST(ExpressionParserTests, parseRawExprNegativeTest) { + EXPECT_THAT( + [] { parseRawExpr(""); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"\" (empty input)"))); + EXPECT_THAT( + [] { parseRawExpr("1+"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1+\" (incomplite expression with operator \"+\")"))); + EXPECT_THAT( + [] { parseRawExpr("1-"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1-\" (incomplite expression with operator \"-\")"))); + EXPECT_THAT( + [] { parseRawExpr("1*"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1*\" (incomplite expression with operator \"*\")"))); + EXPECT_THAT( + [] { parseRawExpr("1/"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1/\" (incomplite expression with operator \"/\")"))); + EXPECT_THAT( + [] { parseRawExpr("*1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"*1\" (incomplite expression with operator \"*\")"))); + EXPECT_THAT( + [] { parseRawExpr("/1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"/1\" (incomplite expression with operator \"/\")"))); + EXPECT_THAT( + [] { parseRawExpr(" + "); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \" + \" (incomplite expression with operator \"+\")"))); + EXPECT_THAT( + [] { parseRawExpr("(1+2))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(1+2))\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("5-*3"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"5-*3\" (incomplite expression with operator \"*\")"))); + EXPECT_THAT( + [] { parseRawExpr("5 3 +"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"5 3 +\" (incomplite expression with operator \"+\")"))); + EXPECT_THAT( + [] { parseRawExpr("2.2.2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"2.2.2\" (invalid term \"2.2.2\")"))); + EXPECT_THAT( + [] { parseRawExpr("--"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"--\" (incomplite expression with operator \"-\")"))); + EXPECT_THAT( + [] { parseRawExpr("."); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \".\" (invalid term \".\")"))); + EXPECT_THAT( + [] { parseRawExpr(","); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \",\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("/"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"/\" (incomplite expression with operator \"/\")"))); + EXPECT_THAT( + [] { parseRawExpr(";"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \";\" (invalid term \";\")"))); + EXPECT_THAT( + [] { parseRawExpr("\'"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"'\" (invalid term \"'\")"))); + EXPECT_THAT( + [] { parseRawExpr("["); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"[\" (invalid term \"[\")"))); + EXPECT_THAT( + [] { parseRawExpr("]"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"]\" (invalid term \"]\")"))); + EXPECT_THAT( + [] { parseRawExpr("!"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("@"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"@\" (invalid term \"@\")"))); + EXPECT_THAT( + [] { parseRawExpr("\""); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"\"\" (invalid term \"\"\")"))); + EXPECT_THAT( + [] { parseRawExpr("#"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"#\" (invalid term \"#\")"))); + EXPECT_THAT( + [] { parseRawExpr("%"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"%\" (incomplite expression with operator \"%\")"))); + EXPECT_THAT( + [] { parseRawExpr(":"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \":\" (invalid term \":\")"))); + EXPECT_THAT( + [] { parseRawExpr("?"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"?\" (invalid term \"?\")"))); + EXPECT_THAT( + [] { parseRawExpr("*"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"*\" (incomplite expression with operator \"*\")"))); + EXPECT_THAT( + [] { parseRawExpr("("); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr(")"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \")\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("-"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"-\" (incomplite expression with operator \"-\")"))); + EXPECT_THAT( + [] { parseRawExpr("+"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"+\" (incomplite expression with operator \"+\")"))); + EXPECT_THAT( + [] { parseRawExpr("^"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"^\" (incomplite expression with operator \"^\")"))); + EXPECT_THAT( + [] { parseRawExpr("&"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"&\" (incomplite expression with operator \"&\")"))); + EXPECT_THAT( + [] { parseRawExpr("_"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"_\" (incomplite expression with operator \"_\")"))); + EXPECT_THAT( + [] { parseRawExpr("[1+1]"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"[1+1]\" (invalid term \"[\")"))); + EXPECT_THAT( + [] { parseRawExpr("{1}"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"{1}\" (invalid term \"{\")"))); + EXPECT_THAT( + [] { parseRawExpr(",2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \",2\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("2,"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"2,\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("(1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(1\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("(((2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(((2)\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("(((2))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(((2))\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("((2)))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((2)))\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("(2)))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(2)))\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("(2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(2\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("((2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((2)\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("((2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((2\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("((((2)((2))))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((((2)((2))))\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("(()())"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(()())\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("((()()))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((()()))\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("((((()))))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((((()))))\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("(,) + (,)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(,) + (,)\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("!2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!2\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("!!2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!!2\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("!2!!"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!2!!\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("!(2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!(2\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("!(2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!(2)\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("2)!"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"2)!\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("sin(2))!"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(2))!\" (bracket mismatch)"))); + EXPECT_THAT( + [] { parseRawExpr("!!!!!!"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"!!!!!!\" (incomplite expression with operator \"!\")"))); + EXPECT_THAT( + [] { parseRawExpr("esin()"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"esin()\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("(a+b)*()"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(a+b)*()\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("sin(2,3)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(2,3)\" (function \"sin\" with 2 arguments not found)"))); + EXPECT_THAT( + [] { parseRawExpr("sin(2,3) + 2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(2,3) + 2\" (function \"sin\" with 2 arguments not found)"))); + EXPECT_THAT( + [] { parseRawExpr("cos(sin(2,3))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"cos(sin(2,3))\" (function \"sin\" with 2 arguments not found)"))); + EXPECT_THAT( + [] { parseRawExpr("sin(,)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(,)\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("sin(,2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(,2)\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("sin(2,)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(2,)\" (incomplite expression with operator \",\")"))); + EXPECT_THAT( + [] { parseRawExpr("sin()"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin()\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("log(1)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"log(1)\" (function \"log\" with 1 arguments not found)"))); + EXPECT_THAT( + [] { parseRawExpr("log()"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"log()\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("(1 = 1) / 2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(1 = 1) / 2\" (unable to call Div \"/\" with argument #0 Boolean \"1 = 1\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("2 + (1 = 2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"2 + (1 = 2)\" (unable to call AddOper \"+\" with argument #1 Boolean \"1 = 2\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("sin(1 = 1)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(1 = 1)\" (unable to call Sin \"sin\" with argument #0 Boolean \"1 = 1\" (expected INumber))"))); + EXPECT_THAT( + [] { parseRawExpr("sin(sin(1 = 1))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(sin(1 = 1))\" (unable to call Sin \"sin\" with argument #0 Boolean \"1 = 1\" (expected INumber))"))); + EXPECT_THAT( + [] { parseRawExpr("sin(sin(sin(1 = 1)))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"sin(sin(sin(1 = 1)))\" (unable to call Sin \"sin\" with argument #0 Boolean \"1 = 1\" (expected INumber))"))); + EXPECT_THAT( + [] { parseRawExpr("True/True"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"True/True\" (unable to call Div \"/\" with argument #0 Boolean \"True\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("((1 = 1)) + ((1 = 2))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((1 = 1)) + ((1 = 2))\" (unable to call AddOper \"+\" with argument #0 Boolean \"1 = 1\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("((1 = 1)) - ((1 = 1))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((1 = 1)) - ((1 = 1))\" (unable to call Sub \"-\" with argument #0 Boolean \"1 = 1\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("((1 = 1)) / ((1 = 1))"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"((1 = 1)) / ((1 = 1))\" (unable to call Div \"/\" with argument #0 Boolean \"1 = 1\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("(5+5)=(2=5)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(5+5)=(2=5)\" (unable to call Eqv \"=\" with argument #1 Boolean \"2 = 5\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("1+(sin(x)<2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1+(sin(x)<2)\" (unable to call AddOper \"+\" with argument #1 Boolean \"sin(x) < 2\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("1/(sin(x)<2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1/(sin(x)<2)\" (unable to call Div \"/\" with argument #1 Boolean \"sin(x) < 2\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("1+False"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1+False\" (unable to call AddOper \"+\" with argument #1 Boolean \"False\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("False+1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"False+1\" (unable to call AddOper \"+\" with argument #0 Boolean \"False\" (expected IArithmetic))"))); + EXPECT_THAT( + [] { parseRawExpr("1=False"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1=False\" (unable to call Eqv \"=\" with argument #1 Boolean \"False\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("False=1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"False=1\" (unable to call Eqv \"=\" with argument #0 Boolean \"False\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("1&2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"1&2\" (unable to call AndOper \"&\" with argument #0 Integer \"1\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("E&I"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"E&I\" (unable to call AndOper \"&\" with argument #0 Real \"E\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("x+1&x+2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"x+1&x+2\" (unable to call AndOper \"&\" with argument #0 IArithmetic \"x + 1\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("x+1&x"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"x+1&x\" (unable to call AndOper \"&\" with argument #0 IArithmetic \"x + 1\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("x&x+2"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"x&x+2\" (unable to call AndOper \"&\" with argument #1 IArithmetic \"x + 2\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("(x&y)=(y&z)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(x&y)=(y&z)\" (unable to call Eqv \"=\" with argument #0 Boolean \"x & y\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("derivative(x=y, x)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"derivative(x=y, x)\" (unable to call Derivative \"derivative\" with argument #0 Boolean \"x = y\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("derivative(x&y,x)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"derivative(x&y,x)\" (unable to call Derivative \"derivative\" with argument #0 Boolean \"x & y\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("derivative(True,a)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"derivative(True,a)\" (unable to call Derivative \"derivative\" with argument #0 Boolean \"True\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("(a+1)_(a>2)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(a+1)_(a>2)\" (unable to call Index \"_\" with argument #0 IArithmetic \"a + 1\" (expected Variable))"))); + EXPECT_THAT( + [] { parseRawExpr("(x+1)_1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(x+1)_1\" (unable to call Index \"_\" with argument #0 IArithmetic \"x + 1\" (expected Variable))"))); + EXPECT_THAT( + [] { parseRawExpr("(x*2)_1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(x*2)_1\" (unable to call Index \"_\" with argument #0 IArithmetic \"x 2\" (expected Variable))"))); + EXPECT_THAT( + [] { parseRawExpr("(x*2)_((x+2)_x)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"(x*2)_((x+2)_x)\" (unable to call Index \"_\" with argument #0 IArithmetic \"x + 2\" (expected Variable))"))); + EXPECT_THAT( + [] { parseRawExpr("x^x_1"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"x^x_1\" (unable to call Index \"_\" with argument #0 INumber \"x^x\" (expected Variable))"))); + EXPECT_THAT( + [] { parseRawExpr("E&a"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"E&a\" (unable to call AndOper \"&\" with argument #0 Real \"E\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("~Inf"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"~Inf\" (unable to call Not \"~\" with argument #0 INumber \"Inf\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("~Undefined"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"~Undefined\" (unable to call Not \"~\" with argument #0 IArithmetic \"Undefined\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("a | Undefined"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"a | Undefined\" (unable to call OrOper \"|\" with argument #1 IArithmetic \"Undefined\" (expected Boolean))"))); + EXPECT_THAT( + [] { parseRawExpr("min()"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"min()\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("min(True)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"min(True)\" (unable to call Min \"min\" with argument #0 Boolean \"True\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("min(True, False)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"min(True, False)\" (unable to call Min \"min\" with argument #0 Boolean \"True\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("max()"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"max()\" (incomplete expression inside brackets)"))); + EXPECT_THAT( + [] { parseRawExpr("max(True)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"max(True)\" (unable to call Max \"max\" with argument #0 Boolean \"True\" (expected IComparable))"))); + EXPECT_THAT( + [] { parseRawExpr("max(True, False)"); }, + testing::ThrowsMessage( + testing::StrEq("Unable to parse an expression from \"max(True, False)\" (unable to call Max \"max\" with argument #0 Boolean \"True\" (expected IComparable))"))); } diff --git a/tests/src/expressions/ExpressionTests.cpp b/tests/src/expressions/ExpressionTests.cpp index e3a083b0f..f9c04cc6d 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(R"(Unable to parse an expression from "" (empty input))"))); + EXPECT_THAT( + [] { Expression("1+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse an expression from "1+" (incomplite expression with operator "+"))"))); } 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("Unable to set 2 Expression children (expected 1)"))); } TEST(ExpressionTests, getFunctionTest) { diff --git a/tests/src/expressions/ExpressionUtilsTests.cpp b/tests/src/expressions/ExpressionUtilsTests.cpp index 5e2c34ca7..678a5f73a 100644 --- a/tests/src/expressions/ExpressionUtilsTests.cpp +++ b/tests/src/expressions/ExpressionUtilsTests.cpp @@ -3,7 +3,6 @@ #include "fintamath/expressions/ExpressionUtils.hpp" #include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionParser.hpp" using namespace fintamath; using namespace detail; @@ -127,13 +126,13 @@ TEST(ExpressionUtilsTests, negateTest) { } TEST(ExpressionUtilsTests, invertTest) { - EXPECT_EQ(invert(parseExpr("2"))->toString(), "1/2"); - EXPECT_EQ(invert(parseExpr("1/2"))->toString(), "2"); - EXPECT_EQ(invert(parseExpr("3/2"))->toString(), "2/3"); - EXPECT_EQ(invert(parseExpr("sqrt(2)"))->toString(), "1/sqrt(2)"); - EXPECT_EQ(invert(parseExpr("sqrt(2)/1"))->toString(), "1/sqrt(2)"); - EXPECT_EQ(invert(parseExpr("1/sqrt(2)"))->toString(), "sqrt(2)"); - EXPECT_EQ(invert(parseExpr("sqrt(2)/2"))->toString(), "2/sqrt(2)"); - EXPECT_EQ(invert(parseExpr("2/sqrt(2)"))->toString(), "sqrt(2)/2"); - EXPECT_EQ(invert(parseExpr("sqrt(2)/sqrt(3)"))->toString(), "sqrt(3)/sqrt(2)"); + EXPECT_EQ(invert(parseRawExpr("2"))->toString(), "1/2"); + EXPECT_EQ(invert(parseRawExpr("1/2"))->toString(), "2"); + EXPECT_EQ(invert(parseRawExpr("3/2"))->toString(), "2/3"); + EXPECT_EQ(invert(parseRawExpr("sqrt(2)"))->toString(), "1/sqrt(2)"); + EXPECT_EQ(invert(parseRawExpr("sqrt(2)/1"))->toString(), "1/sqrt(2)"); + EXPECT_EQ(invert(parseRawExpr("1/sqrt(2)"))->toString(), "sqrt(2)"); + EXPECT_EQ(invert(parseRawExpr("sqrt(2)/2"))->toString(), "2/sqrt(2)"); + EXPECT_EQ(invert(parseRawExpr("2/sqrt(2)"))->toString(), "sqrt(2)/2"); + EXPECT_EQ(invert(parseRawExpr("sqrt(2)/sqrt(3)"))->toString(), "sqrt(3)/sqrt(2)"); } diff --git a/tests/src/expressions/IExpressionTests.cpp b/tests/src/expressions/IExpressionTests.cpp index 528160b08..de3b10d7b 100644 --- a/tests/src/expressions/IExpressionTests.cpp +++ b/tests/src/expressions/IExpressionTests.cpp @@ -4,7 +4,6 @@ #include "fintamath/expressions/IExpression.hpp" #include "fintamath/expressions/Expression.hpp" -#include "fintamath/expressions/ExpressionParser.hpp" #include "fintamath/expressions/ExpressionUtils.hpp" #include "fintamath/functions/arithmetic/Add.hpp" #include "fintamath/functions/other/Factorial.hpp" @@ -80,13 +79,11 @@ TEST(IExpressionTests, setChildrenTest) { expr->setChildren({Variable("b").clone()}); EXPECT_EQ(expr->toString(), "b!"); - EXPECT_THROW(expr->setChildren({Variable("b").clone(), Variable("c").clone()}), InvalidInputException); - // TODO: implement more tests } TEST(IExpressionTests, getVariablesTest) { - const auto expr = cast(parseExpr("x^2+y^2+a")); + const auto expr = cast(parseRawExpr("x^2+y^2+a")); EXPECT_THAT(expr->getVariables(), testing::ElementsAre(Variable("a"), Variable("x"), Variable("y"))); // TODO: implement more tests diff --git a/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp b/tests/src/expressions/interfaces/IBinaryExpressionTests.cpp index 69cac65ee..4bf4dbf49 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" @@ -42,14 +43,14 @@ TEST(IBinaryExpressionTests, getFunctionTest) { EXPECT_EQ(*expr.getFunction(), f); } -TEST(IBinaryExpressionTests, getChildren) { +TEST(IBinaryExpressionTests, getChildrenTest) { const TestBinaryExpression expr(std::make_shared(1), std::make_shared(2)); EXPECT_EQ(expr.getChildren().size(), 2); EXPECT_EQ(*expr.getChildren().front(), Integer(1)); EXPECT_EQ(*expr.getChildren().back(), Integer(2)); } -TEST(IBinaryExpressionTests, setChildren) { +TEST(IBinaryExpressionTests, setChildrenTest) { TestBinaryExpression expr(std::make_shared(1), std::make_shared(2)); expr.setChildren({std::make_shared(0), std::make_shared(0)}); @@ -57,11 +58,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(R"(Unable to call AddOper "+" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { expr.setChildren({std::make_shared(1)}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { expr.setChildren({std::make_shared(1), std::make_shared(1), std::make_shared(1)}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with 3 arguments (expected 2))"))); } TEST(IBinaryExpressionTests, toMinimalObjectTest) { diff --git a/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp b/tests/src/expressions/interfaces/IPolynomExpressionTests.cpp index afcaf8b66..439ad7f0b 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" @@ -46,7 +47,7 @@ TEST(IPolynomExpressionTests, getFunctionTest) { EXPECT_EQ(*expr.getFunction(), f); } -TEST(IPolynomExpressionTests, getChildren) { +TEST(IPolynomExpressionTests, getChildrenTest) { const TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); EXPECT_EQ(expr.getChildren().size(), 3); EXPECT_EQ(*expr.getChildren()[0], Integer(1)); @@ -54,7 +55,7 @@ TEST(IPolynomExpressionTests, getChildren) { EXPECT_EQ(*expr.getChildren()[2], Integer(3)); } -TEST(IPolynomExpressionTests, setChildren) { +TEST(IPolynomExpressionTests, setChildrenTest) { TestPolynomExpression expr({Integer(1).clone(), Integer(2).clone(), Integer(3).clone()}); expr.setChildren({Integer(0).clone()}); @@ -72,7 +73,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(R"(Unable to call Mul "mul" with 0 arguments (expected > 0))"))); } TEST(IPolynomExpressionTests, toMinimalObjectTest) { diff --git a/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp b/tests/src/expressions/interfaces/IUnaryExpressionTests.cpp index 9816a017a..078c651cc 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" @@ -42,22 +43,27 @@ TEST(IUnaryExpressionTests, getFunctionTest) { EXPECT_EQ(*expr.getFunction(), f); } -TEST(IUnaryExpressionTests, getChildren) { +TEST(IUnaryExpressionTests, getChildrenTest) { const TestUnaryExpression expr(std::make_shared(1)); EXPECT_EQ(expr.getChildren().size(), 1); EXPECT_EQ(*expr.getChildren().front(), Integer(1)); } -TEST(IUnaryExpressionTests, setChildren) { +TEST(IUnaryExpressionTests, setChildrenTest) { TestUnaryExpression expr(std::make_shared(1)); expr.setChildren({std::make_shared(0)}); 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(R"(Unable to call Factorial "!" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { expr.setChildren({std::make_shared(1), std::make_shared(1)}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Factorial "!" with 2 arguments (expected 1))"))); } TEST(IUnaryExpressionTests, toMinimalObjectTest) { diff --git a/tests/src/functions/FunctionUtilsTests.cpp b/tests/src/functions/FunctionUtilsTests.cpp index 9628f4914..f84abb8c5 100644 --- a/tests/src/functions/FunctionUtilsTests.cpp +++ b/tests/src/functions/FunctionUtilsTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/expressions/Expression.hpp" @@ -7,6 +8,7 @@ #include "fintamath/functions/arithmetic/Add.hpp" #include "fintamath/functions/arithmetic/MulOper.hpp" #include "fintamath/functions/powers/Pow.hpp" +#include "fintamath/functions/powers/PowOper.hpp" #include "fintamath/functions/trigonometry/Cos.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" @@ -27,10 +29,22 @@ TEST(FunctionUtilsTests, makeExpressionPtrsTest) { EXPECT_EQ(expr2->toString(), "cos(a)"); EXPECT_TRUE(is(expr2)); - EXPECT_THROW(makeExpr(MulOper(), ArgumentPtrVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(MulOper(), ArgumentPtrVector{})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(MulOper(), ArgumentPtrVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(MulOper(), ArgumentPtrVector{})->toString(), InvalidInputException); + EXPECT_THAT( + [&] { makeExpr(MulOper(), ArgumentPtrVector{var}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 1 argument (expected 2))"))); + EXPECT_THAT( + [] { makeExpr(MulOper(), ArgumentPtrVector{}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { makeExpr(PowOper(), ArgumentPtrVector{var}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 1 argument (expected 2))"))); + EXPECT_THAT( + [] { makeExpr(PowOper(), ArgumentPtrVector{}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 0 arguments (expected 2))"))); } TEST(FunctionUtilsTests, makeExpressionRefsTest) { @@ -45,10 +59,22 @@ TEST(FunctionUtilsTests, makeExpressionRefsTest) { EXPECT_EQ(expr2->toString(), "cos(a)"); EXPECT_TRUE(is(expr2)); - EXPECT_THROW(makeExpr(MulOper(), ArgumentRefVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(MulOper(), ArgumentRefVector{})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(MulOper(), ArgumentRefVector{var})->toString(), InvalidInputException); - EXPECT_THROW(makeExpr(MulOper(), ArgumentRefVector{})->toString(), InvalidInputException); + EXPECT_THAT( + [&] { makeExpr(MulOper(), ArgumentRefVector{var}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 1 argument (expected 2))"))); + EXPECT_THAT( + [] { makeExpr(MulOper(), ArgumentRefVector{}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { makeExpr(PowOper(), ArgumentRefVector{var}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 1 argument (expected 2))"))); + EXPECT_THAT( + [] { makeExpr(PowOper(), ArgumentRefVector{}); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 0 arguments (expected 2))"))); } TEST(FunctionUtilsTests, makeExpressionAnyArgsRefTest) { diff --git a/tests/src/functions/IFunctionTests.cpp b/tests/src/functions/IFunctionTests.cpp index 5e0a60c1b..fd690a839 100644 --- a/tests/src/functions/IFunctionTests.cpp +++ b/tests/src/functions/IFunctionTests.cpp @@ -3,11 +3,11 @@ #include "fintamath/functions/IFunction.hpp" +#include "fintamath/functions/arithmetic/Div.hpp" #include "fintamath/functions/arithmetic/Mul.hpp" #include "fintamath/functions/arithmetic/Neg.hpp" #include "fintamath/functions/arithmetic/Sub.hpp" #include "fintamath/functions/arithmetic/UnaryPlus.hpp" -#include "fintamath/functions/logarithms/Log.hpp" #include "fintamath/functions/trigonometry/Sin.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" @@ -40,61 +40,51 @@ TEST(IFunctionTests, parseTest) { } TEST(IFunctionTests, callTest) { - std::unique_ptr f = std::make_unique(); + std::unique_ptr f = std::make_unique
(); Integer a = 3; Rational b(1, 2); Variable c("c"); EXPECT_EQ((*f)(a, a)->toString(), "1"); EXPECT_EQ((*f)(b, b)->toString(), "1"); - EXPECT_EQ((*f)(a, b)->toString(), "-0.6309297535714574371"); - EXPECT_EQ((*f)(b, a)->toString(), "-1.5849625007211561815"); + EXPECT_EQ((*f)(a, b)->toString(), "6"); + EXPECT_EQ((*f)(b, a)->toString(), "1/6"); - EXPECT_EQ((*f)(a, c)->toString(), "log(3, c)"); - - 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_EQ((*f)(a, c)->toString(), "3/c"); } TEST(IFunctionTests, callVectTest) { - std::unique_ptr f = std::make_unique(); + std::unique_ptr f = std::make_unique
(); Integer a = 3; Rational b(1, 2); Variable c("c"); EXPECT_EQ((*f)({a, a})->toString(), "1"); EXPECT_EQ((*f)({b, b})->toString(), "1"); - EXPECT_EQ((*f)({a, b})->toString(), "-0.6309297535714574371"); - EXPECT_EQ((*f)({b, a})->toString(), "-1.5849625007211561815"); - - EXPECT_EQ((*f)({a, c})->toString(), "log(3, c)"); + EXPECT_EQ((*f)({a, b})->toString(), "6"); + EXPECT_EQ((*f)({b, a})->toString(), "1/6"); - 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_EQ((*f)({a, c})->toString(), "3/c"); } TEST(IFunctionTests, equalsTest) { - EXPECT_EQ(Log(), Log()); - EXPECT_NE(Log(), Sub()); - EXPECT_NE(Sub(), Log()); - EXPECT_NE(Log(), UnaryPlus()); - EXPECT_NE(UnaryPlus(), Log()); - EXPECT_NE(Log(), Sin()); - EXPECT_NE(Sin(), Log()); + EXPECT_EQ(Div(), Div()); + EXPECT_NE(Div(), Sub()); + EXPECT_NE(Sub(), Div()); + EXPECT_NE(Div(), UnaryPlus()); + EXPECT_NE(UnaryPlus(), Div()); + EXPECT_NE(Div(), Sin()); + EXPECT_NE(Sin(), Div()); } TEST(IFunctionTests, getArgumentClassesTest) { - EXPECT_THAT(Log().getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic(), INumber::getClassStatic())); + EXPECT_THAT(Div().getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic(), IArithmetic::getClassStatic())); EXPECT_THAT(Neg().getArgumentClasses(), testing::ElementsAre(IArithmetic::getClassStatic())); EXPECT_THAT(Sin().getArgumentClasses(), testing::ElementsAre(INumber::getClassStatic())); } TEST(IFunctionTests, getReturnClassTest) { - EXPECT_EQ(Log().getReturnClass(), INumber::getClassStatic()); + EXPECT_EQ(Div().getReturnClass(), IArithmetic::getClassStatic()); EXPECT_EQ(Neg().getReturnClass(), IArithmetic::getClassStatic()); EXPECT_EQ(Sin().getReturnClass(), INumber::getClassStatic()); } @@ -105,15 +95,15 @@ TEST(IFunctionTests, doArgsMatchTest) { Variable c("c"); { - EXPECT_TRUE(Log().doArgsMatch({a, b})); - EXPECT_FALSE(Log().doArgsMatch({c, c})); - EXPECT_FALSE(Log().doArgsMatch({a, c})); - EXPECT_FALSE(Log().doArgsMatch({c, a})); - - EXPECT_FALSE(Log().doArgsMatch({})); - EXPECT_FALSE(Log().doArgsMatch({a})); - EXPECT_FALSE(Log().doArgsMatch({a, a, a})); - EXPECT_FALSE(Log().doArgsMatch({a, b, a, b})); + EXPECT_TRUE(Div().doArgsMatch({a, b})); + EXPECT_FALSE(Div().doArgsMatch({c, c})); + EXPECT_FALSE(Div().doArgsMatch({a, c})); + EXPECT_FALSE(Div().doArgsMatch({c, a})); + + EXPECT_FALSE(Div().doArgsMatch({})); + EXPECT_FALSE(Div().doArgsMatch({a})); + EXPECT_FALSE(Div().doArgsMatch({a, a, a})); + EXPECT_FALSE(Div().doArgsMatch({a, b, a, b})); } { EXPECT_TRUE(Mul().doArgsMatch({a, b, a})); diff --git a/tests/src/functions/arithmetic/AbsTests.cpp b/tests/src/functions/arithmetic/AbsTests.cpp index b1a6159a4..396f8bb32 100644 --- a/tests/src/functions/arithmetic/AbsTests.cpp +++ b/tests/src/functions/arithmetic/AbsTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/Abs.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -60,8 +61,27 @@ 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(R"(Unable to call Abs "abs" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Abs "abs" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Abs "abs" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Abs "abs" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Abs "abs" with 4 arguments (expected 1))"))); } TEST(AbsTests, exprTest) { diff --git a/tests/src/functions/arithmetic/AddOperTests.cpp b/tests/src/functions/arithmetic/AddOperTests.cpp index da0d2d007..d893a330c 100644 --- a/tests/src/functions/arithmetic/AddOperTests.cpp +++ b/tests/src/functions/arithmetic/AddOperTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/arithmetic/AddOper.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,10 +49,31 @@ TEST(AddOperTests, 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with argument #1 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AddOper "+" with 4 arguments (expected 2))"))); } TEST(AddOperTests, getClassTest) { diff --git a/tests/src/functions/arithmetic/AddTests.cpp b/tests/src/functions/arithmetic/AddTests.cpp index 7c7c5816e..0135ba47a 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/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -50,7 +51,39 @@ TEST(AddTests, callTest) { EXPECT_EQ(f(Integer(5), Variable("a"))->toString(), "a + 5"); EXPECT_EQ(f(Variable("a"), Variable("a"), Variable("b"))->toString(), "2 a + b"); - EXPECT_THROW(f(), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #1 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #2 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #3 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #2 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #1 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with argument #0 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Add "add" with 0 arguments (expected > 0))"))); } TEST(AddTests, exprTest) { diff --git a/tests/src/functions/arithmetic/DivTests.cpp b/tests/src/functions/arithmetic/DivTests.cpp index 1785dfac1..8c844d909 100644 --- a/tests/src/functions/arithmetic/DivTests.cpp +++ b/tests/src/functions/arithmetic/DivTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/arithmetic/Div.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -50,10 +51,31 @@ TEST(DivTests, callTest) { EXPECT_EQ(f(Integer(1), Integer(0))->toString(), "ComplexInf"); EXPECT_EQ(f(Integer(0), Integer(0))->toString(), "Undefined"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with argument #1 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Div "/" with 4 arguments (expected 2))"))); } TEST(DivTests, exprTest) { diff --git a/tests/src/functions/arithmetic/FracMixedTests.cpp b/tests/src/functions/arithmetic/FracMixedTests.cpp index 100a6eadf..dabadcd95 100644 --- a/tests/src/functions/arithmetic/FracMixedTests.cpp +++ b/tests/src/functions/arithmetic/FracMixedTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/arithmetic/FracMixed.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,10 +47,35 @@ TEST(FracMixedTests, callTest) { EXPECT_EQ(f(Integer(0), Integer(3), Variable("a"))->toString(), "3/a"); - 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), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with argument #2 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with argument #1 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with argument #0 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with 0 arguments (expected 3))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with 1 argument (expected 3))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with 2 arguments (expected 3))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call FracMixed "frac" with 4 arguments (expected 3))"))); } TEST(FracMixedTests, getClassTest) { diff --git a/tests/src/functions/arithmetic/FracTests.cpp b/tests/src/functions/arithmetic/FracTests.cpp index 1b6e63545..688385f7d 100644 --- a/tests/src/functions/arithmetic/FracTests.cpp +++ b/tests/src/functions/arithmetic/FracTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/arithmetic/Frac.hpp" #include "fintamath/exceptions/InvalidInputException.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -39,10 +40,31 @@ TEST(FracTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3/a"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Frac "frac" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Frac "frac" with argument #1 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Frac "frac" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Frac "frac" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Frac "frac" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Frac "frac" with 4 arguments (expected 2))"))); } TEST(FracTests, getClassTest) { diff --git a/tests/src/functions/arithmetic/MulOperTests.cpp b/tests/src/functions/arithmetic/MulOperTests.cpp index f6bd039fd..b25da84fd 100644 --- a/tests/src/functions/arithmetic/MulOperTests.cpp +++ b/tests/src/functions/arithmetic/MulOperTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/MulOper.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,10 +47,31 @@ TEST(MulOperTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3 a"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with argument #1 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MulOper "*" with 4 arguments (expected 2))"))); } TEST(MulOperTests, getClassTest) { diff --git a/tests/src/functions/arithmetic/MulTests.cpp b/tests/src/functions/arithmetic/MulTests.cpp index 976a0f72d..737206133 100644 --- a/tests/src/functions/arithmetic/MulTests.cpp +++ b/tests/src/functions/arithmetic/MulTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/Mul.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -50,8 +51,39 @@ TEST(MulTests, callTest) { EXPECT_EQ(f(Integer(5), Variable("a"))->toString(), "5 a"); EXPECT_EQ(f(Variable("a"), Variable("a"), Variable("b"))->toString(), "a^2 b"); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #1 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #2 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #3 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #2 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #1 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with argument #0 Boolean "True" (expected IArithmetic))"))); - EXPECT_THROW(f(), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mul "mul" with 0 arguments (expected > 0))"))); } TEST(MulTests, exprTest) { diff --git a/tests/src/functions/arithmetic/NegTests.cpp b/tests/src/functions/arithmetic/NegTests.cpp index f4f70d82d..34a788d7e 100644 --- a/tests/src/functions/arithmetic/NegTests.cpp +++ b/tests/src/functions/arithmetic/NegTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/Neg.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,9 +46,27 @@ TEST(NegTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "-a"); - EXPECT_THROW(f(Integer(1), Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neg "-" with argument #0 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neg "-" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neg "-" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neg "-" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neg "-" with 4 arguments (expected 1))"))); } TEST(NegTests, exprTest) { diff --git a/tests/src/functions/arithmetic/SignTests.cpp b/tests/src/functions/arithmetic/SignTests.cpp index ab4c5d6d7..bfb799454 100644 --- a/tests/src/functions/arithmetic/SignTests.cpp +++ b/tests/src/functions/arithmetic/SignTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/Sign.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -58,8 +59,27 @@ TEST(SignTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "sign(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sign "sign" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sign "sign" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sign "sign" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sign "sign" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sign "sign" with 4 arguments (expected 1))"))); } TEST(SignTests, exprTest) { diff --git a/tests/src/functions/arithmetic/SubTests.cpp b/tests/src/functions/arithmetic/SubTests.cpp index 600b7a28b..d696a32dc 100644 --- a/tests/src/functions/arithmetic/SubTests.cpp +++ b/tests/src/functions/arithmetic/SubTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/Sub.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,10 +49,31 @@ TEST(SubTests, 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sub "-" with argument #0 Boolean "True" (expected IArithmetic))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sub "-" with argument #1 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sub "-" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sub "-" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sub "-" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sub "-" with 4 arguments (expected 2))"))); } TEST(SubTests, exprTest) { diff --git a/tests/src/functions/arithmetic/UnaryPlusTests.cpp b/tests/src/functions/arithmetic/UnaryPlusTests.cpp index 20f38e888..d3c3321e7 100644 --- a/tests/src/functions/arithmetic/UnaryPlusTests.cpp +++ b/tests/src/functions/arithmetic/UnaryPlusTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/arithmetic/UnaryPlus.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,9 +47,27 @@ TEST(UnaryPlusTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "a"); - EXPECT_THROW(f(Integer(1), Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call UnaryPlus "+" with argument #0 Boolean "True" (expected IArithmetic))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call UnaryPlus "+" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call UnaryPlus "+" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call UnaryPlus "+" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call UnaryPlus "+" with 4 arguments (expected 1))"))); } TEST(UnaryPlusTests, getClassTest) { diff --git a/tests/src/functions/calculus/DerivativeTests.cpp b/tests/src/functions/calculus/DerivativeTests.cpp index 55c78aa93..99ebe00fe 100644 --- a/tests/src/functions/calculus/DerivativeTests.cpp +++ b/tests/src/functions/calculus/DerivativeTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/calculus/Derivative.hpp" #include "fintamath/expressions/Expression.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -85,13 +86,31 @@ TEST(DerivativeTests, callTest) { EXPECT_EQ(f(TestComparable(), Variable("a"))->toString(), "derivative(testderivative, a)"); - EXPECT_THROW(f(Integer(5), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Expression("a+a")), InvalidInputException); - - EXPECT_THROW(f(), InvalidInputException); - EXPECT_THROW(f(Integer(1)), InvalidInputException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputException); + EXPECT_THAT( + [&] { f(Boolean(true), Variable("a")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Derivative "derivative" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Variable("a"), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Derivative "derivative" with argument #1 Boolean "True" (expected Variable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Derivative "derivative" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Derivative "derivative" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Derivative "derivative" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Derivative "derivative" with 4 arguments (expected 2))"))); } TEST(DerivativeTests, exprTest) { diff --git a/tests/src/functions/calculus/IntegralTests.cpp b/tests/src/functions/calculus/IntegralTests.cpp index e34980f3e..4051a00c6 100644 --- a/tests/src/functions/calculus/IntegralTests.cpp +++ b/tests/src/functions/calculus/IntegralTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/calculus/Integral.hpp" #include "fintamath/expressions/Expression.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -39,13 +40,31 @@ TEST(IntegralTests, callTest) { EXPECT_EQ(f(Expression("a+a"), Variable("a"))->toString(), "integral(2 a, a)"); EXPECT_EQ(f(Integer(5), Variable("a"))->toString(), "integral(5, a)"); - EXPECT_THROW(f(Integer(5), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Integer(1)), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Expression("a+a")), InvalidInputException); + EXPECT_THAT( + [&] { f(Boolean(true), Variable("a")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Integral "integral" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Variable("a"), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Integral "integral" with argument #1 Boolean "True" (expected Variable))"))); - EXPECT_THROW(f(), InvalidInputException); - EXPECT_THROW(f(Integer(1)), InvalidInputException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputException); + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Integral "integral" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Integral "integral" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Integral "integral" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Integral "integral" with 4 arguments (expected 2))"))); } TEST(IntegralTests, exprTest) { diff --git a/tests/src/functions/calculus/MaxTests.cpp b/tests/src/functions/calculus/MaxTests.cpp index 3830c9c75..59bc5fd1c 100644 --- a/tests/src/functions/calculus/MaxTests.cpp +++ b/tests/src/functions/calculus/MaxTests.cpp @@ -44,13 +44,39 @@ TEST(MaxTests, callTest) { EXPECT_EQ(f(Rational(-1), Variable("x"), Variable("y"), Integer(1))->toString(), "max(x, y, 1)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer(), Integer()), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #1 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #2 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #3 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #2 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #1 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with argument #0 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Max "max" with 0 arguments (expected > 0))"))); } TEST(MaxTests, exprTest) { diff --git a/tests/src/functions/calculus/MinTests.cpp b/tests/src/functions/calculus/MinTests.cpp index e978e1d2e..3bde1059d 100644 --- a/tests/src/functions/calculus/MinTests.cpp +++ b/tests/src/functions/calculus/MinTests.cpp @@ -44,13 +44,39 @@ TEST(MinTests, callTest) { EXPECT_EQ(f(Rational(-1), Variable("x"), Variable("y"), Integer(1))->toString(), "min(x, y, -1)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Integer(), Boolean()), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(), Boolean(), Integer()), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(), Integer(), Integer()), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #1 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #2 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #3 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Boolean(true), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #2 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #1 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with argument #0 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Min "min" with 0 arguments (expected > 0))"))); } TEST(MinTests, exprTest) { diff --git a/tests/src/functions/comparison/EqvTests.cpp b/tests/src/functions/comparison/EqvTests.cpp index 1fa170f84..824dffb31 100644 --- a/tests/src/functions/comparison/EqvTests.cpp +++ b/tests/src/functions/comparison/EqvTests.cpp @@ -54,10 +54,31 @@ TEST(EqvTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 = 0"); EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "True"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with argument #1 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Eqv "=" with 4 arguments (expected 2))"))); } TEST(EqvTests, exprTest) { diff --git a/tests/src/functions/comparison/LessEqvTests.cpp b/tests/src/functions/comparison/LessEqvTests.cpp index b4b4e1612..1d604c576 100644 --- a/tests/src/functions/comparison/LessEqvTests.cpp +++ b/tests/src/functions/comparison/LessEqvTests.cpp @@ -54,10 +54,31 @@ TEST(LessEqvTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 >= 0"); EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "True"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call LessEqv "<=" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call LessEqv "<=" with argument #1 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call LessEqv "<=" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call LessEqv "<=" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call LessEqv "<=" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call LessEqv "<=" with 4 arguments (expected 2))"))); } TEST(LessEqvTests, exprTest) { diff --git a/tests/src/functions/comparison/LessTests.cpp b/tests/src/functions/comparison/LessTests.cpp index 4d36a2068..24d7c68a5 100644 --- a/tests/src/functions/comparison/LessTests.cpp +++ b/tests/src/functions/comparison/LessTests.cpp @@ -54,10 +54,31 @@ TEST(LessTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 > 0"); EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "False"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Less "<" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Less "<" with argument #1 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Less "<" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Less "<" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Less "<" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Less "<" with 4 arguments (expected 2))"))); } TEST(LessTests, exprTest) { diff --git a/tests/src/functions/comparison/MoreEqvTests.cpp b/tests/src/functions/comparison/MoreEqvTests.cpp index b8ea36c27..80d57ddfe 100644 --- a/tests/src/functions/comparison/MoreEqvTests.cpp +++ b/tests/src/functions/comparison/MoreEqvTests.cpp @@ -54,10 +54,31 @@ TEST(MoreEqvTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 <= 0"); EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "True"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MoreEqv ">=" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MoreEqv ">=" with argument #1 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MoreEqv ">=" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MoreEqv ">=" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MoreEqv ">=" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call MoreEqv ">=" with 4 arguments (expected 2))"))); } TEST(MoreEqvTests, exprTest) { diff --git a/tests/src/functions/comparison/MoreTests.cpp b/tests/src/functions/comparison/MoreTests.cpp index 25a64b474..da8b175b8 100644 --- a/tests/src/functions/comparison/MoreTests.cpp +++ b/tests/src/functions/comparison/MoreTests.cpp @@ -54,10 +54,31 @@ TEST(MoreTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 < 0"); EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "False"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call More ">" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call More ">" with argument #1 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call More ">" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call More ">" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call More ">" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call More ">" with 4 arguments (expected 2))"))); } TEST(MoreTests, exprTest) { diff --git a/tests/src/functions/comparison/NeqvTests.cpp b/tests/src/functions/comparison/NeqvTests.cpp index cb9fac49a..cad2f36f2 100644 --- a/tests/src/functions/comparison/NeqvTests.cpp +++ b/tests/src/functions/comparison/NeqvTests.cpp @@ -54,10 +54,31 @@ TEST(NeqvTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "a - 3 != 0"); EXPECT_EQ(f(Variable("a"), Variable("a"))->toString(), "False"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neqv "!=" with argument #0 Boolean "True" (expected IComparable))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neqv "!=" with argument #1 Boolean "True" (expected IComparable))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neqv "!=" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neqv "!=" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neqv "!=" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Neqv "!=" with 4 arguments (expected 2))"))); } TEST(NeqvTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/AcoshTests.cpp b/tests/src/functions/hyperbolic/AcoshTests.cpp index f1756259d..03926b51f 100644 --- a/tests/src/functions/hyperbolic/AcoshTests.cpp +++ b/tests/src/functions/hyperbolic/AcoshTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Acosh.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AcoshTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "acosh(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acosh "acosh" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acosh "acosh" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acosh "acosh" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acosh "acosh" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acosh "acosh" with 4 arguments (expected 1))"))); } TEST(AcoshTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/AcothTests.cpp b/tests/src/functions/hyperbolic/AcothTests.cpp index 6e0632490..cc657228c 100644 --- a/tests/src/functions/hyperbolic/AcothTests.cpp +++ b/tests/src/functions/hyperbolic/AcothTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Acoth.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AcothTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "acoth(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acoth "acoth" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acoth "acoth" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acoth "acoth" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acoth "acoth" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acoth "acoth" with 4 arguments (expected 1))"))); } TEST(AcothTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/AcschTests.cpp b/tests/src/functions/hyperbolic/AcschTests.cpp index a770081ee..65eab950a 100644 --- a/tests/src/functions/hyperbolic/AcschTests.cpp +++ b/tests/src/functions/hyperbolic/AcschTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Acsch.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -47,8 +48,27 @@ TEST(AcschTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "acsch(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsch "acsch" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsch "acsch" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsch "acsch" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsch "acsch" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsch "acsch" with 4 arguments (expected 1))"))); } TEST(AcschTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/AsechTests.cpp b/tests/src/functions/hyperbolic/AsechTests.cpp index d74dfa16e..a8eb5317a 100644 --- a/tests/src/functions/hyperbolic/AsechTests.cpp +++ b/tests/src/functions/hyperbolic/AsechTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Asech.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AsechTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "asech(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asech "asech" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asech "asech" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asech "asech" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asech "asech" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asech "asech" with 4 arguments (expected 1))"))); } TEST(AsechTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/AsinhTests.cpp b/tests/src/functions/hyperbolic/AsinhTests.cpp index 0eccdfbd8..6d7fe8ad5 100644 --- a/tests/src/functions/hyperbolic/AsinhTests.cpp +++ b/tests/src/functions/hyperbolic/AsinhTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Asinh.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(AsinhTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "asinh(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asinh "asinh" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asinh "asinh" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asinh "asinh" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asinh "asinh" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asinh "asinh" with 4 arguments (expected 1))"))); } TEST(AsinhTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/AtanhTests.cpp b/tests/src/functions/hyperbolic/AtanhTests.cpp index 77f264830..aca70dda4 100644 --- a/tests/src/functions/hyperbolic/AtanhTests.cpp +++ b/tests/src/functions/hyperbolic/AtanhTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Atanh.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AtanhTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "atanh(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atanh "atanh" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atanh "atanh" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atanh "atanh" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atanh "atanh" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atanh "atanh" with 4 arguments (expected 1))"))); } TEST(AtanhTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/CoshTests.cpp b/tests/src/functions/hyperbolic/CoshTests.cpp index 4df0ffc25..d8e4c09a1 100644 --- a/tests/src/functions/hyperbolic/CoshTests.cpp +++ b/tests/src/functions/hyperbolic/CoshTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Cosh.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(CoshTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "cosh(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cosh "cosh" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cosh "cosh" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cosh "cosh" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cosh "cosh" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cosh "cosh" with 4 arguments (expected 1))"))); } TEST(CoshTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/CothTests.cpp b/tests/src/functions/hyperbolic/CothTests.cpp index ea2feca67..6265f5d5c 100644 --- a/tests/src/functions/hyperbolic/CothTests.cpp +++ b/tests/src/functions/hyperbolic/CothTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Coth.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,8 +47,27 @@ TEST(CothTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "coth(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Coth "coth" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Coth "coth" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Coth "coth" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Coth "coth" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Coth "coth" with 4 arguments (expected 1))"))); } TEST(CothTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/CschTests.cpp b/tests/src/functions/hyperbolic/CschTests.cpp index 3ec09c1dc..60d0d153f 100644 --- a/tests/src/functions/hyperbolic/CschTests.cpp +++ b/tests/src/functions/hyperbolic/CschTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Csch.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(CschTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "csch(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csch "csch" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csch "csch" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csch "csch" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csch "csch" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csch "csch" with 4 arguments (expected 1))"))); } TEST(CschTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/SechTests.cpp b/tests/src/functions/hyperbolic/SechTests.cpp index 675400b6f..784a2180e 100644 --- a/tests/src/functions/hyperbolic/SechTests.cpp +++ b/tests/src/functions/hyperbolic/SechTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Sech.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,8 +47,27 @@ TEST(SechTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "sech(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sech "sech" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sech "sech" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sech "sech" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sech "sech" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sech "sech" with 4 arguments (expected 1))"))); } TEST(SechTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/SinhTests.cpp b/tests/src/functions/hyperbolic/SinhTests.cpp index 1928fd5dd..085f85b1f 100644 --- a/tests/src/functions/hyperbolic/SinhTests.cpp +++ b/tests/src/functions/hyperbolic/SinhTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Sinh.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(SinhTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "sinh(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sinh "sinh" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sinh "sinh" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sinh "sinh" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sinh "sinh" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sinh "sinh" with 4 arguments (expected 1))"))); } TEST(SinhTests, exprTest) { diff --git a/tests/src/functions/hyperbolic/TanhTests.cpp b/tests/src/functions/hyperbolic/TanhTests.cpp index 54a0a3ca6..4277e2ed7 100644 --- a/tests/src/functions/hyperbolic/TanhTests.cpp +++ b/tests/src/functions/hyperbolic/TanhTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/hyperbolic/Tanh.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(TanhTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "tanh(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tanh "tanh" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tanh "tanh" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tanh "tanh" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tanh "tanh" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tanh "tanh" with 4 arguments (expected 1))"))); } TEST(TanhTests, exprTest) { diff --git a/tests/src/functions/logarithms/LbTests.cpp b/tests/src/functions/logarithms/LbTests.cpp index 2168123cc..b7a0c521b 100644 --- a/tests/src/functions/logarithms/LbTests.cpp +++ b/tests/src/functions/logarithms/LbTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/logarithms/Lb.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -41,8 +42,27 @@ TEST(LbTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "log(2, a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lb "lb" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lb "lb" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lb "lb" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lb "lb" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lb "lb" with 4 arguments (expected 1))"))); } TEST(LbTests, exprTest) { diff --git a/tests/src/functions/logarithms/LgTests.cpp b/tests/src/functions/logarithms/LgTests.cpp index 19010d9fa..bf89830ae 100644 --- a/tests/src/functions/logarithms/LgTests.cpp +++ b/tests/src/functions/logarithms/LgTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/logarithms/Lg.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -41,8 +42,27 @@ TEST(LgTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "log(10, a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lg "lg" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lg "lg" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lg "lg" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lg "lg" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Lg "lg" with 4 arguments (expected 1))"))); } TEST(LgTests, exprTest) { diff --git a/tests/src/functions/logarithms/LnTests.cpp b/tests/src/functions/logarithms/LnTests.cpp index 4666aa6d5..362586cbc 100644 --- a/tests/src/functions/logarithms/LnTests.cpp +++ b/tests/src/functions/logarithms/LnTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/logarithms/Ln.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" #include "fintamath/numbers/Rational.hpp" @@ -43,8 +44,27 @@ TEST(LnTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "ln(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ln "ln" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ln "ln" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ln "ln" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ln "ln" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ln "ln" with 4 arguments (expected 1))"))); } TEST(LnTests, exprTest) { diff --git a/tests/src/functions/logarithms/LogTests.cpp b/tests/src/functions/logarithms/LogTests.cpp index 3480d6252..d37e87744 100644 --- a/tests/src/functions/logarithms/LogTests.cpp +++ b/tests/src/functions/logarithms/LogTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/logarithms/Log.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -121,9 +122,31 @@ TEST(LogTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "log(a, b)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10)), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(10), Integer(10), Integer(10)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Log "log" with argument #0 Boolean "True" (expected INumber))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Log "log" with argument #1 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Log "log" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Log "log" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Log "log" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Log "log" with 4 arguments (expected 2))"))); } TEST(LogTests, exprTest) { diff --git a/tests/src/functions/logic/AndOperTests.cpp b/tests/src/functions/logic/AndOperTests.cpp index f3cc302fb..9bc1e7ae7 100644 --- a/tests/src/functions/logic/AndOperTests.cpp +++ b/tests/src/functions/logic/AndOperTests.cpp @@ -46,9 +46,31 @@ TEST(AndOperTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "a & b"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AndOper "&" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AndOper "&" with argument #1 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AndOper "&" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AndOper "&" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AndOper "&" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call AndOper "&" with 4 arguments (expected 2))"))); } TEST(AndOperTests, getClassTest) { diff --git a/tests/src/functions/logic/AndTests.cpp b/tests/src/functions/logic/AndTests.cpp index a3abd7768..fca857a89 100644 --- a/tests/src/functions/logic/AndTests.cpp +++ b/tests/src/functions/logic/AndTests.cpp @@ -55,7 +55,39 @@ TEST(AndTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"), Boolean("True"), Variable("c"))->toString(), "a & b & c"); EXPECT_EQ(f(Boolean("False"), Variable("a"), Variable("b"), Variable("c"))->toString(), "False"); - EXPECT_THROW(f(), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #1 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #2 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #3 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #2 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #1 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with argument #0 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call And "and" with 0 arguments (expected > 0))"))); } TEST(AndTests, exprTest) { diff --git a/tests/src/functions/logic/EquivTests.cpp b/tests/src/functions/logic/EquivTests.cpp index 6e190f64c..ba50c736a 100644 --- a/tests/src/functions/logic/EquivTests.cpp +++ b/tests/src/functions/logic/EquivTests.cpp @@ -46,9 +46,31 @@ TEST(EquivTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "(~a & ~b) | (a & b)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Equiv "<->" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Equiv "<->" with argument #1 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Equiv "<->" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Equiv "<->" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Equiv "<->" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Equiv "<->" with 4 arguments (expected 2))"))); } TEST(EquivTests, exprTest) { diff --git a/tests/src/functions/logic/ImplTests.cpp b/tests/src/functions/logic/ImplTests.cpp index 9f4c5a70d..014ace640 100644 --- a/tests/src/functions/logic/ImplTests.cpp +++ b/tests/src/functions/logic/ImplTests.cpp @@ -46,9 +46,31 @@ TEST(ImplTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "~a | b"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Impl "->" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Impl "->" with argument #1 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Impl "->" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Impl "->" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Impl "->" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Impl "->" with 4 arguments (expected 2))"))); } TEST(ImplTests, exprTest) { diff --git a/tests/src/functions/logic/NequivTests.cpp b/tests/src/functions/logic/NequivTests.cpp index 400156eb8..158667025 100644 --- a/tests/src/functions/logic/NequivTests.cpp +++ b/tests/src/functions/logic/NequivTests.cpp @@ -46,9 +46,31 @@ TEST(NequivTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "(~a & b) | (a & ~b)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Nequiv "!<->" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Nequiv "!<->" with argument #1 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Nequiv "!<->" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Nequiv "!<->" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Nequiv "!<->" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Nequiv "!<->" with 4 arguments (expected 2))"))); } TEST(NequivTests, exprTest) { diff --git a/tests/src/functions/logic/NotTests.cpp b/tests/src/functions/logic/NotTests.cpp index 2ab7adddb..eeaf793af 100644 --- a/tests/src/functions/logic/NotTests.cpp +++ b/tests/src/functions/logic/NotTests.cpp @@ -44,9 +44,27 @@ TEST(NotTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "~a"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Not "~" with argument #0 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Not "~" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Not "~" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Not "~" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Not "~" with 4 arguments (expected 1))"))); } TEST(NotTests, exprTest) { diff --git a/tests/src/functions/logic/OrOperTests.cpp b/tests/src/functions/logic/OrOperTests.cpp index affe97223..a1cf64008 100644 --- a/tests/src/functions/logic/OrOperTests.cpp +++ b/tests/src/functions/logic/OrOperTests.cpp @@ -46,9 +46,31 @@ TEST(OrOperTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"))->toString(), "a | b"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true)), InvalidInputFunctionException); - EXPECT_THROW(f(Boolean(true), Boolean(true), Boolean(true)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call OrOper "|" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call OrOper "|" with argument #1 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call OrOper "|" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call OrOper "|" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call OrOper "|" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Boolean(false)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call OrOper "|" with 4 arguments (expected 2))"))); } TEST(OrOperTests, getClassTest) { diff --git a/tests/src/functions/logic/OrTests.cpp b/tests/src/functions/logic/OrTests.cpp index efc8089b6..d78230495 100644 --- a/tests/src/functions/logic/OrTests.cpp +++ b/tests/src/functions/logic/OrTests.cpp @@ -55,7 +55,39 @@ TEST(OrTests, callTest) { EXPECT_EQ(f(Variable("a"), Variable("b"), Boolean("True"), Variable("c"))->toString(), "True"); EXPECT_EQ(f(Boolean("False"), Variable("a"), Variable("b"), Variable("c"))->toString(), "a | b | c"); - EXPECT_THROW(f(), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #0 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #1 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #2 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #3 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Boolean(false), Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #2 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #1 Integer "1" (expected Boolean))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true), Boolean(false), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with argument #0 Integer "1" (expected Boolean))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Or "or" with 0 arguments (expected > 0))"))); } TEST(OrTests, exprTest) { diff --git a/tests/src/functions/ntheory/CeilTests.cpp b/tests/src/functions/ntheory/CeilTests.cpp index 76ad3c129..af78a48cc 100644 --- a/tests/src/functions/ntheory/CeilTests.cpp +++ b/tests/src/functions/ntheory/CeilTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/ntheory/Ceil.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -71,8 +72,27 @@ TEST(CeilTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "ceil(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ceil "ceil" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ceil "ceil" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ceil "ceil" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ceil "ceil" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Ceil "ceil" with 4 arguments (expected 1))"))); } TEST(CeilTests, exprTest) { diff --git a/tests/src/functions/ntheory/FloorTests.cpp b/tests/src/functions/ntheory/FloorTests.cpp index 2c5e0120c..f59044c79 100644 --- a/tests/src/functions/ntheory/FloorTests.cpp +++ b/tests/src/functions/ntheory/FloorTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/ntheory/Floor.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -71,8 +72,27 @@ TEST(FloorTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "floor(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Floor "floor" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Floor "floor" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Floor "floor" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Floor "floor" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Floor "floor" with 4 arguments (expected 1))"))); } TEST(FloorTests, exprTest) { diff --git a/tests/src/functions/ntheory/ModTests.cpp b/tests/src/functions/ntheory/ModTests.cpp index 2de2d5f8c..9dab4491a 100644 --- a/tests/src/functions/ntheory/ModTests.cpp +++ b/tests/src/functions/ntheory/ModTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/ntheory/Mod.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -88,10 +89,31 @@ TEST(ModTests, callTest) { EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3 mod a"); - 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), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mod "mod" with argument #0 Boolean "True" (expected INumber))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mod "mod" with argument #1 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mod "mod" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mod "mod" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mod "mod" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Mod "mod" with 4 arguments (expected 2))"))); } TEST(ModTests, exprTest) { diff --git a/tests/src/functions/other/CommaTests.cpp b/tests/src/functions/other/CommaTests.cpp index d769dc380..39b05ed40 100644 --- a/tests/src/functions/other/CommaTests.cpp +++ b/tests/src/functions/other/CommaTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/other/Comma.hpp" #include "fintamath/expressions/Expression.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" @@ -40,10 +41,27 @@ TEST(CommaTests, isAssociativeTest) { } TEST(CommaTests, callTest) { - EXPECT_THROW(f(Variable("a"), Variable("a"))->toString(), InvalidInputException); + EXPECT_THAT( + [&] { f(Variable("a"), Variable("a")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Calling Comma directly is not allowed)"))); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Comma "," with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Comma "," with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Comma "," with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Comma "," with 4 arguments (expected 2))"))); } TEST(CommaTests, exprTest) { diff --git a/tests/src/functions/other/DegTests.cpp b/tests/src/functions/other/DegTests.cpp index b01a7171e..42cd93193 100644 --- a/tests/src/functions/other/DegTests.cpp +++ b/tests/src/functions/other/DegTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/other/Deg.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -47,8 +48,27 @@ TEST(DegTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "(Pi a)/180"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Deg "deg" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Deg "deg" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Deg "deg" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Deg "deg" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Deg "deg" with 4 arguments (expected 1))"))); } TEST(DegTests, degTest) { diff --git a/tests/src/functions/other/FactorialTests.cpp b/tests/src/functions/other/FactorialTests.cpp index 92c0f0ad2..cc1181d9d 100644 --- a/tests/src/functions/other/FactorialTests.cpp +++ b/tests/src/functions/other/FactorialTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/other/Factorial.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -67,8 +68,27 @@ TEST(FactorialTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "a!"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Factorial "!" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Factorial "!" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Factorial "!" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Factorial "!" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Factorial "!" with 4 arguments (expected 1))"))); } TEST(FactorialTests, callDoubleFactorialTest) { @@ -93,9 +113,6 @@ TEST(FactorialTests, callDoubleFactorialTest) { EXPECT_EQ(f2(Real(-10))->toString(), "(-10.0)!!"); EXPECT_EQ(f2(Variable("a"))->toString(), "a!!"); - - EXPECT_THROW(f2(), InvalidInputFunctionException); - EXPECT_THROW(f2(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } TEST(FactorialTests, callTripleFactorialTest) { @@ -120,9 +137,6 @@ TEST(FactorialTests, callTripleFactorialTest) { EXPECT_EQ(f3(Real(-10))->toString(), "(-10.0)!!!"); EXPECT_EQ(f3(Variable("a"))->toString(), "a!!!"); - - EXPECT_THROW(f3(), InvalidInputFunctionException); - EXPECT_THROW(f3(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); } TEST(FactorialTests, getSetOrderTest) { diff --git a/tests/src/functions/other/IndexTests.cpp b/tests/src/functions/other/IndexTests.cpp index b15baf11a..70ba261be 100644 --- a/tests/src/functions/other/IndexTests.cpp +++ b/tests/src/functions/other/IndexTests.cpp @@ -4,6 +4,7 @@ #include "fintamath/functions/other/Index.hpp" #include "fintamath/expressions/Expression.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Integer.hpp" @@ -46,16 +47,31 @@ TEST(IndexTests, callTest) { EXPECT_EQ(f(Variable("a"), Integer("100000000000000000000000000000000"))->toString(), "a_100000000000000000000000000000000"); - EXPECT_THROW(f(Variable("a"), Variable("a"))->toString(), InvalidInputException); - EXPECT_THROW(f(Variable("a"), Expression("a+1"))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a"), Integer(-1))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("1"), Integer(2))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a+1"), Integer(2))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a+1"), Expression("a+1"))->toString(), InvalidInputException); - EXPECT_THROW(f(Expression("a"), Expression("a>1"))->toString(), InvalidInputException); - - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Index "_" with argument #0 Boolean "True" (expected Variable))"))); + EXPECT_THAT( + [&] { f(Variable("a"), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Index "_" with argument #1 Boolean "True" (expected Integer))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Index "_" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Index "_" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Index "_" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Index "_" with 4 arguments (expected 2))"))); } TEST(IndexTests, exprTest) { diff --git a/tests/src/functions/other/PercentTests.cpp b/tests/src/functions/other/PercentTests.cpp index e1812b26f..2ba4073d3 100644 --- a/tests/src/functions/other/PercentTests.cpp +++ b/tests/src/functions/other/PercentTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/other/Percent.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,8 +47,27 @@ TEST(PercentTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "a/100"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Percent "%" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Percent "%" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Percent "%" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Percent "%" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Percent "%" with 4 arguments (expected 1))"))); } TEST(PercentTests, degTest) { diff --git a/tests/src/functions/powers/ExpTests.cpp b/tests/src/functions/powers/ExpTests.cpp index c00995609..55c58ea73 100644 --- a/tests/src/functions/powers/ExpTests.cpp +++ b/tests/src/functions/powers/ExpTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/powers/Exp.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" @@ -37,8 +38,27 @@ TEST(ExpTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "E^a"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Exp "exp" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Exp "exp" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Exp "exp" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Exp "exp" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Exp "exp" with 4 arguments (expected 1))"))); } TEST(ExpTests, exprTest) { diff --git a/tests/src/functions/powers/PowOperTests.cpp b/tests/src/functions/powers/PowOperTests.cpp index 86579ba42..a1a217c56 100644 --- a/tests/src/functions/powers/PowOperTests.cpp +++ b/tests/src/functions/powers/PowOperTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/powers/PowOper.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,10 +49,31 @@ TEST(PowOperTests, callTest) { EXPECT_EQ(f(Variable("a"), Rational(1, 2))->toString(), "sqrt(a)"); EXPECT_EQ(f(Variable("a"), Rational(3, 2))->toString(), "a^(3/2)"); - EXPECT_THROW(f(), InvalidInputException); - EXPECT_THROW(f(Integer(1)), InvalidInputException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputException); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with argument #0 Boolean "True" (expected INumber))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with argument #1 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call PowOper "^" with 4 arguments (expected 2))"))); } TEST(PowOperTests, getClassTest) { diff --git a/tests/src/functions/powers/PowTests.cpp b/tests/src/functions/powers/PowTests.cpp index 383723c0a..ae14deccb 100644 --- a/tests/src/functions/powers/PowTests.cpp +++ b/tests/src/functions/powers/PowTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/powers/Pow.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -149,10 +150,31 @@ TEST(PowTests, callTest) { EXPECT_EQ(f(Variable("a"), Rational(3, 2))->toString(), "a^(3/2)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1)), InvalidInputFunctionException); - EXPECT_THROW(f(Rational(2, 3)), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Pow "pow" with argument #0 Boolean "True" (expected INumber))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Pow "pow" with argument #1 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Pow "pow" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Pow "pow" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Pow "pow" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Pow "pow" with 4 arguments (expected 2))"))); } TEST(PowTests, exprTest) { diff --git a/tests/src/functions/powers/RootTests.cpp b/tests/src/functions/powers/RootTests.cpp index 1fc401358..036d65ad6 100644 --- a/tests/src/functions/powers/RootTests.cpp +++ b/tests/src/functions/powers/RootTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/powers/Root.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" #include "fintamath/numbers/Real.hpp" @@ -173,8 +174,31 @@ TEST(RootTests, callTest) { EXPECT_EQ(f(Integer(2), Variable("a"))->toString(), "root(2, a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true), Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Root "root" with argument #0 Boolean "True" (expected INumber))"))); + EXPECT_THAT( + [&] { f(Integer(1), Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Root "root" with argument #1 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Root "root" with 0 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Root "root" with 1 argument (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Root "root" with 3 arguments (expected 2))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Root "root" with 4 arguments (expected 2))"))); } TEST(RootTests, exprTest) { diff --git a/tests/src/functions/powers/SqrTests.cpp b/tests/src/functions/powers/SqrTests.cpp index bcffcb2c5..a0af22ae9 100644 --- a/tests/src/functions/powers/SqrTests.cpp +++ b/tests/src/functions/powers/SqrTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/powers/Sqr.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" #include "fintamath/numbers/Real.hpp" @@ -42,8 +43,27 @@ TEST(SqrTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "a^2"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqr "sqr" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqr "sqr" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqr "sqr" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqr "sqr" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqr "sqr" with 4 arguments (expected 1))"))); } TEST(SqrTests, exprTest) { diff --git a/tests/src/functions/powers/SqrtTests.cpp b/tests/src/functions/powers/SqrtTests.cpp index a9edf5065..235b42215 100644 --- a/tests/src/functions/powers/SqrtTests.cpp +++ b/tests/src/functions/powers/SqrtTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/powers/Sqrt.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Rational.hpp" #include "fintamath/numbers/Real.hpp" @@ -61,8 +62,27 @@ TEST(SqrtTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "sqrt(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqrt "sqrt" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqrt "sqrt" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqrt "sqrt" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqrt "sqrt" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sqrt "sqrt" with 4 arguments (expected 1))"))); } TEST(SqrtTests, exprTest) { diff --git a/tests/src/functions/trigonometry/AcosTests.cpp b/tests/src/functions/trigonometry/AcosTests.cpp index 586161d44..6ac76a2da 100644 --- a/tests/src/functions/trigonometry/AcosTests.cpp +++ b/tests/src/functions/trigonometry/AcosTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Acos.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AcosTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "acos(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acos "acos" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acos "acos" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acos "acos" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acos "acos" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acos "acos" with 4 arguments (expected 1))"))); } TEST(AcosTests, exprTest) { diff --git a/tests/src/functions/trigonometry/AcotTests.cpp b/tests/src/functions/trigonometry/AcotTests.cpp index dade7662b..567a4b70a 100644 --- a/tests/src/functions/trigonometry/AcotTests.cpp +++ b/tests/src/functions/trigonometry/AcotTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Acot.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AcotTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "acot(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acot "acot" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acot "acot" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acot "acot" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acot "acot" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acot "acot" with 4 arguments (expected 1))"))); } TEST(AcotTests, exprTest) { diff --git a/tests/src/functions/trigonometry/AcscTests.cpp b/tests/src/functions/trigonometry/AcscTests.cpp index c5d9ca09b..1bf457171 100644 --- a/tests/src/functions/trigonometry/AcscTests.cpp +++ b/tests/src/functions/trigonometry/AcscTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Acsc.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -42,15 +43,33 @@ TEST(AcscTests, callTest) { EXPECT_EQ(f(Rational(1, 10))->toString(), "acsc(1/10)"); EXPECT_EQ(f(Rational(-1, 5))->toString(), "acsc(-1/5)"); - EXPECT_EQ(f(Real("0.5"))->toString(), - "acsc(0.5)"); + EXPECT_EQ(f(Real("0.5"))->toString(), "acsc(0.5)"); EXPECT_EQ(f(Complex(1, 1))->toString(), "acsc(1 + I)"); EXPECT_EQ(f(Variable("a"))->toString(), "acsc(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsc "acsc" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsc "acsc" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsc "acsc" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsc "acsc" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Acsc "acsc" with 4 arguments (expected 1))"))); } TEST(AcscTests, exprTest) { diff --git a/tests/src/functions/trigonometry/AsecTests.cpp b/tests/src/functions/trigonometry/AsecTests.cpp index 8c0cbab3d..e3bb0b618 100644 --- a/tests/src/functions/trigonometry/AsecTests.cpp +++ b/tests/src/functions/trigonometry/AsecTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Asec.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -49,8 +50,27 @@ TEST(AsecTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "asec(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asec "asec" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asec "asec" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asec "asec" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asec "asec" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asec "asec" with 4 arguments (expected 1))"))); } TEST(AsecTests, exprTest) { diff --git a/tests/src/functions/trigonometry/AsinTests.cpp b/tests/src/functions/trigonometry/AsinTests.cpp index 43213ad90..9e7add770 100644 --- a/tests/src/functions/trigonometry/AsinTests.cpp +++ b/tests/src/functions/trigonometry/AsinTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Asin.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AsinTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "asin(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asin "asin" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asin "asin" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asin "asin" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asin "asin" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Asin "asin" with 4 arguments (expected 1))"))); } TEST(AsinTests, exprTest) { diff --git a/tests/src/functions/trigonometry/AtanTests.cpp b/tests/src/functions/trigonometry/AtanTests.cpp index 1301ac948..ac6e240af 100644 --- a/tests/src/functions/trigonometry/AtanTests.cpp +++ b/tests/src/functions/trigonometry/AtanTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Atan.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -48,8 +49,27 @@ TEST(AtanTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "atan(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atan "atan" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atan "atan" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atan "atan" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atan "atan" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Atan "atan" with 4 arguments (expected 1))"))); } TEST(AtanTests, exprTest) { diff --git a/tests/src/functions/trigonometry/CosTests.cpp b/tests/src/functions/trigonometry/CosTests.cpp index 2f7749643..ec3c5b0ea 100644 --- a/tests/src/functions/trigonometry/CosTests.cpp +++ b/tests/src/functions/trigonometry/CosTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Cos.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(CosTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "cos(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cos "cos" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cos "cos" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cos "cos" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cos "cos" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cos "cos" with 4 arguments (expected 1))"))); } TEST(CosTests, exprTest) { diff --git a/tests/src/functions/trigonometry/CotTests.cpp b/tests/src/functions/trigonometry/CotTests.cpp index 10e98f763..2c7f85592 100644 --- a/tests/src/functions/trigonometry/CotTests.cpp +++ b/tests/src/functions/trigonometry/CotTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Cot.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,8 +47,27 @@ TEST(CotTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "cot(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cot "cot" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cot "cot" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cot "cot" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cot "cot" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Cot "cot" with 4 arguments (expected 1))"))); } TEST(CotTests, exprTest) { diff --git a/tests/src/functions/trigonometry/CscTests.cpp b/tests/src/functions/trigonometry/CscTests.cpp index 5bb542564..48e159f42 100644 --- a/tests/src/functions/trigonometry/CscTests.cpp +++ b/tests/src/functions/trigonometry/CscTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Csc.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(CscTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "csc(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csc "csc" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csc "csc" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csc "csc" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csc "csc" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Csc "csc" with 4 arguments (expected 1))"))); } TEST(CscTests, exprTest) { diff --git a/tests/src/functions/trigonometry/SecTests.cpp b/tests/src/functions/trigonometry/SecTests.cpp index 9e3aa5a8d..d2a4aaf93 100644 --- a/tests/src/functions/trigonometry/SecTests.cpp +++ b/tests/src/functions/trigonometry/SecTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Sec.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(SecTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "sec(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sec "sec" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sec "sec" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sec "sec" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sec "sec" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sec "sec" with 4 arguments (expected 1))"))); } TEST(SecTests, exprTest) { diff --git a/tests/src/functions/trigonometry/SinTests.cpp b/tests/src/functions/trigonometry/SinTests.cpp index bf5dea866..94cb53fae 100644 --- a/tests/src/functions/trigonometry/SinTests.cpp +++ b/tests/src/functions/trigonometry/SinTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Sin.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -45,8 +46,27 @@ TEST(SinTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "sin(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sin "sin" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sin "sin" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sin "sin" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sin "sin" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Sin "sin" with 4 arguments (expected 1))"))); } TEST(SinTests, exprTest) { diff --git a/tests/src/functions/trigonometry/TanTests.cpp b/tests/src/functions/trigonometry/TanTests.cpp index be16e5a6f..6da00c707 100644 --- a/tests/src/functions/trigonometry/TanTests.cpp +++ b/tests/src/functions/trigonometry/TanTests.cpp @@ -3,6 +3,7 @@ #include "fintamath/functions/trigonometry/Tan.hpp" +#include "fintamath/literals/Boolean.hpp" #include "fintamath/literals/Variable.hpp" #include "fintamath/numbers/Complex.hpp" #include "fintamath/numbers/Rational.hpp" @@ -46,8 +47,27 @@ TEST(TanTests, callTest) { EXPECT_EQ(f(Variable("a"))->toString(), "tan(a)"); - EXPECT_THROW(f(), InvalidInputFunctionException); - EXPECT_THROW(f(Integer(1), Integer(1), Integer(1)), InvalidInputFunctionException); + EXPECT_THAT( + [&] { f(Boolean(true)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tan "tan" with argument #0 Boolean "True" (expected INumber))"))); + + EXPECT_THAT( + [&] { f(); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tan "tan" with 0 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tan "tan" with 2 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tan "tan" with 3 arguments (expected 1))"))); + EXPECT_THAT( + [&] { f(Integer(1), Integer(2), Integer(3), Integer(4)); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to call Tan "tan" with 4 arguments (expected 1))"))); } TEST(TanTests, exprTest) { diff --git a/tests/src/literals/BooleanTests.cpp b/tests/src/literals/BooleanTests.cpp index a888038ae..dd4d35790 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("True"), true); EXPECT_EQ(Boolean("False"), false); - EXPECT_THROW(Boolean("true"), InvalidInputException); - EXPECT_THROW(Boolean("false"), InvalidInputException); - EXPECT_THROW(Boolean("10"), InvalidInputException); - EXPECT_THROW(Boolean("i"), InvalidInputException); - EXPECT_THROW(Boolean(""), InvalidInputException); - EXPECT_THROW(Boolean(""), InvalidInputException); + EXPECT_THAT( + [] { Boolean(std::string("")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Boolean from "" (expected "True" or "False"))"))); + EXPECT_THAT( + [] { Boolean(std::string("true")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Boolean from "true" (expected "True" or "False"))"))); + EXPECT_THAT( + [] { Boolean(std::string("false")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Boolean from "false" (expected "True" or "False"))"))); + EXPECT_THAT( + [] { Boolean(std::string("10")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Boolean from "10" (expected "True" or "False"))"))); + EXPECT_THAT( + [] { Boolean(std::string("i")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Boolean from "i" (expected "True" or "False"))"))); } TEST(BooleanTests, boolConstructorTest) { diff --git a/tests/src/literals/VariableTests.cpp b/tests/src/literals/VariableTests.cpp index 223af20a2..2730305b4 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,91 @@ 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(R"(Unable to parse Variable name from "" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "10" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("a1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "a1" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("abc"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "abc" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("1e"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "1e" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("A1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "A1" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("Bb"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "Bb" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("1C"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "1C" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("A"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "A" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("B"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "B" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("C"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "C" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "1" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "+" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("!"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "!" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("["); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "[" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("|"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "|" (expected single English lowercase letter))"))); - EXPECT_THROW(Variable("a", -1), InvalidInputException); - EXPECT_THROW(Variable("a", -2), InvalidInputException); - EXPECT_THROW(Variable("a", Integer("-100000000000000000000000000000000000000")), InvalidInputException); + EXPECT_THAT( + [] { Variable("ab", 1); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "ab" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("A", 1); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Variable name from "A" (expected single English lowercase letter))"))); + EXPECT_THAT( + [] { Variable("a", -1); }, + testing::ThrowsMessage( + testing::StrEq(R"(Negative Variable index -1 is not allowed)"))); + EXPECT_THAT( + [] { Variable("a", -2); }, + testing::ThrowsMessage( + testing::StrEq(R"(Negative Variable index -2 is not allowed)"))); + EXPECT_THAT( + [] { Variable("a", Integer("-100000000000000000000000000000000000000")); }, + testing::ThrowsMessage( + testing::StrEq(R"(Negative Variable index -100000000000000000000000000000000000000 is not allowed)"))); } TEST(VariableTest, getClassTest) { diff --git a/tests/src/numbers/ComplexTests.cpp b/tests/src/numbers/ComplexTests.cpp index 412148a51..f87390887 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(""); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "")"))); + EXPECT_THAT( + [] { Complex("--10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "--10")"))); + EXPECT_THAT( + [] { Complex("test"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "test")"))); + EXPECT_THAT( + [] { Complex("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "+")"))); + EXPECT_THAT( + [] { Complex("939849.0-0023"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "939849.0-0023")"))); + EXPECT_THAT( + [] { Complex("a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "a")"))); + EXPECT_THAT( + [] { Complex("a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "a.1")"))); + EXPECT_THAT( + [] { Complex("1.a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "1.a")"))); + EXPECT_THAT( + [] { Complex("1a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "1a.1")"))); + EXPECT_THAT( + [] { Complex("1.1a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "1.1a")"))); + EXPECT_THAT( + [] { Complex(".1."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from ".1.")"))); + EXPECT_THAT( + [] { Complex("."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from ".")"))); + EXPECT_THAT( + [] { Complex("--10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "--10.-1")"))); + EXPECT_THAT( + [] { Complex("10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "10.-1")"))); + EXPECT_THAT( + [] { Complex("1-0.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "1-0.1")"))); + EXPECT_THAT( + [] { Complex("10-.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "10-.1")"))); + EXPECT_THAT( + [] { Complex("10.--1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "10.--1")"))); + EXPECT_THAT( + [] { Complex("1.10.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "1.10.1")"))); + EXPECT_THAT( + [] { Complex("0II"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Complex from "0II")"))); } 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("Nested Complex numbers are not allowed"))); + EXPECT_THAT( + [] { Complex(Complex(), Integer()); }, + testing::ThrowsMessage( + testing::StrEq("Nested Complex numbers are not allowed"))); + EXPECT_THAT( + [] { Complex(Integer(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq("Nested Complex numbers are not allowed"))); + EXPECT_THAT( + [] { Complex(Complex(), Rational()); }, + testing::ThrowsMessage( + testing::StrEq("Nested Complex numbers are not allowed"))); + EXPECT_THAT( + [] { Complex(Rational(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq("Nested Complex numbers are not allowed"))); + EXPECT_THAT( + [] { Complex(Complex(), Real()); }, + testing::ThrowsMessage( + testing::StrEq("Nested Complex numbers are not allowed"))); + EXPECT_THAT( + [] { Complex(Real(), Complex()); }, + testing::ThrowsMessage( + testing::StrEq("Nested Complex numbers are not allowed"))); } 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(R"(div(0, 0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { Complex(2, 3) /= Complex(0, 0); }, + testing::ThrowsMessage( + testing::StrEq(R"(div(2 + 3 I, 0) is undefined (division by zero))"))); } TEST(ComplexTests, integerDivideAssignmentOperatorTest) { diff --git a/tests/src/numbers/IntegerFunctionsTests.cpp b/tests/src/numbers/IntegerFunctionsTests.cpp index 8767d4a0e..f7321a1c4 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(R"(sqrt(-9289) is undefined (expected argument >= 0))"))); } 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(R"(sqrt(-9289) is undefined (expected argument >= 0))"))); } 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(R"(pow({}, {}) is undefined (zero to the power of zero))"))); + EXPECT_THAT( + [] { pow(Rational(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(pow({}, {}) is undefined (zero to the power of zero))"))); + EXPECT_THAT( + [] { pow(Real(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(pow({}, {}) is undefined (zero to the power of zero))"))); + EXPECT_THAT( + [] { pow(Complex(0), Integer(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(pow({}, {}) is undefined (zero to the power of zero))"))); } 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(R"(factorial(-1) is undefined (expected argument >= 0))"))); + EXPECT_THAT( + [] { factorial(Integer(-2)); }, + testing::ThrowsMessage( + testing::StrEq(R"(factorial(-2) is undefined (expected argument >= 0))"))); } 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(R"(factorial(-1, 1) is undefined (expected first argument >= 0))"))); + EXPECT_THAT( + [] { factorial(Integer(-1), 20); }, + testing::ThrowsMessage( + testing::StrEq(R"(factorial(-1, 20) is undefined (expected first argument >= 0))"))); + EXPECT_THAT( + [] { factorial(Integer(-2), 1); }, + testing::ThrowsMessage( + testing::StrEq(R"(factorial(-2, 1) is undefined (expected first argument >= 0))"))); + EXPECT_THAT( + [] { factorial(Integer(-2), 20); }, + testing::ThrowsMessage( + testing::StrEq(R"(factorial(-2, 20) is undefined (expected first argument >= 0))"))); } 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(R"(factors(-1) is undefined (expected argument >= 2))"))); + EXPECT_THAT( + [] { factors(0); }, + testing::ThrowsMessage( + testing::StrEq(R"(factors(0) is undefined (expected argument >= 2))"))); + EXPECT_THAT( + [] { factors(1); }, + testing::ThrowsMessage( + testing::StrEq(R"(factors(1) is undefined (expected argument >= 2))"))); } TEST(IntegerFunctionsTests, combinationsTest) { @@ -279,20 +325,24 @@ 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(R"(combinations(20, 40) is undefined (expected totalNumber > choosedNumber))"))); + + EXPECT_THAT( + [] { combinations(Integer(-3), Integer(-8)); }, + testing::ThrowsMessage( + testing::StrEq(R"(combinations(-3, -8) is undefined (expected totalNumber >= 0 and choosedNumber >= 0))"))); + EXPECT_THAT( + [] { combinations(Integer(5), Integer(-3)); }, + testing::ThrowsMessage( + testing::StrEq(R"(combinations(5, -3) is undefined (expected totalNumber >= 0 and choosedNumber >= 0))"))); } TEST(IntegerFunctionsTests, multinomialCoefficientTest) { - EXPECT_EQ(multinomialCoefficient(Integer(6), {Integer(2), Integer(3), Integer(1)}), 60); - EXPECT_EQ(multinomialCoefficient(Integer(8), {Integer(8)}), 1); - 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_EQ(multinomialCoefficient({Integer(2), Integer(3), Integer(1)}), 60); + EXPECT_EQ(multinomialCoefficient({Integer(8)}), 1); + EXPECT_EQ(multinomialCoefficient({Integer(3), Integer(2)}), 10); + EXPECT_EQ(multinomialCoefficient({Integer(3), Integer(9), Integer(0)}), 220); } diff --git a/tests/src/numbers/IntegerTests.cpp b/tests/src/numbers/IntegerTests.cpp index 5fedad20f..0ee965239 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"(Unable to parse Integer from "")"))); + EXPECT_THAT( + [] { Integer("--10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Integer from "--10")"))); + EXPECT_THAT( + [] { Integer("test"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Integer from "test")"))); + EXPECT_THAT( + [] { Integer("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Integer from "+")"))); } TEST(IntegerTests, templateConstructorTest) { @@ -190,7 +203,10 @@ TEST(IntegerTests, divideAssignmentOperatorTest) { Integer("3507630615696849555869044818661735064986392883263011691538871248141434862220387449579227548346015035603501276296494442204769872208628882685816583149015034150490829747567986311156822048603845157334656209386816063095043939468216080230001796494390400252142375053346581510773088042280290835395905258970276127578670424725237113115641881479792031434427596080908227551489188776476145554883257759405245297150541759841671819727944845899493678892840111830112509529920517471699237861267263602427655073892668208557712684031475765670957010740054698088570050264362373595571625821629034477445434265168041405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361"), Integer("3507630615696849555869044818661735064986392883263011691538871248141434862220387449579227548346015035603501276296494442204769872208628882685816583149015034150490829747567986311156822048603845157334656209386816063095043939468216080230001796494390400252142375053346581510773088042280290835395905258970276127578670424725237113115641881479792031434427596080908227551489188776476145554883257759405245297150541759841671819727944845899493678892840111830112509529920517471699237861267263602427655073892668208557712684031475765670957010740054698088570050264362373595571625821629034477445434265168041405756975664327860057312868835959178663661834688407715795207372052181069795781487373087361")); - EXPECT_THROW(Integer(-25) /= Integer(0), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Integer(-25) /= Integer(0); }, + testing::ThrowsMessage( + testing::StrEq(R"(div(-25, 0) is undefined (division by zero))"))); } TEST(IntegerTests, intDivideAssignmentOperatorTest) { @@ -252,7 +268,10 @@ TEST(IntegerTests, moduloAssignmentOperatorTest) { EXPECT_EQ(Integer("5473289765787324752874728729473876573874654738747632794676328746738849389483948938493848394839849383893847267328724673874") %= Integer("1738383928837528673287446238746237943"), Integer("1186817955126284001426922341829394317")); - EXPECT_THROW(Integer(-25) %= Integer(0), UndefinedBinaryOperatorException); + EXPECT_THAT( + [] { Integer(-25) %= Integer(0); }, + testing::ThrowsMessage( + testing::StrEq(R"(mod(-25, 0) is undefined (modulo by zero))"))); } TEST(IntegerTests, intModuloAssignmentOperatorTest) { @@ -362,8 +381,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"(bitLeftShift(192, -5) is undefined (negative shift))"))); + EXPECT_THAT( + [] { Integer(-192) <<= Integer(-5); }, + testing::ThrowsMessage( + testing::StrEq(R"(bitLeftShift(-192, -5) is undefined (negative shift))"))); } TEST(IntegerTests, intBitLeftShiftAssignmentOperatorTest) { @@ -389,8 +414,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"(bitRightShift(192, -5) is undefined (negative shift))"))); + EXPECT_THAT( + [] { Integer(-192) >>= Integer(-5); }, + testing::ThrowsMessage( + testing::StrEq(R"(bitRightShift(-192, -5) is undefined (negative shift))"))); } TEST(IntegerTests, intBitRightShiftAssignmentOperatorTest) { diff --git a/tests/src/numbers/NumberAbstractTests.cpp b/tests/src/numbers/NumberAbstractTests.cpp index c3fa499e0..0a7ac1760 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"(div(0, 0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { Integer(0) / cast(Real(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(div(0.0, 0.0) is undefined (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"(div(0, 0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { Rational(0) / cast(Real(0)); }, + testing::ThrowsMessage( + testing::StrEq(R"(div(0.0, 0.0) is undefined (division by zero))"))); } //-------------------------------------------------------------------------------------// diff --git a/tests/src/numbers/RationalTests.cpp b/tests/src/numbers/RationalTests.cpp index 02ce09cb7..5df353a0f 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"(Unable to parse Rational from "")"))); + EXPECT_THAT( + [] { Rational("--10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "--10")"))); + EXPECT_THAT( + [] { Rational("test"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "test")"))); + EXPECT_THAT( + [] { Rational("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "+")"))); + EXPECT_THAT( + [] { Rational("939849.0-0023"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "939849.0-0023")"))); + EXPECT_THAT( + [] { Rational("a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "a")"))); + EXPECT_THAT( + [] { Rational("."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from ".")"))); + EXPECT_THAT( + [] { Rational("a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "a.1")"))); + EXPECT_THAT( + [] { Rational("1.a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "1.a")"))); + EXPECT_THAT( + [] { Rational("1a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "1a.1")"))); + EXPECT_THAT( + [] { Rational("1.1a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "1.1a")"))); + EXPECT_THAT( + [] { Rational(".1."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from ".1.")"))); + EXPECT_THAT( + [] { Rational("--10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "--10.-1")"))); + EXPECT_THAT( + [] { Rational("10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "10.-1")"))); + EXPECT_THAT( + [] { Rational("1-0.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "1-0.1")"))); + EXPECT_THAT( + [] { Rational("10-.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "10-.1")"))); + EXPECT_THAT( + [] { Rational("10.--1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "10.--1")"))); + EXPECT_THAT( + [] { Rational("1.10.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Rational from "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"(div(23070, 0) is undefined (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"(div(369/5, 0) is undefined (division by zero))"))); } TEST(RationalTests, integerDivideAssignmentOperatorTest) { diff --git a/tests/src/numbers/RealFunctionsTests.cpp b/tests/src/numbers/RealFunctionsTests.cpp index cdc4be8d0..02235825d 100644 --- a/tests/src/numbers/RealFunctionsTests.cpp +++ b/tests/src/numbers/RealFunctionsTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/core/Cache.hpp" @@ -55,6 +56,8 @@ TEST(RealFunctionsTests, floorTest) { "-1"); EXPECT_EQ(floor(Real("-0.3")).toString(), "-1"); + EXPECT_EQ(floor(Real("-0")).toString(), + "-1"); EXPECT_EQ(floor(Real("0")).toString(), "0"); EXPECT_EQ(floor(Real("0.3")).toString(), @@ -93,10 +96,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("floor(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { floor(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("floor(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); EXPECT_EQ(floor(1 / getTop()).toString(), "0"); EXPECT_EQ(floor(-1 / getTop()).toString(), @@ -132,6 +139,8 @@ TEST(RealFunctionsTests, ceilTest) { "0"); EXPECT_EQ(ceil(Real("-0.3")).toString(), "0"); + EXPECT_EQ(ceil(Real("-0")).toString(), + "0"); EXPECT_EQ(ceil(Real("0")).toString(), "0"); EXPECT_EQ(ceil(Real("0.3")).toString(), @@ -170,10 +179,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("ceil(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { ceil(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("ceil(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); EXPECT_EQ(ceil(1 / getTop()).toString(), "1"); EXPECT_EQ(ceil(-1 / getTop()).toString(), @@ -193,6 +206,8 @@ TEST(RealFunctionsTests, absTest) { EXPECT_EQ(abs(Real("0")).toString(), "0.0"); + EXPECT_EQ(abs(Real("-0")).toString(), + "0.0"); EXPECT_EQ(abs(Real("1")).toString(), "1.0"); EXPECT_EQ(abs(Real("-1")).toString(), @@ -263,46 +278,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("sqrt(-0.0) is undefined (expected argument >= 0)"))); + EXPECT_THAT( + [] { sqrt(Real(-1)); }, + testing::ThrowsMessage( + testing::StrEq("sqrt(-1.0) is undefined (expected argument >= 0)"))); + EXPECT_THAT( + [] { sqrt(Real(-10)); }, + testing::ThrowsMessage( + testing::StrEq("sqrt(-10.0) is undefined (expected argument >= 0)"))); EXPECT_EQ(sqrt(getBottom()).toString(), "7787033741169900729251715815485773693572833921585377451230548885066769607873479007659071982456633322947892066185977166857642583972097125178340595060116728563374256202600009698063524254105227036090331595060371028923930614245952174706617222746879926470.8510897821851530612877059206724864583284715928797081352754008253316368153779308877986149769954082553680155667453706957387521573664658902203158531980680861391512633677953799840216307772389412518628573193107066033055571314455053475570689817047532784603"); - EXPECT_THROW(sqrt(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("sqrt(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (expected argument >= 0)"))); 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("sqrt(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (expected argument >= 0)"))); 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("sqrt(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (expected argument >= 0)"))); + EXPECT_THAT( + [] { sqrt(-1 - 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("sqrt(-1.0) is undefined (expected argument >= 0)"))); EXPECT_EQ(sqrt(getTop()).toString(), "12838650304502567820342847439865633074310503792406078718470723550586214728557638663815746712937333587127496004640597516330302267248830820742443565086264610567153748278274474007832355643130116977702031439768479199109529814956630304548763269465384389756.52053975223085046502607341722170036312711000508017122016275623179708765814713563176019216943962531158532833134883846404994409109602478985370587448336374563571387052781900218402134345188878655222048458591611141484862841724667172384676656109304785616"); - EXPECT_THROW(sqrt(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { sqrt(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sqrt(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (expected argument >= 0)"))); 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("sqrt(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (expected argument >= 0)"))); 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("sqrt(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (expected argument >= 0)"))); + EXPECT_THAT( + [] { sqrt(-1 - 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sqrt(-1.0) is undefined (expected argument >= 0)"))); } TEST(RealFunctionsTests, powTest) { @@ -318,8 +355,22 @@ TEST(RealFunctionsTests, powTest) { "1.0"); EXPECT_EQ(pow(Real("-1"), Real("-1")).toString(), "-1.0"); + EXPECT_EQ(pow(Real("0"), Real("10")).toString(), + "0.0"); + EXPECT_EQ(pow(Real("-0"), Real("10")).toString(), + "0.0"); EXPECT_EQ(pow(Real("10"), Real("0")).toString(), "1.0"); + EXPECT_EQ(pow(Real("10"), Real("-0")).toString(), + "1.0"); + EXPECT_EQ(pow(Real("0"), Real("11")).toString(), + "0.0"); + EXPECT_EQ(pow(Real("-0"), Real("11")).toString(), + "-0.0"); + EXPECT_EQ(pow(Real("11"), Real("0")).toString(), + "1.0"); + EXPECT_EQ(pow(Real("11"), Real("-0")).toString(), + "1.0"); EXPECT_EQ(pow(Real("-10"), Real("3")).toString(), "-1000.0"); EXPECT_EQ(pow(Real("1"), Real("25")).toString(), @@ -360,25 +411,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("pow(0.0, 0.0) is undefined (zero to the power of zero)"))); + EXPECT_THAT( + [] { pow(Real("0"), Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("pow(0.0, -0.0) is undefined (zero to the power of zero)"))); + EXPECT_THAT( + [] { pow(Real("-0"), Real("0")); }, + testing::ThrowsMessage( + testing::StrEq("pow(-0.0, 0.0) is undefined (zero to the power of zero)"))); + EXPECT_THAT( + [] { pow(Real("-0"), Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("pow(-0.0, -0.0) is undefined (zero to the power of zero)"))); + EXPECT_THAT( + [] { pow(Real("0"), Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq("pow(0.0, -10.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { pow(Real("-10"), Real("1.5")); }, + testing::ThrowsMessage( + testing::StrEq("pow(-10.0, 1.5) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { pow(Real("-0"), Real("1.5")); }, + testing::ThrowsMessage( + testing::StrEq("pow(-0.0, 1.5) is undefined (pow(-1.0, 1.5) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { pow(Real("10"), Real("100000000000000000000")); }, + testing::ThrowsMessage( + testing::StrEq("pow(10.0, 100000000000000000000.0) is undefined (result overflow)"))); + + EXPECT_THAT( + [] { pow(2, getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("pow(2.0, 60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); EXPECT_EQ(pow(2, -getBottom()).toString(), "0.0"); EXPECT_EQ(pow(2, 1 / getBottom()).toString(), @@ -394,8 +463,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("pow(2.0, 1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); EXPECT_EQ(pow(2, -getTop()).toString(), "0.0"); EXPECT_EQ(pow(2, 1 / getTop()).toString(), @@ -417,6 +488,8 @@ TEST(RealFunctionsTests, expTest) { EXPECT_EQ(exp(Real("0")).toString(), "1.0"); + EXPECT_EQ(exp(Real("-0")).toString(), + "1.0"); EXPECT_EQ(exp(Real("1")).toString(), "2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931"); EXPECT_EQ(exp(Real("-1")).toString(), @@ -430,8 +503,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("exp(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); EXPECT_EQ(exp(-getBottom()).toString(), "0.0"); EXPECT_EQ(exp(1 / getBottom()).toString(), @@ -447,8 +522,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("exp(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); EXPECT_EQ(exp(-getTop()).toString(), "0.0"); EXPECT_EQ(exp(1 / getTop()).toString(), @@ -495,50 +572,92 @@ 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("log(0.0, 0.0) is undefined (ln(0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(Real("0"), Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("log(0.0, -0.0) is undefined (ln(0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(Real("-0"), Real("0")); }, + testing::ThrowsMessage( + testing::StrEq("log(-0.0, 0.0) is undefined (ln(-0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(Real("-0"), Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("log(-0.0, -0.0) is undefined (ln(-0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(Real("1"), Real("66")); }, + testing::ThrowsMessage( + testing::StrEq(R"(log(1.0, 66.0) is undefined (div(4.1896547420264255448744209363458315725446975461204218810739420522614615391015403955545337898127855677446872359746665499983090936202844377734407750132034614375855322466924278989591414054061908800439205842378476964717818785535562556221481423253679976493420852339317987961870493593040854711141491246445359358373722644761959819863963576390829124879365541233265787258798046029241557202934580563944417723930344537189078848697331335312087479189786893021895715688916117667659732380841091142872749455090483267, 0.0) is undefined (division by zero)))"))); + EXPECT_THAT( + [] { log(Real("-1"), Real("66")); }, + testing::ThrowsMessage( + testing::StrEq("log(-1.0, 66.0) is undefined (ln(-1.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(Real("10"), Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq("log(10.0, -10.0) is undefined (ln(-10.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(Real("-10"), Real("10")); }, + testing::ThrowsMessage( + testing::StrEq("log(-10.0, 10.0) is undefined (ln(-10.0) is undefined (expected argument > 0))"))); EXPECT_EQ(log(getBottom(), 2).toString(), "0.00060232170720148787335668247421703824233401793451907250732522916773385188954022906541837983996988431059094169862536414811557500495692329813203780906742857930168615297869764675322448206577626017712119000549151745205989997178535528834383829035005402069701450414530378257833776070969021526094444364816945235600935174058268565904524492686376745284448718663559682349198279109942125716899713858375086069625495195599080433207462875895090264590143184205942381892712807641877394970943778378340993960349468596485"); - EXPECT_THROW(log(-getBottom(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-getBottom(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0, 2.0) is undefined (ln(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (expected argument > 0))"))); 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("log(-4.6323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181017842413*10^-8, 2.0) is undefined (ln(-4.6323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181017842413*10^-8) is undefined (expected argument > 0))"))); 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("log(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898, 2.0) is undefined (ln(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(-1 - 1 / getLogBottom(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181, 2.0) is undefined (ln(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181) is undefined (expected argument > 0))"))); EXPECT_EQ(log(getTop(), 2).toString(), "0.00060179876403741195722267317028855276394958413863600696746297947633334990788320974726870323010323169588434938957603948500307384601018276229818373404501474310740195421987299739513709619111109837324557071587494251284044564219729803312816295558386812381034330050678075348580043519249230961108398858937009744461829681015882625617053962800932198087109777009790513513968156196421213763732007888196867038077809114726287574264983420066015703482789580169600344172129477299815596840195855948016245613690226508255"); - EXPECT_THROW(log(-getTop(), 2), - UndefinedFunctionException); + EXPECT_THAT( + [] { log(-getTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500, 2.0) is undefined (ln(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (expected argument > 0))"))); 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("log(-4.5822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027048317145*10^-8, 2.0) is undefined (ln(-4.5822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027048317145*10^-8) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(1 + 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027, 2.0) is undefined (ln(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (underflow))"))); + EXPECT_THAT( + [] { log(1 - 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295, 2.0) is undefined (ln(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (underflow))"))); + EXPECT_THAT( + [] { log(-1 + 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295, 2.0) is undefined (ln(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { log(-1 - 1 / getLogTop(), 2); }, + testing::ThrowsMessage( + testing::StrEq("log(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027, 2.0) is undefined (ln(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (expected argument > 0))"))); } TEST(RealFunctionsTests, lnTest) { @@ -549,49 +668,79 @@ 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("ln(0.0) is undefined (expected argument > 0)"))); + EXPECT_THAT( + [] { ln(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("ln(-0.0) is undefined (expected argument > 0)"))); + EXPECT_THAT( + [] { ln(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("ln(-1.0) is undefined (expected argument > 0)"))); EXPECT_EQ(ln(getBottom()).toString(), "1150.7922963302310752589242362151479313201731416891692833911699400851637036457415027739371939670841652308917357020983836730332705230349503481680214714976474839209077565316325602764151150216708300128886161589992601482604232651461734619835153032025914096909878125883457082637067939111344489500238615160009909178260268499686021249686533307312007952386375303998821252181168668959796267869490105263893896521620725067223980718367681264027500730584855433248242010154290038201336903273791780223593743126300917"); - EXPECT_THROW(ln(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("ln(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (expected argument > 0)"))); EXPECT_EQ(ln(1 / getBottom()).toString(), "-1150.7922963302310752589242362151479313201731416891692833911699400851637036457415027739371939670841652308917357020983836730332705230349503481680214714976474839209077565316325602764151150216708300128886161589992601482604232651461734619835153032025914096909878125883457082637067939111344489500238615160009909178260268499686021249686533307312007952386375303998821252181168668959796267869490105263893896521620725067223980718367681264027500730584855433248242010154290038201336903273791780223593743126300917"); - EXPECT_THROW(ln(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("ln(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (expected argument > 0)"))); 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("ln(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898) is undefined (expected argument > 0)"))); + EXPECT_THAT( + [] { ln(-1 - 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq("ln(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181) is undefined (expected argument > 0)"))); EXPECT_EQ(ln(getTop()).toString(), "1151.7922966635646085924004268024496095309282755109697640151737838982364673175055998951467299258996052465500220510896818993462124890472738694984769323698716068886745193057012811943430642366646091837561108162687936796823299767705815255181578427768061307290354919840683949388317852313255500361482131430137488582877970196536516803839211139492790968508269095773231100312182466822895779683752382008537434837173083611909767545379191434734806361489542919224380933936036537329432840742844554171617404889632642"); - EXPECT_THROW(ln(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { ln(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("ln(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (expected argument > 0)"))); 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("ln(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (expected argument > 0)"))); + EXPECT_THAT( + [] { ln(1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("ln(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (underflow)"))); + EXPECT_THAT( + [] { ln(1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("ln(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (underflow)"))); + EXPECT_THAT( + [] { ln(-1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("ln(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (expected argument > 0)"))); + EXPECT_THAT( + [] { ln(-1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("ln(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (expected argument > 0)"))); } TEST(RealFunctionsTests, lbTest) { Real::ScopedSetPrecision setPrecision(precision); + EXPECT_EQ(lb(Real("1")).toString(), + "0.0"); EXPECT_EQ(lb(Real("2")).toString(), "1.0"); EXPECT_EQ(lb(Real("3")).toString(), @@ -599,49 +748,79 @@ 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("lb(0.0) is undefined (ln(0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lb(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("lb(-0.0) is undefined (ln(-0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lb(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("lb(-1.0) is undefined (ln(-1.0) is undefined (expected argument > 0))"))); EXPECT_EQ(lb(getBottom()).toString(), "1660.2423390088468152391910752389223371556027033502350030047043970665552604033557193348632239845183566271017417710501538215097901794377254202764363841871643747071564808438403849686328703846578940097114426960217287346753381210056644885659785581770910105170063280253795447247762538890216319599066790175392754544932873241866224231658503043157397318916028330680138739335892411716116576564640798839083902475693032164084479471776090955137972737315592315237578699070714960186770111882960267580469773996621113"); - EXPECT_THROW(lb(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("lb(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (ln(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (expected argument > 0))"))); EXPECT_EQ(lb(1 / getBottom()).toString(), "-1660.2423390088468152391910752389223371556027033502350030047043970665552604033557193348632239845183566271017417710501538215097901794377254202764363841871643747071564808438403849686328703846578940097114426960217287346753381210056644885659785581770910105170063280253795447247762538890216319599066790175392754544932873241866224231658503043157397318916028330680138739335892411716116576564640798839083902475693032164084479471776090955137972737315592315237578699070714960186770111882960267580469773996621113"); - EXPECT_THROW(lb(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("lb(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (ln(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (expected argument > 0))"))); 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("lb(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898) is undefined (ln(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lb(-1 - 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq("lb(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181) is undefined (ln(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181) is undefined (expected argument > 0))"))); EXPECT_EQ(lb(getTop()).toString(), "1661.6850345306344141487530796177690746215158836948925002095220520038185509989931038272246710097629299710429990443367317181033697520479130844014839956432996829364738082384471341579821245656450941161111418270425586144696676643091196292534437222731085099151401430686452988712060138169216117489101036905404477911088920929597538663365923888861719817611791774685691023049143284296171501716483628778816866896852353629726107200682703242297950283551340834724294269534579127490555479536375902006763171420106197"); - EXPECT_THROW(lb(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lb(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("lb(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (ln(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (expected argument > 0))"))); 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("lb(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (ln(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lb(1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lb(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (ln(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (underflow))"))); + EXPECT_THAT( + [] { lb(1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lb(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (ln(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (underflow))"))); + EXPECT_THAT( + [] { lb(-1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lb(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (ln(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lb(-1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lb(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (ln(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (expected argument > 0))"))); } TEST(RealFunctionsTests, lgTest) { Real::ScopedSetPrecision setPrecision(precision); + EXPECT_EQ(lg(Real("1")).toString(), + "0.0"); EXPECT_EQ(lg(Real("0.001")).toString(), "-3.0"); EXPECT_EQ(lg(Real("1000")).toString(), @@ -649,44 +828,72 @@ 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("lg(0.0) is undefined (ln(0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lg(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("lg(-0.0) is undefined (ln(-0.0) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lg(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("lg(-1.0) is undefined (ln(-1.0) is undefined (expected argument > 0))"))); EXPECT_EQ(lg(getBottom()).toString(), "499.78274411299115434676719965223768779167964136920007055363841585463644188622791943555370510164980964264750094313258593253768816086436746615232975204548281091270192678941451207329501545599209700116287734424296607709230395802024565114215533908757411944516763884090982261616328224420567778290181253387292750617933539643330552558518205798043923795251523923586037612283521406459121448490318126006960906308176149951008770475545170983614291254760922234519816329245038107624609046278865956610110296462324552"); - EXPECT_THROW(lg(-getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("lg(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (ln(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (expected argument > 0))"))); EXPECT_EQ(lg(1 / getBottom()).toString(), "-499.78274411299115434676719965223768779167964136920007055363841585463644188622791943555370510164980964264750094313258593253768816086436746615232975204548281091270192678941451207329501545599209700116287734424296607709230395802024565114215533908757411944516763884090982261616328224420567778290181253387292750617933539643330552558518205798043923795251523923586037612283521406459121448490318126006960906308176149951008770475545170983614291254760922234519816329245038107624609046278865956610110296462324552"); - EXPECT_THROW(lg(-1 / getBottom()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("lg(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (ln(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (expected argument > 0))"))); 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("lg(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898) is undefined (ln(-0.99999995367639865479840398110793812148401792786416808675087521847079195754501735137153438530303420213008606478125694539754248543964739938863243401184322641416881832389488161259082176504477814477347735994040454672676815374960260039669456418666964797812431671188765447397393828271073928924619040130107318237541321727720948669818883213669079345236500740924269857689003558427839418012998482472527595143278671958043481931273609653225179286820218023963231571599688035330704134226391385365761201908801781898) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lg(-1 - 1 / getLogBottom()); }, + testing::ThrowsMessage( + testing::StrEq("lg(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181) is undefined (ln(-1.000000046323601345201596018892061878515982072135831913249124781529208042454982648628465614696965797869913935218743054602457514560352600611367565988156773585831181676105118387409178234955221855226522640059595453273231846250397399603305435813330352021875683288112345526026061717289260710753809598698926817624586782722790513301811167863309206547634992590757301423109964415721605819870015175274724048567213280419565180687263903467748207131797819760367684284003119646692958657736086146342387980911982181) is undefined (expected argument > 0))"))); EXPECT_EQ(lg(getTop()).toString(), "500.21703873965932033446069388899443301000188758874338645068247369777978188276137722252688424605970600893853927714983535582557236730510225838524295217100484539293318342301289243646059775923458762067839867333175852316509178327044942829214965210822082429417197201185525689704910240757839537066890081621757756380437386048194814809511491445030505791198598921869543591521133770911428148229663487063107650428872664624111572569774068160311266584524855638648630118535214458717640520183965265359385275880778024"); - EXPECT_THROW(lg(-getTop()), - UndefinedFunctionException); + EXPECT_THAT( + [] { lg(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("lg(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (ln(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (expected argument > 0))"))); 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("lg(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (ln(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lg(1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lg(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (ln(1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (underflow))"))); + EXPECT_THAT( + [] { lg(1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lg(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (ln(0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (underflow))"))); + EXPECT_THAT( + [] { lg(-1 + 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lg(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (ln(-0.99999995417735333037764629058459118410138623449964651173567067601808010557433866588314683926162236118773896026751150182017519164769255296210118447491146779862545790791243586890835094131313473377719792371963621878577249864612911470220649977786877910939552696561986417997367300599342620455346528419567305689879261643669514445633927722757374865158388342193693458508987514934561853269286404801156911891181027848084643878052506689530731389703910196291797296879492814663820944892281776128257193361787297295) is undefined (expected argument > 0))"))); + EXPECT_THAT( + [] { lg(-1 - 1 / getLogTop()); }, + testing::ThrowsMessage( + testing::StrEq("lg(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (ln(-1.000000045822646669622353709415408815898613765500353488264329323981919894425661334116853160738377638812261039732488498179824808352307447037898815525088532201374542092087564131091649058686865266222802076280363781214227501353870885297793500222131220890604473034380135820026326994006573795446534715804326943101207383563304855543660722772426251348416116578063065414910124850654381467307135951988430881088189721519153561219474933104692686102960898037082027031205071853361790551077182238717428066382127027) is undefined (expected argument > 0))"))); } TEST(RealFunctionsTests, sinTest) { @@ -694,6 +901,8 @@ TEST(RealFunctionsTests, sinTest) { EXPECT_EQ(sin(Real("0")).toString(), "0.0"); + EXPECT_EQ(sin(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(sin(Real("1")).toString(), "0.8414709848078965066525023216302989996225630607983710656727517099919104043912396689486397435430526958543490379079206742932591189209918988811934103277292124094807919558267666069999077640119784087827325663474848028702986561570179624553948935729246701270864862810533820305613772182038684496677616742662390133827533979567642555654779639897648243286902756964291206300583036515230312782552898532648513981934521359709559620621721148144417810576010756741366480550089167266058041400780623930703718779562612888"); EXPECT_EQ(sin(Real("-1")).toString(), @@ -701,14 +910,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("sin(6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow)"))); + EXPECT_THAT( + [] { sin(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq("sin(-6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow)"))); + EXPECT_THAT( + [] { sin(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq("sin(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow)"))); + EXPECT_THAT( + [] { sin(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq("sin(-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow)"))); EXPECT_EQ(sin(Real(getPi() / 2)).toString(), "1.0"); EXPECT_EQ(sin(Real(-getPi() / 2)).toString(), @@ -735,14 +952,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("sin(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { sin(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sin(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { sin(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sin(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { sin(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sin(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); EXPECT_EQ(sin(1 + 1 / getTop()).toString(), "0.84147098480789650665250232163029899962256306079837106567275170999191040439123966894863974354305269585434903790792067429325911892099189888119341032772921240948079195582676660699990776401197840878273256634748480287029865615701796245539489357292467012708648628105338203056137721820386844966776167426623901338275339795676425556547796398976482432869027569642912063005830365152303127825528985326485139819345213597095596206217211481444178105760107567413664805500891672660580414007806239307037187795626128881"); EXPECT_EQ(sin(1 - 1 / getTop()).toString(), @@ -758,6 +983,8 @@ TEST(RealFunctionsTests, cosTest) { EXPECT_EQ(cos(Real("0")).toString(), "1.0"); + EXPECT_EQ(cos(Real("-0")).toString(), + "1.0"); EXPECT_EQ(cos(Real("1")).toString(), "0.54030230586813971740093660744297660373231042061792222767009725538110039477447176451795185608718308934357173116003008909786063376002166345640651226541731858471797116447447949423311792455139325433594351775670289259637573615432754964175449177511513122273010063135707823223677140151746899593667873067422762024507763744067587498161784272021645585111563296889057108124272933169868524714568949043423754330944230240935962395831824547281736640780712434336217481003220271297578822917644683598726994264913443918"); EXPECT_EQ(cos(Real("-1")).toString(), @@ -773,10 +1000,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("cos(1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result underflow)"))); + EXPECT_THAT( + [] { cos(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq("cos(-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result underflow)"))); EXPECT_EQ(cos(Real(getPi() / 4)).toString(), "0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802792536860632206074854996791570661133296375279637789997525057639103028573505477998580298513726729843100736425870932044459930477616461524215435716072541988130181399762570399484362669827316590441482031030762917619752737287514387998086491778761016876592850567718730170424942358019344998534950240751527201389515822712391153424646845931079028923155579833435650650780928449361862"); EXPECT_EQ(cos(Real(-getPi() / 4)).toString(), @@ -799,10 +1030,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("cos(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { cos(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("cos(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); EXPECT_EQ(cos(1 / getTop()).toString(), "1.0"); EXPECT_EQ(cos(-1 / getTop()).toString(), @@ -822,6 +1057,8 @@ TEST(RealFunctionsTests, tanTest) { EXPECT_EQ(tan(Real("0")).toString(), "0.0"); + EXPECT_EQ(tan(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(tan(Real("1")).toString(), "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); EXPECT_EQ(tan(Real("-1")).toString(), @@ -831,18 +1068,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("tan(6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow)"))); + EXPECT_THAT( + [] { tan(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq("tan(-6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow)"))); + EXPECT_THAT( + [] { tan(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq("tan(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow)"))); + EXPECT_THAT( + [] { tan(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq("tan(-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow)"))); + EXPECT_THAT( + [] { tan(Real(getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq("tan(1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result overflow)"))); + EXPECT_THAT( + [] { tan(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq("tan(-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result overflow)"))); EXPECT_EQ(tan(Real(getPi() / 4)).toString(), "1.0"); EXPECT_EQ(tan(Real(-getPi() / 4)).toString(), @@ -865,14 +1114,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("tan(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { tan(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("tan(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow)"))); + EXPECT_THAT( + [] { tan(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("tan(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { tan(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("tan(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); EXPECT_EQ(tan(1 + 1 / getTop()).toString(), "1.5574077246549022305069748074583601730872507723815200383839466056988613971517272895550999652022429838046338214117481666133235546181245589376060716845489044392935860431671479080368246132747069555973416406107755352473025067968505070413523851449176214816275700278860224507720140161857721306739416643223690166756717950962610882330224852131148350591629692587616111732650100459456348215643353850532597808631549824289061892210758848878924221385209053656104434472362861925446578778273514850773908880700372159"); EXPECT_EQ(tan(1 - 1 / getTop()).toString(), @@ -895,21 +1152,39 @@ 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("cot(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { cot(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("cot(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + + EXPECT_THAT( + [] { cot(Real(2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq("cot(6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (tan(6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow))"))); + EXPECT_THAT( + [] { cot(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq("cot(-6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (tan(-6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow))"))); + EXPECT_THAT( + [] { cot(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq("cot(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (tan(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow))"))); + EXPECT_THAT( + [] { cot(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq("cot(-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (tan(-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow))"))); + EXPECT_THAT( + [] { cot(Real(getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq("cot(1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (tan(1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result overflow))"))); + EXPECT_THAT( + [] { cot(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq("cot(-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (tan(-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result overflow))"))); EXPECT_EQ(cot(Real(getPi() / 4)).toString(), "1.0"); EXPECT_EQ(cot(Real(-getPi() / 4)).toString(), @@ -932,14 +1207,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("cot(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (tan(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow))"))); + EXPECT_THAT( + [] { cot(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("cot(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (tan(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow))"))); + EXPECT_THAT( + [] { cot(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("cot(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (tan(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { cot(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("cot(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (tan(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); EXPECT_EQ(cot(1 + 1 / getTop()).toString(), "0.64209261593433070300641998659426562023027811391817137910116228042627685683916467219848291976019680465814306596047141573918356963493705933122378784310056202796590177952583993144431226921022120997092394574813060354777658685526661570956826754318872654659780710610492629489626709295081160952483427016354137699541561458952860701107858227259376088670827067970590687137491185081969260425814554198558997437568690607879275252280812126851999661677146531833095334863246223721746553979982097961711441872912451218"); EXPECT_EQ(cot(1 - 1 / getTop()).toString(), @@ -955,6 +1238,8 @@ TEST(RealFunctionsTests, secTest) { EXPECT_EQ(sec(Real("0")).toString(), "1.0"); + EXPECT_EQ(sec(Real("-0")).toString(), + "1.0"); EXPECT_EQ(sec(Real("1")).toString(), "1.8508157176809256179117532413986501934703966550940092988351582778588154112615967059218414132873066711491035115807339528416408998731176774131560787241383862147409231241515235786388237571054049733204438514990354855937330333279994572038442605499267955577813651494388974489708121098698689024822929458998871134135427663188500839953123828815800381513006621410411846961570477808388478499442707545318664792285082946656651090325360041775536641555012184458039002171415610374409790953100073117119984608557958766"); EXPECT_EQ(sec(Real("-1")).toString(), @@ -972,10 +1257,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("sec(1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (cos(1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result underflow))"))); + EXPECT_THAT( + [] { sec(Real(-getPi() / 2)); }, + testing::ThrowsMessage( + testing::StrEq("sec(-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (cos(-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746) is undefined (result underflow))"))); EXPECT_EQ(sec(Real(getPi() / 4)).toString(), "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372"); EXPECT_EQ(sec(Real(-getPi() / 4)).toString(), @@ -998,10 +1287,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("sec(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (cos(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow))"))); + EXPECT_THAT( + [] { sec(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sec(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (cos(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow))"))); EXPECT_EQ(sec(1 / getTop()).toString(), "1.0"); EXPECT_EQ(sec(-1 / getTop()).toString(), @@ -1030,17 +1323,31 @@ 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("csc(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { csc(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("csc(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + + EXPECT_THAT( + [] { csc(Real(2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq("csc(6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (sin(6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow))"))); + EXPECT_THAT( + [] { csc(Real(-2 * getPi())); }, + testing::ThrowsMessage( + testing::StrEq("csc(-6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (sin(-6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359642961730265646132941876892191011644634507188162569622349005682054038770422111192892458979098607639288576219513318668922569512964675735663305424038182912971338469206972209086532964267872145204982825474491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188661145407315191839061843722347638652235862102370961489247599254991347037715054497824558763660238983) is undefined (result underflow))"))); + EXPECT_THAT( + [] { csc(Real(getPi())); }, + testing::ThrowsMessage( + testing::StrEq("csc(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (sin(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow))"))); + EXPECT_THAT( + [] { csc(Real(-getPi())); }, + testing::ThrowsMessage( + testing::StrEq("csc(-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (sin(-3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491) is undefined (result underflow))"))); EXPECT_EQ(csc(Real(getPi() / 2)).toString(), "1.0"); EXPECT_EQ(csc(Real(-getPi() / 2)).toString(), @@ -1067,14 +1374,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("csc(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (sin(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow))"))); + EXPECT_THAT( + [] { csc(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("csc(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (sin(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument overflow))"))); + EXPECT_THAT( + [] { csc(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("csc(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (sin(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { csc(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("csc(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (sin(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); EXPECT_EQ(csc(1 + 1 / getTop()).toString(), "1.1883951057781212162615994523745510035278298340979626252652536663591843673571904879136635680308530232472479285607355300046767997261054621744411787730114762446028425233143142004017226704681329668496699454726395217600143376991057765233165669093621429979755229705180663841364565078822602575834843221309765112529134018803701291196253064696269055657610587513727537585232559260303432589997118789357728292536966170276437169716491704026280178391400624291988181131298891953546837005862558906922729413477101736"); EXPECT_EQ(csc(1 - 1 / getTop()).toString(), @@ -1090,6 +1405,8 @@ TEST(RealFunctionsTests, asinTest) { EXPECT_EQ(asin(Real("0")).toString(), "0.0"); + EXPECT_EQ(asin(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(asin(Real("1")).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(asin(Real("-1")).toString(), @@ -1099,44 +1416,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("asin(10.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { asin(Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq("asin(-10.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { asin(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("asin(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { asin(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("asin(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); 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("asin(1.0) is undefined (argument out of range)"))); 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("asin(-1.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { asin(getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asin(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { asin(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asin(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { asin(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asin(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { asin(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asin(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { asin(1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asin(1.0) is undefined (argument out of range)"))); 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("asin(-1.0) is undefined (argument out of range)"))); } TEST(RealFunctionsTests, acosTest) { @@ -1144,6 +1485,8 @@ TEST(RealFunctionsTests, acosTest) { EXPECT_EQ(acos(Real("0")).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); + EXPECT_EQ(acos(Real("-0")).toString(), + "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(acos(Real("1")).toString(), "0.0"); EXPECT_EQ(acos(Real("-1")).toString(), @@ -1151,44 +1494,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("acos(10.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acos(Real("-10")); }, + testing::ThrowsMessage( + testing::StrEq("acos(-10.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { acos(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("acos(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acos(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("acos(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); 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("acos(1.0) is undefined (argument out of range)"))); 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("acos(-1.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { acos(getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acos(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acos(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acos(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); 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("acos(1.0) is undefined (argument out of range)"))); 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("acos(-1.0) is undefined (argument out of range)"))); } TEST(RealFunctionsTests, atanTest) { @@ -1196,6 +1559,8 @@ TEST(RealFunctionsTests, atanTest) { EXPECT_EQ(atan(Real("0")).toString(), "0.0"); + EXPECT_EQ(atan(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(atan(Real("1")).toString(), "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298728"); EXPECT_EQ(atan(Real("-1")).toString(), @@ -1224,10 +1589,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("atan(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { atan(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("atan(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); EXPECT_EQ(atan(1 + 1 / getTop()).toString(), "0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115238764555793133985203212027936257102567548463027638991115573723873259549110720274391648336153211891205844669579131780047728641214173086508715261358166205334840181506228531843114675165157889704372038023024070731352292884109197314759000283263263720511663034603673798537790235826431759143989798827304652934548315294827627963701861559499068739183797143818122280698454575298729"); EXPECT_EQ(atan(1 - 1 / getTop()).toString(), @@ -1248,8 +1617,14 @@ 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("acot(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { acot(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("acot(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); EXPECT_EQ(acot(getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); @@ -1268,10 +1643,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("acot(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (atan(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { acot(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acot(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (atan(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); EXPECT_EQ(acot(1 / getTop()).toString(), "1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009545728242834617301743052271633241066968036301245706368622935033031577940874407604604814146270458576821839462951800056652652744102332606920734759707558047165286351828797959765460930586909663058965525592740372311899813747836759428763624456139690915059746"); EXPECT_EQ(acot(-1 / getTop()).toString(), @@ -1298,27 +1677,45 @@ 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("asec(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { asec(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("asec(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { asec(Real("0.54")); }, + testing::ThrowsMessage( + testing::StrEq("asec(0.54) is undefined (acos(1.8518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518519) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asec(Real("-0.54")); }, + testing::ThrowsMessage( + testing::StrEq("asec(-0.54) is undefined (acos(-1.8518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518519) is undefined (argument out of range))"))); 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("asec(1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (acos(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asec(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("asec(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (acos(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); 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("asec(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (acos(1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asec(-1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("asec(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (acos(-1.0) is undefined (argument out of range))"))); EXPECT_EQ(asec(-1 - 1 / getBottom()).toString(), "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019089640372359109626654798566502707211319370946985199183116327206111697941832567456673383308341695687723186584254926079042617489189536693145085156626317645923939786002762119455196396275564077376997598528804471407147463811172732950453025794670761851619242"); @@ -1326,16 +1723,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("asec(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (acos(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asec(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asec(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (acos(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); 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("asec(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (acos(1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asec(-1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("asec(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (acos(-1.0) is undefined (argument out of range))"))); EXPECT_EQ(asec(-1 - 1 / getTop()).toString(), "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019090354957448719769074801411670258845675317644354427277390187470669184627578520053124031899893789647494905415565915303073780628489595150764963580672492560980997155307017069219383588763138881564237000138811161903252708963375042846593538538373681532259612"); } @@ -1354,44 +1759,74 @@ 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("acsc(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { acsc(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { acsc(Real("0.54")); }, + testing::ThrowsMessage( + testing::StrEq("acsc(0.54) is undefined (asin(1.8518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518519) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acsc(Real("-0.54")); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-0.54) is undefined (asin(-1.8518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518518519) is undefined (argument out of range))"))); 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("acsc(1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (asin(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acsc(-1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (asin(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); 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("acsc(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (asin(1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acsc(-1 + 1 / getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (asin(-1.0) is undefined (argument out of range))"))); 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("acsc(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (asin(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { acsc(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (asin(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { acsc(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acsc(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (asin(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acsc(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (asin(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); 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("acsc(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (asin(1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acsc(-1 + 1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("acsc(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (asin(-1.0) is undefined (argument out of range))"))); EXPECT_EQ(acsc(-1 - 1 / getTop()).toString(), "-1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667230642378241168933915826356009544626714614102467331749140037017778707281343108720908767252437637606686704112448519217753623331070673065952614115246421127884387262543844228820964934513815710803478219109453922658176229218505271474546070789591352895215538283417829914082233990617199866"); } @@ -1401,6 +1836,8 @@ TEST(RealFunctionsTests, sinhTest) { EXPECT_EQ(sinh(Real("0")).toString(), "0.0"); + EXPECT_EQ(sinh(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(sinh(Real("1")).toString(), "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780262"); EXPECT_EQ(sinh(Real("-1")).toString(), @@ -1412,10 +1849,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("sinh(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { sinh(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("sinh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); EXPECT_EQ(sinh(1 / getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); EXPECT_EQ(sinh(-1 / getBottom()).toString(), @@ -1429,14 +1870,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("sinh(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); + EXPECT_THAT( + [] { sinh(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sinh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); + EXPECT_THAT( + [] { sinh(1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sinh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { sinh(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("sinh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); EXPECT_EQ(sinh(1 + 1 / getTop()).toString(), "1.1752011936438014568823818505956008151557179813340958702295654130133075673043238956071174520896233918404195333275795323567852189019194572821368403528832484238229689806253026878572974193778037894530156457975748559863812033933000211943571349392767479287838086397780915943822887094379183712322502306432683489821868659007368597138765536487737915436208491950598400985696957504601707347646045559914877642254885845736315892502135438245978143162874775249565935186798861968577094170390099113872716177152780263"); EXPECT_EQ(sinh(1 - 1 / getTop()).toString(), @@ -1452,6 +1901,8 @@ TEST(RealFunctionsTests, coshTest) { EXPECT_EQ(cosh(Real("0")).toString(), "1.0"); + EXPECT_EQ(cosh(Real("-0")).toString(), + "1.0"); EXPECT_EQ(cosh(Real("1")).toString(), "1.5430806348152437784779056207570616826015291123658637047374022147107690630492236989642647264355430355870468586044235275650321946947095862907634939423773472069151633480026408029059364105029494057980033657762593319443209506958499136898103743054847127392984561603903858174714536360045187363068275143488012027205749727055244716707064471032711422829394484116772731021396329586672730122826261409857215459162042522453939258584439199475134380734969475319971032521055637731102374474158960765443652715148207669"); EXPECT_EQ(cosh(Real("-1")).toString(), @@ -1463,10 +1914,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("cosh(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { cosh(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("cosh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); EXPECT_EQ(cosh(1 / getBottom()).toString(), "1.0"); EXPECT_EQ(cosh(-1 / getBottom()).toString(), @@ -1480,10 +1935,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("cosh(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); + EXPECT_THAT( + [] { cosh(-getTop()); }, + testing::ThrowsMessage( + testing::StrEq("cosh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); EXPECT_EQ(cosh(1 / getTop()).toString(), "1.0"); EXPECT_EQ(cosh(-1 / getTop()).toString(), @@ -1503,6 +1962,8 @@ TEST(RealFunctionsTests, tanhTest) { EXPECT_EQ(tanh(Real("0")).toString(), "0.0"); + EXPECT_EQ(tanh(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(tanh(Real("1")).toString(), "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); EXPECT_EQ(tanh(Real("-1")).toString(), @@ -1537,10 +1998,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("tanh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { tanh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("tanh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); EXPECT_EQ(tanh(1 + 1 / getTop()).toString(), "0.76159415595576488811945828260479359041276859725793655159681050012195324457663848345894752167367671442190275970155407753236830911476248541329700666961132112539651013760808777643934099260420667955311747580113059006625778319752451237997591796119707757354591410814335043351567518059703276048802963895774140411055528274345747412887011673202243366614182042652138531498400801780942494059716650201970771112780762115100557417027786836013212010823078830175221024750850545493659202265152413525903793814306804484"); EXPECT_EQ(tanh(1 - 1 / getTop()).toString(), @@ -1567,8 +2032,14 @@ 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("coth(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { coth(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("coth(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); EXPECT_EQ(coth(getBottom()).toString(), "1.0"); @@ -1591,10 +2062,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("coth(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (tanh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { coth(-1 / getTop()); }, + testing::ThrowsMessage( + testing::StrEq("coth(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (tanh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); EXPECT_EQ(coth(1 + 1 / getTop()).toString(), "1.3130352854993313036361612469308478329120139412404526555431529675670842704618743826746792414808563029467947050738448204197703961861267108989696017535496187432786603952677415430193164214901222207116902698721736279449551078863534426431459421512705491545530284902291249287850149672463612993918572556026640725698026338831716611079696232602874932353108307435238960892539297808523447222896268792900584895961848078828348145997881467167886864925710322604873807663078752942123708924231550111748471298599194883"); EXPECT_EQ(coth(1 - 1 / getTop()).toString(), @@ -1610,6 +2085,8 @@ TEST(RealFunctionsTests, sechTest) { EXPECT_EQ(sech(Real("0")).toString(), "1.0"); + EXPECT_EQ(sech(Real("-0")).toString(), + "1.0"); EXPECT_EQ(sech(Real("1")).toString(), "0.64805427366388539957497735322615032310848931207194202303786533731871759564671283028085478530789289238484741080920067693803371342199608047328527095053204320637710138926219751549816225165048045954767037456642342841785116074316762362109780982148957951547955724736187053107831495505487985321572485483727544183904287647250786507031934414748522969445640178730087299069355083406660792094751146726395612000124233338654264471442651311028781015766133420886738838930728215565261724863512460842165916753490629436"); EXPECT_EQ(sech(Real("-1")).toString(), @@ -1621,10 +2098,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("sech(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (cosh(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow))"))); + EXPECT_THAT( + [] { sech(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("sech(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (cosh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow))"))); EXPECT_EQ(sech(1 / getBottom()).toString(), "1.0"); EXPECT_EQ(sech(-1 / getBottom()).toString(), @@ -1638,10 +2119,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("sech(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (cosh(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow))"))); + EXPECT_THAT( + [] { sech(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("sech(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (cosh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow))"))); EXPECT_EQ(sech(1 / getTop()).toString(), "1.0"); EXPECT_EQ(sech(-1 / getTop()).toString(), @@ -1670,13 +2155,23 @@ 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("csch(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { csch(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("csch(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + + EXPECT_THAT( + [] { csch(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("csch(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (sinh(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow))"))); + EXPECT_THAT( + [] { csch(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("csch(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (sinh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow))"))); EXPECT_EQ(csch(1 / getBottom()).toString(), "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0"); EXPECT_EQ(csch(-1 / getBottom()).toString(), @@ -1690,14 +2185,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("csch(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (sinh(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow))"))); + EXPECT_THAT( + [] { csch(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("csch(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (sinh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow))"))); + EXPECT_THAT( + [] { csch(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("csch(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (sinh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { csch(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("csch(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (sinh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); EXPECT_EQ(csch(1 + 1 / getTop()).toString(), "0.85091812823932154513384276328717528418172466091033961699042115172900336432146510389973017732889381236244577208756327128688813072425711300301245714193374017994952769110096460382194385355935195067438882126357436553537332427446054349644213938204921347277018075690693498752022695416702001165378305540256814299412503544882032859324691046068505985960347029085439306176440022553590441722160679621286381402767940097301844636744314043849892045810662300858561471713244460798164774405712623774000961019889161074"); EXPECT_EQ(csch(1 - 1 / getTop()).toString(), @@ -1713,6 +2216,8 @@ TEST(RealFunctionsTests, asinhTest) { EXPECT_EQ(asinh(Real("0")).toString(), "0.0"); + EXPECT_EQ(asinh(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(asinh(Real("1")).toString(), "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); EXPECT_EQ(asinh(Real("-1")).toString(), @@ -1743,10 +2248,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("asinh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { asinh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asinh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); EXPECT_EQ(asinh(1 + 1 / getTop()).toString(), "0.88137358701954302523260932497979230902816032826163541075329560865337718422202608783370689191025604285673981619210649218876207251197659193752725546276579040922157868036289719624030735740962554897787156326236780650676303289540416355819005952730435167974467341511551586178006392610631334097262572894915748472288200076465594693049140628994381122451738158467277126319460884455255316858936825946495242451691598886050671829540158959591479483197050095772634225707401729190593428412086592318144508722640957213"); EXPECT_EQ(asinh(1 - 1 / getTop()).toString(), @@ -1771,48 +2280,84 @@ 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("acosh(0.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-0.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-1.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(Real("0.5")); }, + testing::ThrowsMessage( + testing::StrEq("acosh(0.5) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(Real("-0.5")); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-0.5) is undefined (argument out of range)"))); 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("acosh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(-1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (argument out of range)"))); 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("acosh(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(-1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(-1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-1.0) is undefined (argument out of range)"))); 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("acosh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (argument out of range)"))); 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("acosh(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(-1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { acosh(-1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acosh(-1.0) is undefined (argument out of range)"))); } TEST(RealFunctionsTests, atanhTest) { @@ -1820,6 +2365,8 @@ TEST(RealFunctionsTests, atanhTest) { EXPECT_EQ(atanh(Real("0")).toString(), "0.0"); + EXPECT_EQ(atanh(Real("-0")).toString(), + "-0.0"); EXPECT_EQ(atanh(Real("0.333")).toString(), "0.34619863713154247570599098685804826103609094329948378301404880413603328167394351962984431122461634023514290948031983237010653082502383710411969497037700185034288291947812555415915624018289058114167215829473448898016693296117239767068765288453353874546879688588509527472127797230451642236773965637268386840777259731872792797439722710677660848463210316000632738984571681501515219339944295988966181227125287741569589464016162821348393994703181239553059740942030273093670294694522971556318809608720244053"); EXPECT_EQ(atanh(Real("0.333")).toString(), @@ -1829,44 +2376,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("atanh(-1.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { atanh(Real("1")); }, + testing::ThrowsMessage( + testing::StrEq("atanh(1.0) is undefined (result overflow)"))); + + EXPECT_THAT( + [] { atanh(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { atanh(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range)"))); 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("atanh(1.0) is undefined (argument out of range)"))); 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("atanh(-1.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { atanh(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { atanh(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { atanh(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { atanh(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow)"))); + EXPECT_THAT( + [] { atanh(1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("atanh(1.0) is undefined (argument out of range)"))); 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("atanh(-1.0) is undefined (argument out of range)"))); } TEST(RealFunctionsTests, acothTest) { @@ -1883,44 +2454,74 @@ 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("acoth(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { acoth(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { acoth(Real("1")); }, + testing::ThrowsMessage( + testing::StrEq("acoth(1.0) is undefined (atanh(1.0) is undefined (result overflow))"))); + EXPECT_THAT( + [] { acoth(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-1.0) is undefined (atanh(-1.0) is undefined (result overflow))"))); 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("acoth(1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (atanh(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acoth(-1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (atanh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); 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("acoth(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (atanh(1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acoth(-1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (atanh(-1.0) is undefined (argument out of range))"))); 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("acoth(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (atanh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { acoth(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (atanh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { acoth(1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acoth(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (atanh(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acoth(-1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (atanh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); 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("acoth(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (atanh(1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { acoth(-1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acoth(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (atanh(-1.0) is undefined (argument out of range))"))); EXPECT_EQ(acoth(-1 - 1 / getTop()).toString(), "-576.24272192206227695090882946195389304950188782266500963464723195386493046973764730537629662644801196704601176605512629253994900464151600002775480156075334142530262343826482631476668563764425042861361708319207908881878454862287710354654495396616543243428068746726070101707907593698982713765301404752874464433664891079891116102771987933105953251130572826717469083114139641627339268542843798712169101720628451476605701420582103621498709158735847201064889329778435614385399369053905492485468661695725731"); } @@ -1937,44 +2538,76 @@ 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("asech(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { asech(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("asech(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { asech(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("asech(-1.0) is undefined (acosh(-1.0) is undefined (argument out of range))"))); + + EXPECT_THAT( + [] { asech(getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (acosh(1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asech(-getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (acosh(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (argument out of range))"))); 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("asech(-1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500) is undefined (acosh(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asech(1 + 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(1.0) is undefined (acosh(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (argument out of range))"))); 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("asech(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (acosh(-1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asech(-1 - 1 / getBottom()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(-1.0) is undefined (acosh(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998) is undefined (argument out of range))"))); + + EXPECT_THAT( + [] { asech(getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (acosh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asech(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (acosh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (argument out of range))"))); 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("asech(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (acosh(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asech(1 + 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(1.0) is undefined (acosh(0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (argument out of range))"))); 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("asech(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (acosh(-1.0) is undefined (argument out of range))"))); + EXPECT_THAT( + [] { asech(-1 - 1 / getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("asech(-1.0) is undefined (acosh(-0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999) is undefined (argument out of range))"))); } TEST(RealFunctionsTests, acschTest) { @@ -1993,8 +2626,14 @@ 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("acsch(0.0) is undefined (div(1.0, 0.0) is undefined (division by zero))"))); + EXPECT_THAT( + [] { acsch(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("acsch(-0.0) is undefined (div(1.0, -0.0) is undefined (division by zero))"))); EXPECT_EQ(acsch(getBottom()).toString(), "1.649133777606550136784218687424004095254941179759911333322637797136168830422634602314115700570892532765885213315763059469571051644237637081484422101463976767747598782769417969433884505005703538555118938103621519633425441890710503685760392630169558339325007093682810777671600073987912657467898712686051207323137042203911162690969426661891984432432828752922861693151232817522147506107429166604238235729862621545138953775084345915962310286003786258852115334834242333756164161942927832989128545815901011*10^-500"); @@ -2013,10 +2652,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("acsch(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (asinh(6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); + EXPECT_THAT( + [] { acsch(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("acsch(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (asinh(-6.0668221029528883281001366314451847775935571133154238337171617833892450389160443125661348729414343216076125585969768627866417572939707591975194837504732271906720565461629125208223721770347418712253634983033545337441357369348683484607312730428153166293652348836911624689467579262852324397776485195641635454176050858364773926346141137128601392334738037847620070433795854009788846254290816064680050028109867977104220909303033881251773870034221919630587132642554461027088303513413484297018404111713636352*10^-501) is undefined (result underflow))"))); EXPECT_EQ(acsch(1 / getTop()).toString(), "1152.4854438441245539018176589239077860990037756453300192692944639077298609394752946107525932528960239340920235321102525850798980092830320000555096031215066828506052468765296526295333712752885008572272341663841581776375690972457542070930899079323308648685613749345214020341581518739796542753060280950574892886732978215978223220554397586621190650226114565343493816622827928325467853708568759742433820344125690295321140284116420724299741831747169440212977865955687122877079873810781098497093732339145146"); EXPECT_EQ(acsch(-1 / getTop()).toString(), @@ -2066,26 +2709,48 @@ 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("tgamma(0.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { tgamma(Real("-0")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-0.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { tgamma(Real("-1")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-1.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { tgamma(Real("-2")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-2.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { tgamma(Real("-3")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-3.0) is undefined (argument out of range)"))); + EXPECT_THAT( + [] { tgamma(Real("-32352")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-32352.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { tgamma(Real("1000000000")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(1000000000.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { tgamma(Real("-1000000000")); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-1000000000.0) is undefined (argument out of range)"))); + + EXPECT_THAT( + [] { tgamma(getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); + EXPECT_THAT( + [] { tgamma(-getBottom()); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633533.0) is undefined (result overflow)"))); EXPECT_EQ(tgamma(1 / getBottom()).toString(), "60637894486118500503636099732462364956850790907849127113254769591568608656948985194787389448417544101315522875333719830559375058059221999457285045467709773208236451195138842541700657594134640809985287947796233555965864294685760448475889927065472080334188866294714585098656713287282618832026757995083776993799896864197894811997715757204066567900975498475027932179243797839056728035498370647887472466931408463051355352585045395714991459137805650231442038783923968764653054533405715475155191362599633532.0"); EXPECT_EQ(tgamma(-1 / getBottom()).toString(), @@ -2099,10 +2764,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("tgamma(1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); + EXPECT_THAT( + [] { tgamma(-getTop()).toString(); }, + testing::ThrowsMessage( + testing::StrEq("tgamma(-1.6483094164130387741510320575015722415830725719070958553581810817964045839732801283320767366433561500407417949917038975822310585763375699419424510422581997424963334554622569199584327881930851555021315633087886023249271483198945434608517539913558850905928096069667671775054328978413933023917511835527377381808000967094899992816840848691527375424965235810613599352178207607112172283212141431574982992000512238522963665692263518204556874384169868120188374052307633082011946880362142902601993503659461819*10^500) is undefined (result overflow)"))); 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 6c7ff7056..bd449f3ae 100644 --- a/tests/src/numbers/RealTests.cpp +++ b/tests/src/numbers/RealTests.cpp @@ -1,3 +1,4 @@ +#include #include #include "fintamath/numbers/Real.hpp" @@ -22,43 +23,117 @@ TEST(RealTests, stringConstructorTest) { EXPECT_EQ(Real(".1").toString(), "0.1"); EXPECT_EQ(Real("1.").toString(), "1.0"); EXPECT_EQ(Real("10000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000").toString(), "1.00000000002*10^94"); + EXPECT_EQ(Real("2*10^2").toString(), "200.0"); EXPECT_EQ(Real("-2*10^2").toString(), "-200.0"); EXPECT_EQ(Real("2*10^-2").toString(), "0.02"); EXPECT_EQ(Real("-2*10^-2").toString(), "-0.02"); + EXPECT_EQ(Real("2*10^0").toString(), "2.0"); + EXPECT_EQ(Real("-2*10^0").toString(), "-2.0"); + + EXPECT_EQ(Real("0*10^2").toString(), "0.0"); + EXPECT_EQ(Real("0*10^-2").toString(), "0.0"); + EXPECT_EQ(Real("0*10^0").toString(), "0.0"); + EXPECT_EQ(Real("123.456*10^1000").toString(), "1.23456*10^1002"); EXPECT_EQ(Real("-123.456*10^1000").toString(), "-1.23456*10^1002"); EXPECT_EQ(Real("123.456*10^-1000").toString(), "1.23456*10^-998"); EXPECT_EQ(Real("-123.456*10^-1000").toString(), "-1.23456*10^-998"); + EXPECT_EQ(Real("123.456*10^0").toString(), "123.456"); + EXPECT_EQ(Real("-123.456*10^0").toString(), "-123.456"); + EXPECT_EQ(Real("0.123456*10^1000").toString(), "1.23456*10^999"); EXPECT_EQ(Real("-0.123456*10^1000").toString(), "-1.23456*10^999"); 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_EQ(Real("0.123456*10^0").toString(), "0.123456"); + EXPECT_EQ(Real("-0.123456*10^0").toString(), "-0.123456"); + + EXPECT_THAT( + [] { Real(""); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "")"))); + EXPECT_THAT( + [] { Real("--10"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "--10")"))); + EXPECT_THAT( + [] { Real("test"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "test")"))); + EXPECT_THAT( + [] { Real("+"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "+")"))); + EXPECT_THAT( + [] { Real("939849.0-0023"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "939849.0-0023")"))); + EXPECT_THAT( + [] { Real("a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "a")"))); + EXPECT_THAT( + [] { Real("a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "a.1")"))); + EXPECT_THAT( + [] { Real("1.a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "1.a")"))); + EXPECT_THAT( + [] { Real("1a.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "1a.1")"))); + EXPECT_THAT( + [] { Real("1.1a"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "1.1a")"))); + EXPECT_THAT( + [] { Real("--10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "--10.-1")"))); + EXPECT_THAT( + [] { Real("10.-1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "10.-1")"))); + EXPECT_THAT( + [] { Real("1-0.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "1-0.1")"))); + EXPECT_THAT( + [] { Real("10-.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "10-.1")"))); + EXPECT_THAT( + [] { Real("10.--1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "10.--1")"))); + EXPECT_THAT( + [] { Real("."); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from ".")"))); + EXPECT_THAT( + [] { Real("1.2.1"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "1.2.1")"))); + EXPECT_THAT( + [] { Real("2*10^2.2"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "2*10^2.2")"))); + EXPECT_THAT( + [] { Real("2*10^-2.2"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Unable to parse Real from "2*10^-2.2")"))); + + EXPECT_THAT( + [] { Real("10*10^100000000000000000000"); }, + testing::ThrowsMessage( + testing::StrEq(R"(Undefined "10*10^100000000000000000000" (overflow))"))); } 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 +148,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) { @@ -1030,11 +1108,24 @@ TEST(RealTests, signTest) { TEST(RealTests, isZeroTest) { EXPECT_TRUE(Real("0").isZero()); EXPECT_TRUE(Real("-0").isZero()); - EXPECT_FALSE(Real("1").isZero()); EXPECT_FALSE(Real("-1").isZero()); } +TEST(RealTests, isPosZeroTest) { + EXPECT_TRUE(Real("0").isPosZero()); + EXPECT_FALSE(Real("-0").isPosZero()); + EXPECT_FALSE(Real("1").isPosZero()); + EXPECT_FALSE(Real("-1").isPosZero()); +} + +TEST(RealTests, isNegZeroTest) { + EXPECT_FALSE(Real("0").isNegZero()); + EXPECT_TRUE(Real("-0").isNegZero()); + EXPECT_FALSE(Real("1").isNegZero()); + EXPECT_FALSE(Real("-1").isNegZero()); +} + TEST(RealTests, isPreciseTest) { EXPECT_FALSE(Real(2).isPrecise()); } diff --git a/thirdparty/boost-config b/thirdparty/boost-config new file mode 160000 index 000000000..cbeca533d --- /dev/null +++ b/thirdparty/boost-config @@ -0,0 +1 @@ +Subproject commit cbeca533d2113efbcffa84326111ad15a6a1f57a diff --git a/thirdparty/boost-container-hash b/thirdparty/boost-container-hash new file mode 160000 index 000000000..48a306dcf --- /dev/null +++ b/thirdparty/boost-container-hash @@ -0,0 +1 @@ +Subproject commit 48a306dcf236ae460d9ba55648d449ed7bea1dee diff --git a/thirdparty/boost-describe b/thirdparty/boost-describe new file mode 160000 index 000000000..c89e4dd3d --- /dev/null +++ b/thirdparty/boost-describe @@ -0,0 +1 @@ +Subproject commit c89e4dd3db81eb4f2867b2bc965d161f51cc316c diff --git a/thirdparty/boost-mp11 b/thirdparty/boost-mp11 new file mode 160000 index 000000000..391e23ae7 --- /dev/null +++ b/thirdparty/boost-mp11 @@ -0,0 +1 @@ +Subproject commit 391e23ae716aec4d59f6c7272e49e1dd8c01dcdb