Skip to content

Commit

Permalink
Added LineEqationTests.cpp (#3152)
Browse files Browse the repository at this point in the history
  • Loading branch information
paarongiroux authored and Kelvin Rodriguez committed Mar 11, 2019
1 parent ce26475 commit e6fb02c
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions isis/src/base/objs/LineEquation/LineEquation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions isis/src/base/objs/LineEquation/LineEquation.truth

This file was deleted.

30 changes: 0 additions & 30 deletions isis/src/base/objs/LineEquation/unitTest.cpp

This file was deleted.

173 changes: 173 additions & 0 deletions isis/tests/LineEquationTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#include <gtest/gtest.h>
#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"))
<<e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message:"
"\"Line equation undefined: 2 points are required\"";
}
}

TEST(LineEquation, UndefinedIntercept)
{
Isis::LineEquation testEquation;

try
{
testEquation.Intercept();
FAIL() << "Expected an exception to be thrown";
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Line equation undefined"))
<<e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message:"
" \"Line equation undefined: 2 points are required\"";
}
}

TEST(LineEquation, AddSamePoints)
{
Isis::LineEquation testEquation;
testEquation.AddPoint(1.0,1.0);
testEquation.AddPoint(1.0,1.0);

try
{
testEquation.Intercept();
FAIL() << "Expected an exception to be thrown";
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Points have identical"))
<<e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message:"
"\"Points have identical independent variables -- no intercept\"";
}

try
{
testEquation.Slope();
FAIL() << "Expected an exception to be thrown";
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Points have identical"))
<<e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message:"
"\"Points have identical independent variables -- no slope\"";
}
}

TEST(LineEquation, InitSamePoints)
{
try
{
Isis::LineEquation testEquation(1.0,1.0,1.0,1.0);
FAIL() << "Expected an exception to be thrown";
}
catch(Isis::IException &e)
{
EXPECT_TRUE(e.toString().toLatin1().contains("Points have identical"))
<<e.toString().toStdString();
}
catch(...)
{
FAIL() << "Expected an IException with message:"
"\"Points have identical independent variables -- no intercept\"";
}
}

0 comments on commit e6fb02c

Please sign in to comment.