-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ enum class MathObjectType : MathObjectTypeId { | |
Derivative, | ||
Integral, | ||
Frac, | ||
PowF, | ||
|
||
IOperator = 12000, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "fintamath/core/IArithmetic.hpp" | ||
#include "fintamath/functions/IFunction.hpp" | ||
|
||
namespace fintamath { | ||
|
||
class PowF : public IFunctionCRTP<IArithmetic, PowF, IArithmetic, IArithmetic> { | ||
public: | ||
std::string toString() const override { | ||
return "pow"; | ||
} | ||
|
||
static MathObjectTypeId getTypeIdStatic() { | ||
return MathObjectTypeId(MathObjectType::PowF); | ||
} | ||
|
||
protected: | ||
std::unique_ptr<IMathObject> call(const ArgumentsRefVector &argsVect) const override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "fintamath/functions/powers/PowF.hpp" | ||
|
||
#include "fintamath/functions/powers/Pow.hpp" | ||
|
||
namespace fintamath { | ||
|
||
std::unique_ptr<IMathObject> PowF::call(const ArgumentsRefVector &argsVect) const { | ||
return Pow()(argsVect); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "fintamath/functions/powers/PowF.hpp" | ||
|
||
#include "fintamath/core/IArithmetic.hpp" | ||
#include "fintamath/exceptions/UndefinedException.hpp" | ||
#include "fintamath/functions/arithmetic/Sub.hpp" | ||
#include "fintamath/functions/arithmetic/UnaryPlus.hpp" | ||
#include "fintamath/literals/Variable.hpp" | ||
#include "fintamath/numbers/Rational.hpp" | ||
#include "fintamath/numbers/Real.hpp" | ||
|
||
using namespace fintamath; | ||
|
||
const PowF f; | ||
|
||
TEST(PowFTests, toStringTest) { | ||
EXPECT_EQ(f.toString(), "pow"); | ||
} | ||
|
||
TEST(PowFTests, getFunctionTypeTest) { | ||
EXPECT_EQ(f.getFunctionType(), IFunction::Type::Binary); | ||
} | ||
|
||
TEST(PowFTests, callTest) { | ||
EXPECT_EQ(f(Integer(3), Integer(2))->toString(), "9"); | ||
EXPECT_EQ(f(Integer(-3), Integer(2))->toString(), "9"); | ||
EXPECT_EQ(f(Integer(3), Integer(-2))->toString(), "1/9"); | ||
EXPECT_EQ(f(Rational(5, 2), Integer(2))->toString(), "25/4"); | ||
EXPECT_EQ(f(Integer(11), Integer(200))->toString(), | ||
"1899052764604618242121820463954116340585832240009877848127251456103762646167989140750662066593328455813588" | ||
"1805238401044949435868367905913020005911442340062387227375955664576836341689587626164144676307968892001"); | ||
|
||
EXPECT_EQ(f(Integer(4), Rational(1, 2))->toString(), "2"); | ||
EXPECT_EQ(f(Integer(4), Rational(1, 3))->toString(), "root(4, 3)"); | ||
EXPECT_EQ(f(Integer(4), Rational(1, 4))->toString(), "sqrt(2)"); | ||
EXPECT_EQ(f(Integer(8), Rational(1, 3))->toString(), "2"); | ||
EXPECT_EQ(f(Integer(16), Rational(1, 4))->toString(), "2"); | ||
EXPECT_EQ(f(Integer(7), Rational(1, 1000))->toString(), "root(7, 1000)"); | ||
EXPECT_EQ(f(Integer(4), Rational(5, 2))->toString(), "32"); | ||
EXPECT_EQ(f(Integer(4), Rational(5, 3))->toString(), "8 root(2, 3)"); | ||
EXPECT_EQ(f(Integer(4), Rational(5, 4))->toString(), "4 sqrt(2)"); | ||
EXPECT_EQ(f(Integer(8), Rational(5, 3))->toString(), "32"); | ||
EXPECT_EQ(f(Integer(16), Rational(5, 4))->toString(), "32"); | ||
EXPECT_EQ(f(Integer(7), Rational(3, 1000))->toString(), "root(343, 1000)"); | ||
EXPECT_EQ(f(Integer(1), Rational(1, 1234))->toString(), "1"); | ||
EXPECT_EQ(f(Integer(10000000000), Rational(1, 100))->toString(), "root(10, 10)"); | ||
EXPECT_EQ(f(Integer(-4), Rational(1))->toString(), "-4"); | ||
|
||
EXPECT_EQ(f(*f(Integer(10), Integer(100)), Rational(1, 100))->toString(), "10"); | ||
EXPECT_EQ(f(*f(Integer(10), Integer(300)), Rational(1, 100))->toString(), "1000"); | ||
|
||
EXPECT_EQ(f(Integer(4), Rational(-1, 2))->toString(), "1/2"); | ||
EXPECT_EQ(f(Integer(4), Rational(-1, 3))->toString(), "1/root(4, 3)"); | ||
EXPECT_EQ(f(Integer(4), Rational(-1, 4))->toString(), "1/sqrt(2)"); | ||
EXPECT_EQ(f(Integer(8), Rational(-1, 3))->toString(), "1/2"); | ||
EXPECT_EQ(f(Integer(16), Rational(-1, 4))->toString(), "1/2"); | ||
EXPECT_EQ(f(Integer(4), Rational(-5, 2))->toString(), "1/32"); | ||
EXPECT_EQ(f(Integer(4), Rational(-5, 3))->toString(), "1/(8 root(2, 3))"); | ||
EXPECT_EQ(f(Integer(4), Rational(-5, 4))->toString(), "1/(4 sqrt(2))"); | ||
EXPECT_EQ(f(Integer(8), Rational(-5, 3))->toString(), "1/32"); | ||
EXPECT_EQ(f(Integer(16), Rational(-5, 4))->toString(), "1/32"); | ||
EXPECT_EQ(f(Integer(7), Rational(-3, 1000))->toString(), "1/root(343, 1000)"); | ||
|
||
EXPECT_EQ(f(Rational(-10), Rational(-3))->toString(), "-1/1000"); | ||
EXPECT_EQ(f(Rational(-1), Rational(-25))->toString(), "-1"); | ||
EXPECT_EQ(f(Rational("-2.2"), Rational(-5))->toString(), "-3125/161051"); | ||
EXPECT_EQ(f(Rational("2.2"), Rational(-5, 2))->toString(), "(25 sqrt(5/11))/121"); | ||
|
||
EXPECT_EQ(f(Real("2.2"), Real("2"))->toString(), "4.84"); | ||
EXPECT_EQ(f(Real("2.2"), Real("0.5"))->toString(), | ||
"1.48323969741913258974227948816014261219598086381950031974652465286876603686277"); | ||
|
||
EXPECT_EQ(f(Integer(3), Variable("a"))->toString(), "3^a"); | ||
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(Integer(0), Integer(0)), UndefinedException); | ||
EXPECT_THROW(f(Rational("0"), Rational("-10")), UndefinedException); | ||
EXPECT_THROW(f(Rational("-10"), Rational("-1.5")), UndefinedException); | ||
|
||
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); | ||
} | ||
|
||
TEST(PowFTests, doArgsMatchTest) { | ||
Integer a; | ||
|
||
EXPECT_FALSE(f.doArgsMatch({})); | ||
EXPECT_FALSE(f.doArgsMatch({a})); | ||
EXPECT_TRUE(f.doArgsMatch({a, a})); | ||
EXPECT_FALSE(f.doArgsMatch({a, a, a})); | ||
} | ||
|
||
TEST(PowFTests, equalsTest) { | ||
EXPECT_EQ(f, f); | ||
EXPECT_EQ(f, PowF()); | ||
EXPECT_EQ(PowF(), f); | ||
EXPECT_EQ(f, cast<IMathObject>(PowF())); | ||
EXPECT_EQ(cast<IMathObject>(PowF()), f); | ||
EXPECT_NE(f, Sub()); | ||
EXPECT_NE(Sub(), f); | ||
EXPECT_NE(f, UnaryPlus()); | ||
EXPECT_NE(UnaryPlus(), f); | ||
} | ||
|
||
TEST(PowFTests, getTypeIdTest) { | ||
EXPECT_EQ(PowF::getTypeIdStatic(), MathObjectTypeId(MathObjectType::PowF)); | ||
EXPECT_EQ(PowF().getTypeId(), MathObjectTypeId(MathObjectType::PowF)); | ||
} |