Skip to content

Commit

Permalink
refs #7281. Regression tests added.
Browse files Browse the repository at this point in the history
.Menu options were broken as forgot to reimplement.
  • Loading branch information
OwenArnold committed Jun 12, 2013
1 parent 0874d4d commit 5de1883
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,22 @@ namespace MantidQt

double ConcretePeaksPresenter::getPeakSizeOnProjection() const
{
throw std::runtime_error("Not implemented");
double result = 0;
if (m_viewPeaks != NULL && m_viewPeaks->positionOnly())
{
result = m_viewPeaks->getOccupancyInView();
}
return result;
}

double ConcretePeaksPresenter::getPeakSizeIntoProjection() const
{
throw std::runtime_error("Not implemented");
double result = 0;
if (m_viewPeaks != NULL && m_viewPeaks->positionOnly())
{
result = m_viewPeaks->getOccupancyIntoView();
}
return result;
}

}
Expand Down
53 changes: 53 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,59 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS("QSample", coordinateToString(Mantid::API::QSample));
}

void test_getPeaksSizeOnProjection()
{
const int nPeaks = 1;
const double occupancyInView = 0.07;

// Create a mock view object/product that will be returned by the mock factory.
auto pMockView = new NiceMock<MockPeakOverlayView>;
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);
EXPECT_CALL(*pMockView, positionOnly()).WillOnce(Return(true)); // A peak repesentation without an absolute size.
EXPECT_CALL(*pMockView, getOccupancyInView()).WillOnce(Return(occupancyInView)); // The occupancy that the VIEW returns.
// Create a widget factory mock
auto pMockViewFactory = new MockPeakOverlayFactory;
PeakOverlayViewFactory_sptr mockViewFactory = PeakOverlayViewFactory_sptr(pMockViewFactory);
EXPECT_CALL(*pMockViewFactory, createView(_)).WillRepeatedly(Return(mockView));
EXPECT_CALL(*pMockViewFactory, getPlotXLabel()).WillRepeatedly(Return("H"));
EXPECT_CALL(*pMockViewFactory, getPlotYLabel()).WillRepeatedly(Return("K"));

auto presenterBuilder = createStandardBuild(nPeaks); // Creates a default Concrete presenter product.
presenterBuilder.withViewFactory(mockViewFactory); // Change the view factories to deliver the expected mock object
auto concretePresenter = presenterBuilder.create();

TS_ASSERT_EQUALS(occupancyInView, concretePresenter->getPeakSizeOnProjection());

TS_ASSERT(Mock::VerifyAndClearExpectations(pMockView));
}

void test_getPeaksSizeIntoProjection()
{
const int nPeaks = 1;
const double occupancyIntoView = 0.05;

// Create a mock view object/product that will be returned by the mock factory.
auto pMockView = new NiceMock<MockPeakOverlayView>;
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);
EXPECT_CALL(*pMockView, positionOnly()).WillOnce(Return(true)); // A peak repesentation without an absolute size.
EXPECT_CALL(*pMockView, getOccupancyIntoView()).WillOnce(Return(occupancyIntoView)); // The occupancy that the VIEW returns.
// Create a widget factory mock
auto pMockViewFactory = new MockPeakOverlayFactory;
PeakOverlayViewFactory_sptr mockViewFactory = PeakOverlayViewFactory_sptr(pMockViewFactory);
EXPECT_CALL(*pMockViewFactory, createView(_)).WillRepeatedly(Return(mockView));
EXPECT_CALL(*pMockViewFactory, getPlotXLabel()).WillRepeatedly(Return("H"));
EXPECT_CALL(*pMockViewFactory, getPlotYLabel()).WillRepeatedly(Return("K"));

auto presenterBuilder = createStandardBuild(nPeaks); // Creates a default Concrete presenter product.
presenterBuilder.withViewFactory(mockViewFactory); // Change the view factories to deliver the expected mock object
auto concretePresenter = presenterBuilder.create();

TS_ASSERT_EQUALS(occupancyIntoView, concretePresenter->getPeakSizeIntoProjection());

TS_ASSERT(Mock::VerifyAndClearExpectations(pMockView));
}


};


Expand Down

0 comments on commit 5de1883

Please sign in to comment.