-
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
116 additions
and
6 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 |
---|---|---|
|
@@ -112,6 +112,7 @@ class MathObjectType { | |
Derivative, | ||
Integral, | ||
Frac, | ||
FracMixed, | ||
PowFunction, | ||
Floor, | ||
Ceil, | ||
|
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 FracMixed : public IFunctionCRTP<IArithmetic, FracMixed, IArithmetic, IArithmetic, IArithmetic> { | ||
public: | ||
std::string toString() const override { | ||
return "frac"; | ||
} | ||
|
||
static MathObjectType getTypeStatic() { | ||
return MathObjectType::FracMixed; | ||
} | ||
|
||
protected: | ||
std::unique_ptr<IMathObject> call(const ArgumentRefVector &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,16 @@ | ||
#include "fintamath/functions/arithmetic/FracMixed.hpp" | ||
|
||
#include "fintamath/functions/arithmetic/Add.hpp" | ||
#include "fintamath/functions/arithmetic/Div.hpp" | ||
|
||
namespace fintamath { | ||
|
||
std::unique_ptr<IMathObject> FracMixed::call(const ArgumentRefVector &argsVect) const { | ||
const auto &integ = cast<IArithmetic>(argsVect[0].get()); | ||
const auto &numer = cast<IArithmetic>(argsVect[1].get()); | ||
const auto &denom = cast<IArithmetic>(argsVect[2].get()); | ||
|
||
return Add()(integ, *Div()(numer, denom)); | ||
} | ||
|
||
} |
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,63 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "fintamath/functions/arithmetic/Add.hpp" | ||
|
||
#include "fintamath/exceptions/InvalidInputException.hpp" | ||
#include "fintamath/functions/arithmetic/FracMixed.hpp" | ||
#include "fintamath/functions/arithmetic/Sub.hpp" | ||
#include "fintamath/functions/arithmetic/UnaryPlus.hpp" | ||
#include "fintamath/literals/Variable.hpp" | ||
#include "fintamath/numbers/Rational.hpp" | ||
|
||
using namespace fintamath; | ||
|
||
const FracMixed f; | ||
|
||
TEST(FracMixedTests, toStringTest) { | ||
EXPECT_EQ(f.toString(), "frac"); | ||
} | ||
|
||
TEST(FracMixedTests, getFunctionTypeTest) { | ||
EXPECT_EQ(f.getFunctionType(), IFunction::Type::Ternary); | ||
} | ||
|
||
TEST(FracMixedTests, callTest) { | ||
EXPECT_EQ(f(Integer(0), Integer(3), Integer(5))->toString(), "3/5"); | ||
EXPECT_EQ(f(Integer(0), Integer(3), Rational(5, 2))->toString(), "6/5"); | ||
EXPECT_EQ(f(Integer(0), Rational(5, 2), Integer(3))->toString(), "5/6"); | ||
EXPECT_EQ(f(Integer(0), Rational(5, 2), Rational(5, 3))->toString(), "3/2"); | ||
|
||
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); | ||
} | ||
|
||
TEST(FracMixedTests, doArgsMatchTest) { | ||
Integer a; | ||
|
||
EXPECT_FALSE(f.doArgsMatch({})); | ||
EXPECT_FALSE(f.doArgsMatch({a})); | ||
EXPECT_FALSE(f.doArgsMatch({a, a})); | ||
EXPECT_TRUE(f.doArgsMatch({a, a, a})); | ||
EXPECT_FALSE(f.doArgsMatch({a, a, a, a})); | ||
} | ||
|
||
TEST(FracMixedTests, equalsTest) { | ||
EXPECT_EQ(f, f); | ||
EXPECT_EQ(f, FracMixed()); | ||
EXPECT_EQ(FracMixed(), f); | ||
EXPECT_EQ(f, cast<IMathObject>(FracMixed())); | ||
EXPECT_EQ(cast<IMathObject>(FracMixed()), f); | ||
EXPECT_NE(f, Sub()); | ||
EXPECT_NE(Sub(), f); | ||
EXPECT_NE(f, UnaryPlus()); | ||
EXPECT_NE(UnaryPlus(), f); | ||
} | ||
|
||
TEST(FracMixedTests, getTypeTest) { | ||
EXPECT_EQ(FracMixed::getTypeStatic(), MathObjectType::FracMixed); | ||
EXPECT_EQ(FracMixed().getType(), MathObjectType::FracMixed); | ||
} |
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