Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BasisFunctionTests.cpp. Removed BasisFunction unit test and tru… #3200

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions isis/src/base/objs/BasisFunction/BasisFunction.truth

This file was deleted.

54 changes: 0 additions & 54 deletions isis/src/base/objs/BasisFunction/unitTest.cpp

This file was deleted.

142 changes: 142 additions & 0 deletions isis/tests/BasisFunctionTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include <gtest/gtest.h>
#include <QString>
#include "BasisFunction.h"
#include "IException.h"

TEST(BasisFunction, Initialization)
{
std::string name("basis1");
Isis::BasisFunction testBasis("basis1", 3, 3);

EXPECT_EQ(testBasis.Coefficients(), 3);
EXPECT_EQ(testBasis.Variables(), 3);
EXPECT_STREQ(testBasis.Name().toStdString().c_str(), name.c_str());
}

TEST(BasisFunction, Evaluation)
{
Isis::BasisFunction testBasis("basis", 3, 3);
double expectedOutput = 12.7;
double output;
std::vector <double> vars;
std::vector <double> coefs;

coefs.push_back(2.5);
coefs.push_back(3.2);
coefs.push_back(1.0);
testBasis.SetCoefficients(coefs);

vars.push_back(3.0);
vars.push_back(1.0);
vars.push_back(2.0);

output = testBasis.Evaluate(vars);
EXPECT_DOUBLE_EQ(output, expectedOutput);

vars[0] = 3.5;
vars[1] = 1.2;
vars[2] = 10.8;

expectedOutput = 23.39;
output = testBasis.Evaluate(vars);
EXPECT_DOUBLE_EQ(output, expectedOutput);
}

TEST(BasisFunction, InequalCoefficientAmount)
{
Isis:: BasisFunction testBasis("basis", 1, 1);
std::vector <double> coefs;

coefs.push_back(1.0);
coefs.push_back(1.0);

try
{
testBasis.SetCoefficients(coefs);
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Unable to set coefficients vector"))
<< e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message: "
"\"Unable to set coefficients vector. The size of the given vector "
"does not match number of coefficients "
"in the basis equation\"";
}

}

TEST(BasisFunction, InequalVariableAmount)
{
Isis:: BasisFunction testBasis("basis", 1, 1);
std::vector <double> coefs;
std::vector <double> vars;

coefs.push_back(1.0);
testBasis.SetCoefficients(coefs);

vars.push_back(1.0);
vars.push_back(1.0);

try
{
testBasis.Evaluate(vars);
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Unable to evaluate function"))
<< e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message: "
"\"Unable to set coefficients vector. The size of the given vector"
" does not match number of coefficients in the basis equation\"";
}
}

TEST(BasisFunction, ExtraCoefficients)
{
Isis::BasisFunction testBasis("basis", 1, 2);
std::vector <double> coefs;
std::vector <double> vars;

coefs.push_back(1.0);
coefs.push_back(1.0);
testBasis.SetCoefficients(coefs);

vars.push_back(1.0);
try
{
testBasis.Evaluate(vars);
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Unable to evaluate function"))
<< e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message: "
"\"Unable to evaluate function for the given vector of values. "
"The number of terms in the expansion does not "
"match number of coefficients in the basis equation\"";
}
}

TEST(BasisFunction, NonVectorVariable)
{
Isis::BasisFunction testBasis("basis", 1, 1);
double var = 1.2;
double expectedOutput = 3.0;
double output;
std::vector <double> coefs;

coefs.push_back(2.5);
testBasis.SetCoefficients(coefs);
output = testBasis.Evaluate(var);
EXPECT_DOUBLE_EQ(output, expectedOutput);
}