Skip to content

Commit

Permalink
Refs #10537 Added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Dec 16, 2014
1 parent 078d6c6 commit 19b251a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
3 changes: 0 additions & 3 deletions Code/Mantid/Vates/VatesAPI/src/vtkSplatterPlotFactory.cpp
Expand Up @@ -318,7 +318,6 @@ namespace VATES
*/
void vtkSplatterPlotFactory::doCreateMDHisto(IMDHistoWorkspace_sptr workspace) const
{
CPUTimer tim;
// Acquire a scoped read-only lock to the workspace (prevent segfault
// from algos modifying wworkspace)
ReadLock lock(*workspace);
Expand Down Expand Up @@ -421,8 +420,6 @@ namespace VATES
visualDataSet->SetPoints(points);
visualDataSet->GetCellData()->SetScalars(signal);

std::cout << tim << " to create the visual data set." << std::endl;

points->Delete();
signal->Delete();
visualDataSet->Squeeze();
Expand Down
59 changes: 59 additions & 0 deletions Code/Mantid/Vates/VatesAPI/test/vtkSplatterPlotFactoryTest.h
Expand Up @@ -46,6 +46,65 @@ class vtkSplatterPlotFactoryTest : public CxxTest::TestSuite
}

/*Demonstrative tests*/
void test_3DHistoWorkspace()
{
FakeProgressAction progressUpdate;

// Create workspace with 5x5x5 binning
size_t binning = 5;
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, 3, binning);
vtkSplatterPlotFactory factory(ThresholdRange_scptr(new UserDefinedThresholdRange(0, 1)), "signal");
factory.initialize(ws);
vtkDataSet* product = NULL;

TS_ASSERT_THROWS_NOTHING(product = factory.create(progressUpdate));

// Expecting 5x5x5 points; Signal equal for each box => 1/(10^3/5^3)
const size_t expected_n_points = binning*binning*binning;
const size_t expected_n_cells = binning*binning*binning;
const size_t expected_n_signals = expected_n_cells;
const double expected_signal_value = 1.0/((10.0*10.0*10.0)/(5.0*5.0*5.0));

double* range = product->GetScalarRange();

TSM_ASSERT_EQUALS("Should have one point per bin.", expected_n_points, product->GetNumberOfPoints());
TSM_ASSERT_EQUALS("Should have one cells per bin", expected_n_cells, product->GetNumberOfCells());
TSM_ASSERT_EQUALS("Should have signal flag", "signal", std::string(product->GetCellData()->GetArray(0)->GetName()));
TSM_ASSERT_EQUALS("Should have one signal per bin", expected_n_signals, product->GetCellData()->GetArray(0)->GetSize());
TSM_ASSERT_EQUALS("Should have a signal which is normalized to the 3D volume", expected_signal_value, range[0]);

product->Delete();
}

void test_4DHistoWorkspace()
{
FakeProgressAction progressUpdate;

// Create workspace with 5x5x5x5 binning, signal is 1 and extent for each dimension is 10
size_t binning = 5;
IMDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, 4, binning);
vtkSplatterPlotFactory factory(ThresholdRange_scptr(new UserDefinedThresholdRange(0, 1)), "signal");
factory.initialize(ws);
vtkDataSet* product = NULL;

TS_ASSERT_THROWS_NOTHING(product = factory.create(progressUpdate));

// Expecting 5x5x5 points; Signal equal for each box => 1/(10^4/5^4)
const size_t expected_n_points = binning*binning*binning;
const size_t expected_n_cells = binning*binning*binning;
const size_t expected_n_signals = expected_n_cells;
const double expected_signal_value = 1.0/((10.0*10.0*10.0*10.0)/(5.0*5.0*5.0*5.0));

double* range = product->GetScalarRange();

TSM_ASSERT_EQUALS("Should have one point per bin.", expected_n_points, product->GetNumberOfPoints());
TSM_ASSERT_EQUALS("Should have one cells per bin", expected_n_cells, product->GetNumberOfCells());
TSM_ASSERT_EQUALS("Should have signal flag", "signal", std::string(product->GetCellData()->GetArray(0)->GetName()));
TSM_ASSERT_EQUALS("Should have one signal per bin", expected_n_signals, product->GetCellData()->GetArray(0)->GetSize());
TSM_ASSERT_EQUALS("Should have a signal which is normalized to the 4D volume", expected_signal_value, range[0]);

product->Delete();
}

void test_3DWorkspace()
{
Expand Down

0 comments on commit 19b251a

Please sign in to comment.