diff --git a/.gitignore b/.gitignore index be8aea3649..b2738b0bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,7 @@ print.prt */tsts/*/output/* */build/ build/ -*/install/ +install/ # Created by https://www.gitignore.io/api/macos # Edit at https://www.gitignore.io/?templates=macos diff --git a/isis/src/base/objs/LineEquation/LineEquation.cpp b/isis/src/base/objs/LineEquation/LineEquation.cpp index b7d08ddc6a..04efba3a22 100644 --- a/isis/src/base/objs/LineEquation/LineEquation.cpp +++ b/isis/src/base/objs/LineEquation/LineEquation.cpp @@ -90,6 +90,7 @@ namespace Isis { } else if(!p_slopeDefined) { p_slope = (p_y[0] - p_y[1]) / (p_x[0] - p_x[1]); + p_slopeDefined = true; } return p_slope; } @@ -110,6 +111,7 @@ namespace Isis { } else if(!p_interceptDefined) { p_intercept = p_y[0] - Slope() * p_x[0]; + p_interceptDefined = true; } return p_intercept; diff --git a/isis/src/base/objs/LineEquation/LineEquation.truth b/isis/src/base/objs/LineEquation/LineEquation.truth deleted file mode 100644 index 29e90dc1fe..0000000000 --- a/isis/src/base/objs/LineEquation/LineEquation.truth +++ /dev/null @@ -1,7 +0,0 @@ -Unit test for LineEquation -Testing first constructor... - Slope = 2.5 - Intercept = -1.5 -Testing second constructor... - Slope = -0.5 - Intercept = 0.5 diff --git a/isis/src/base/objs/LineEquation/unitTest.cpp b/isis/src/base/objs/LineEquation/unitTest.cpp deleted file mode 100644 index 90adb00b01..0000000000 --- a/isis/src/base/objs/LineEquation/unitTest.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include "LineEquation.h" -#include "FileName.h" -#include "Preference.h" -#include "Table.h" - - - -using namespace std; - -int main(int argc, char *argv[]) { - Isis::Preference::Preferences(true); - - cout << setprecision(8); - cout << "Unit test for LineEquation" << endl; - - cout << "Testing first constructor..." << endl; - Isis::LineEquation line1; - line1.AddPoint(1., 1.); - line1.AddPoint(3., 6.); - cout << " Slope = " << line1.Slope() << endl; - cout << " Intercept = " << line1.Intercept() << endl; - - cout << "Testing second constructor..." << endl; - Isis::LineEquation line2(-1., 1., -3., 2.); - cout << " Slope = " << line2.Slope() << endl; - cout << " Intercept = " << line2.Intercept() << endl; - -} diff --git a/isis/tests/LineEquationTests.cpp b/isis/tests/LineEquationTests.cpp new file mode 100644 index 0000000000..549c0da07a --- /dev/null +++ b/isis/tests/LineEquationTests.cpp @@ -0,0 +1,173 @@ +#include +#include "LineEquation.h" +#include "IException.h" +#include "TestUtilities.h" + +TEST(LineEquation, DefaultConstructor) +{ + Isis::LineEquation testEquation; + + EXPECT_FALSE(testEquation.Defined()); + EXPECT_FALSE(testEquation.HaveSlope()); + EXPECT_FALSE(testEquation.HaveIntercept()); + EXPECT_EQ(testEquation.Points(), 0); +} + +TEST(LineEquation, InitConstructor) +{ + Isis::LineEquation testEquation(1.0, 2.0, 3.0, 4.0); + + EXPECT_TRUE(testEquation.Defined()); + EXPECT_TRUE(testEquation.HaveSlope()); + EXPECT_TRUE(testEquation.HaveIntercept()); + + EXPECT_DOUBLE_EQ(testEquation.Slope(), 1.0); + EXPECT_DOUBLE_EQ(testEquation.Intercept(), 1.0); + EXPECT_EQ(testEquation.Points(), 2); +} + +TEST(LineEquation, AddingPoints) +{ + Isis::LineEquation testEquation; + + testEquation.AddPoint(1.0,2.0); + + EXPECT_EQ(testEquation.Points(), 1); + EXPECT_FALSE(testEquation.HaveSlope()); + EXPECT_FALSE(testEquation.HaveIntercept()); + EXPECT_FALSE(testEquation.Defined()); + + testEquation.AddPoint(3.0,4.0); + + EXPECT_EQ(testEquation.Points(), 2); + EXPECT_FALSE(testEquation.HaveSlope()); + EXPECT_FALSE(testEquation.HaveIntercept()); + EXPECT_TRUE(testEquation.Defined()); + EXPECT_DOUBLE_EQ(testEquation.Slope(), 1.0); + EXPECT_DOUBLE_EQ(testEquation.Intercept(), 1.0); + EXPECT_TRUE(testEquation.HaveSlope()); + EXPECT_TRUE(testEquation.HaveIntercept()); + + try + { + testEquation.AddPoint(5.0, 6.0); + FAIL() << "Expected an exception to be thrown"; + } + catch(Isis::IException &e) + { + EXPECT_TRUE(e.toString().toLatin1().contains("Line equation is already defined")) + << e.toString().toStdString(); + } + catch(...) + { + FAIL() << "Expected an IException with message:" + "\"Line equation is already defined with 2 points\""; + } + + EXPECT_EQ(testEquation.Points(), 2); + EXPECT_TRUE(testEquation.HaveSlope()); + EXPECT_TRUE(testEquation.HaveIntercept()); + EXPECT_TRUE(testEquation.Defined()); + EXPECT_DOUBLE_EQ(testEquation.Slope(), 1.0); + EXPECT_DOUBLE_EQ(testEquation.Intercept(), 1.0); +} + +TEST(LineEquation, UndefinedSlope) +{ + Isis::LineEquation testEquation; + + try + { + testEquation.Slope(); + FAIL() << "Expected an exception to be thrown"; + } + catch(Isis::IException &e) + { + EXPECT_TRUE(e.toString().toLatin1().contains("Line equation undefined")) + <