Skip to content

Commit

Permalink
Refs #11043. Adding more unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Mar 17, 2015
1 parent 5db3ba1 commit d02719a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
Expand Up @@ -112,10 +112,10 @@ class PawleyFunction : public API::FunctionParameterDecorator {

void setPeaks(const std::vector<Kernel::V3D> &hkls, double fwhm,
double height);

void clearPeaks();

void addPeak(const Kernel::V3D &hkl, double fwhm, double height);
size_t getPeakCount() const;
API::IPeakFunction_sptr getPeakFunction(size_t i) const;
Kernel::V3D getPeakHKL(size_t i) const;

Expand Down
18 changes: 16 additions & 2 deletions Code/Mantid/Framework/CurveFitting/src/PawleyFunction.cpp
Expand Up @@ -247,7 +247,12 @@ void PawleyFunction::setProfileFunction(const std::string &profileFunction) {
m_pawleyParameterFunction->getProfileFunctionName()));

newFunction->setCentre(oldFunction->centre());
newFunction->setFwhm(oldFunction->fwhm());
try {
newFunction->setFwhm(oldFunction->fwhm());
}
catch (...) {
// do nothing.
}
newFunction->setHeight(oldFunction->height());

m_peakProfileComposite->replaceFunction(i, newFunction);
Expand Down Expand Up @@ -302,14 +307,23 @@ void PawleyFunction::addPeak(const Kernel::V3D &hkl, double fwhm,

peak->fix(peak->parameterIndex(
m_pawleyParameterFunction->getProfileFunctionCenterParameterName()));
peak->setFwhm(fwhm);

try {
peak->setFwhm(fwhm);
}
catch (...) {
// do nothing.
}

peak->setHeight(height);

m_peakProfileComposite->addFunction(peak);

m_compositeFunction->checkFunction();
}

size_t PawleyFunction::getPeakCount() const { return m_hkls.size(); }

IPeakFunction_sptr PawleyFunction::getPeakFunction(size_t i) const {
return boost::dynamic_pointer_cast<IPeakFunction>(
m_peakProfileComposite->getFunction(i));
Expand Down
55 changes: 54 additions & 1 deletion Code/Mantid/Framework/CurveFitting/test/PawleyFunctionTest.h
Expand Up @@ -251,6 +251,47 @@ class PawleyFunctionTest : public CxxTest::TestSuite {
cellParametersAre(cell, 3.0, 4.0, 5.0, 101.0, 111.0, 103.0);
}

void testSetParametersFromUnitCell() {
PawleyParameterFunction fn;
fn.initialize();

fn.setAttributeValue("CrystalSystem", "Triclinic");

UnitCell cell(3., 4., 5., 101., 111., 103.);

TS_ASSERT_THROWS_NOTHING(fn.setParametersFromUnitCell(cell));

TS_ASSERT_EQUALS(fn.getParameter("a"), 3.0);
TS_ASSERT_EQUALS(fn.getParameter("b"), 4.0);
TS_ASSERT_EQUALS(fn.getParameter("c"), 5.0);
TS_ASSERT_EQUALS(fn.getParameter("Alpha"), 101.0);
TS_ASSERT_EQUALS(fn.getParameter("Beta"), 111.0);
TS_ASSERT_EQUALS(fn.getParameter("Gamma"), 103.0);

fn.setAttributeValue("CrystalSystem", "Cubic");

cell.seta(5.43);
TS_ASSERT_THROWS_NOTHING(fn.setParametersFromUnitCell(cell));

TS_ASSERT_EQUALS(fn.getParameter("a"), 5.43);
}

void testProfileFunctionName() {
PawleyParameterFunction fn;
fn.initialize();

TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("ProfileFunction", "Gaussian"));
TS_ASSERT_EQUALS(fn.getProfileFunctionName(), "Gaussian");

// works only with IPeakFunctions
TS_ASSERT_THROWS(fn.setAttributeValue("ProfileFunction", "Chebyshev"),
std::invalid_argument);

TS_ASSERT_THROWS(fn.setAttributeValue("ProfileFunction", "DoesNotExist"),
Exception::NotFoundError);
}

void testPawleyFunctionInitialization() {
PawleyFunction fn;
fn.initialize();
Expand All @@ -276,12 +317,24 @@ class PawleyFunctionTest : public CxxTest::TestSuite {
void testPawleyFunctionAddPeak() {
PawleyFunction fn;
fn.initialize();
TS_ASSERT_EQUALS(fn.getPeakCount(), 0);

TS_ASSERT_EQUALS(fn.nParams(), 7);

fn.addPeak(V3D(), 3.0, 4.0);

TS_ASSERT_EQUALS(fn.nParams(), 10);
TS_ASSERT_EQUALS(fn.getPeakCount(), 1);
}

void testPawleyFunctionClearPeaks() {
PawleyFunction fn;
fn.initialize();

fn.addPeak(V3D(), 3.0, 4.0);
TS_ASSERT_EQUALS(fn.getPeakCount(), 1);
TS_ASSERT_THROWS_NOTHING(fn.clearPeaks());
TS_ASSERT_EQUALS(fn.getPeakCount(), 0);
}

void testPawleyFunctionSetProfileFunction() {
Expand All @@ -290,7 +343,7 @@ class PawleyFunctionTest : public CxxTest::TestSuite {

TS_ASSERT_EQUALS(fn.nParams(), 7);

fn.addPeak(V3D(), 2.0, 3.0, 4.0);
fn.addPeak(V3D(), 3.0, 4.0);

TS_ASSERT_EQUALS(fn.nParams(), 10);

Expand Down

0 comments on commit d02719a

Please sign in to comment.