Skip to content

Commit

Permalink
Unit test changes to NumericAxis
Browse files Browse the repository at this point in the history
Refs #11179
  • Loading branch information
DanNixon committed Feb 26, 2015
1 parent 9016870 commit d2f9d86
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions Code/Mantid/Framework/API/test/NumericAxisTest.h
Expand Up @@ -34,12 +34,12 @@ class NumericAxisTest : public CxxTest::TestSuite
numericAxis = new NumericAxis(5);
numericAxis->title() = "A numeric axis";
}

~NumericAxisTest()
{
delete numericAxis;
}

void testConstructor()
{
TS_ASSERT_EQUALS( numericAxis->title(), "A numeric axis" );
Expand All @@ -56,23 +56,23 @@ class NumericAxisTest : public CxxTest::TestSuite
axistester.title() = "tester";
axistester.unit() = UnitFactory::Instance().create("Wavelength");
axistester.setValue(0,5.5);

NumericAxisTester copiedAxis = axistester;
TS_ASSERT_EQUALS( copiedAxis.title(), "tester" );
TS_ASSERT_EQUALS( copiedAxis.unit()->unitID(), "Wavelength" );
TS_ASSERT( copiedAxis.isNumeric() );
TS_ASSERT_EQUALS( copiedAxis(0), 5.5 );
TS_ASSERT_THROWS( copiedAxis(1), Exception::IndexError );
}

void testClone()
{
WorkspaceTester ws; // Fake workspace to pass to clone
Axis* newNumAxis = numericAxis->clone(&ws);
TS_ASSERT_DIFFERS( newNumAxis, numericAxis );
delete newNumAxis;
}

void testCloneDifferentLength()
{
numericAxis->setValue(0,9.9);
Expand Down Expand Up @@ -124,7 +124,7 @@ class NumericAxisTest : public CxxTest::TestSuite
{
TS_ASSERT_THROWS( numericAxis->setValue(-1, 1.1), Exception::IndexError );
TS_ASSERT_THROWS( numericAxis->setValue(5, 1.1), Exception::IndexError );

for (int i=0; i<5; ++i)
{
TS_ASSERT_THROWS_NOTHING( numericAxis->setValue(i, i+0.5) );
Expand All @@ -146,7 +146,7 @@ class NumericAxisTest : public CxxTest::TestSuite
{
axis.setValue(i, static_cast<double>(i));
}

std::vector<double> boundaries = axis.createBinBoundaries();
const size_t nvalues(boundaries.size());
TS_ASSERT_EQUALS(nvalues, npoints + 1);
Expand All @@ -172,6 +172,21 @@ class NumericAxisTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(4, axis.indexOfValue(5.4));
}

void test_equalWithinTolerance()
{
double points1[] = {1.0, 2.0, 3.0, 4.0, 5.0};
double points2[] = {1.0, 2.0, 3.0, 4.0, 5.001};
const size_t npoints(5);
NumericAxis axis1(std::vector<double>(points1, points1 + npoints));
NumericAxis axis2(std::vector<double>(points2, points2 + npoints));

// Difference (0.001) < tolerance (0.01), should be equal
TS_ASSERT( axis1.equalWithinTolerance(axis2, 0.01) );

// Difference (0.001) > tolerance (0.0001), should not be equal
TS_ASSERT( !axis1.equalWithinTolerance(axis2, 0.0001) );
}

//-------------------------------- Failure cases ----------------------------

void test_indexOfValue_Throws_When_Input_Not_In_Axis_Range()
Expand Down

0 comments on commit d2f9d86

Please sign in to comment.