Skip to content

Commit

Permalink
refs #9428. Extend functional and performance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed May 9, 2014
1 parent c7d22a8 commit 6a182aa
Showing 1 changed file with 165 additions and 10 deletions.
175 changes: 165 additions & 10 deletions Code/Mantid/Framework/MDEvents/test/MDHistoWorkspaceIteratorTest.h
Expand Up @@ -297,7 +297,8 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
TS_ASSERT(!iterator.isWithinBounds(end));
}

void do_test_neighbours_1d(boost::function<std::vector<size_t>(MDHistoWorkspaceIterator*) > findNeighbourMemberFunction)
void do_test_neighbours_1d(
boost::function<std::vector<size_t>(MDHistoWorkspaceIterator*)> findNeighbourMemberFunction)
{
const size_t nd = 1;
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, nd, 10);
Expand All @@ -324,8 +325,8 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
// Go to intermediate position
/*
0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9
^
|
^
|
*/
it->next();
neighbourIndexes = findNeighbourMemberFunction(it);
Expand All @@ -337,8 +338,8 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
// Go to last position
/*
0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9
^
|
^
|
*/
it->jumpTo(9);
neighbourIndexes = findNeighbourMemberFunction(it);
Expand All @@ -348,19 +349,88 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite

void test_neighbours_1d_face_touching()
{
boost::function<std::vector<size_t>(MDHistoWorkspaceIterator*) > findNeighbourIndexesFaceTouching = &MDHistoWorkspaceIterator::findNeighbourIndexesFaceTouching;
boost::function<std::vector<size_t>(MDHistoWorkspaceIterator*)> findNeighbourIndexesFaceTouching =
&MDHistoWorkspaceIterator::findNeighbourIndexesFaceTouching;
do_test_neighbours_1d(findNeighbourIndexesFaceTouching);
}

void test_neighours_1d_vertex_touching()
{
boost::function<std::vector<size_t>(MDHistoWorkspaceIterator*) > findNeighbourIndexesVertexTouching = &MDHistoWorkspaceIterator::findNeighbourIndexes;
boost::function<std::vector<size_t>(MDHistoWorkspaceIterator*)> findNeighbourIndexesVertexTouching =
&MDHistoWorkspaceIterator::findNeighbourIndexes;
do_test_neighbours_1d(findNeighbourIndexesVertexTouching);
}

void test_neighbours_2d_face_touching()
{
throw std::runtime_error("Test not implemented yet");
const size_t nd = 2;
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, nd, 4);
/*
2D MDHistoWorkspace
0 - 1 - 2 - 3
4 - 5 - 6 - 7
8 - 9 -10 -11
12-13 -14 -15
*/
MDHistoWorkspaceIterator * it = new MDHistoWorkspaceIterator(ws);

// At initial position
/*
|0| - 1 - 2 - 3
4 - 5 - 6 - 7
8 - 9 -10 -11
12-13 -14 -15
*/
std::vector<size_t> neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(2, neighbourIndexes.size());
// Is on an edge
TSM_ASSERT( "Neighbour at index 0 is 1", doesContainIndex(neighbourIndexes, 1));
TSM_ASSERT( "Neighbour at index 0 is 4", doesContainIndex(neighbourIndexes, 4));

// At first position
/*
0 -|1|- 2 - 3
4 - 5 - 6 - 7
8 - 9 -10 -11
12-13 -14 -15
*/
it->next();
neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(3, neighbourIndexes.size());
TSM_ASSERT( "Neighbour at index 1 is 0", doesContainIndex(neighbourIndexes, 0));
TSM_ASSERT( "Neighbour at index 1 is 2", doesContainIndex(neighbourIndexes, 2));
TSM_ASSERT( "Neighbour at index 1 is 5", doesContainIndex(neighbourIndexes, 5));

// At index 9 position
/*
0 - 1 - 2 - 3
4 - 5 - 6 - 7
8 -|9|-10 -11
12-13 -14 -15
*/
it->jumpTo(9);
neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(4, neighbourIndexes.size());

TSM_ASSERT( "Neighbour at index 9 is 5", doesContainIndex(neighbourIndexes, 5));
TSM_ASSERT( "Neighbour at index 9 is 8", doesContainIndex(neighbourIndexes, 8));
TSM_ASSERT( "Neighbour at index 9 is 10", doesContainIndex(neighbourIndexes, 10));
TSM_ASSERT( "Neighbour at index 9 is 13", doesContainIndex(neighbourIndexes, 13));

// At last position
/*
0 - 1 - 2 - 3
4 - 5 - 6 - 7
8 - 9 -10 -11
12-13 -14 -|15|
*/
it->jumpTo(15);
neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(2, neighbourIndexes.size());
// Is on an edge
TSM_ASSERT( "Neighbour at index 15 is 11", doesContainIndex(neighbourIndexes, 11));
TSM_ASSERT( "Neighbour at index 15 is 14", doesContainIndex(neighbourIndexes, 14));
}

void test_neighbours_2d_vertex_touching()
Expand Down Expand Up @@ -443,7 +513,83 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
TSM_ASSERT( "Neighbour at index 15 is 14", doesContainIndex(neighbourIndexes, 14));
}

void test_neighbours_3d()
void test_neighbours_3d_face_touching()
{
const size_t nd = 3;
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, nd, 4);
/*
3D MDHistoWorkspace
[[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]
[12 13 14 15]]
[[16 17 18 19]
[20 21 22 23]
[24 25 26 27]
[28 29 30 31]]
[[32 33 34 35]
[36 37 38 39]
[40 41 42 43]
[44 45 46 47]]
[[48 49 50 51]
[52 53 54 55]
[56 57 58 59]
[60 61 62 63]]]
*/

MDHistoWorkspaceIterator * it = new MDHistoWorkspaceIterator(ws);

// Start at Index = 0
std::vector<size_t> neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(3, neighbourIndexes.size());
// Is on an edge
TS_ASSERT(doesContainIndex(neighbourIndexes, 1));
TS_ASSERT(doesContainIndex(neighbourIndexes, 4));
TS_ASSERT(doesContainIndex(neighbourIndexes, 16));

// Move to index 1
it->jumpTo(1);
neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(4, neighbourIndexes.size());
std::vector<size_t> expected_neighbours = boost::assign::list_of(0)(2)(5)(17).convert_to_container<
std::vector<size_t>>();
for (auto i = expected_neighbours.begin(); i != expected_neighbours.end(); ++i)
{
TS_ASSERT(doesContainIndex(neighbourIndexes, *i));
}

// Move to index 21
it->jumpTo(21);
neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TSM_ASSERT_EQUALS("Should have 2*n neighbours here", 6, neighbourIndexes.size());
// Is completely enclosed
expected_neighbours = boost::assign::list_of(17)(20)(22)(25)(5)(37).convert_to_container<
std::vector<size_t>>();

for (auto i = expected_neighbours.begin(); i != expected_neighbours.end(); ++i)
{
TS_ASSERT(doesContainIndex(neighbourIndexes, *i));
}

// Move to index 63. The last index.
it->jumpTo(63);
neighbourIndexes = it->findNeighbourIndexesFaceTouching();
TS_ASSERT_EQUALS(3, neighbourIndexes.size());
// Is on edge
expected_neighbours = boost::assign::list_of(47)(59)(62).convert_to_container<std::vector<size_t>>();

for (auto i = expected_neighbours.begin(); i != expected_neighbours.end(); ++i)
{
TS_ASSERT(doesContainIndex(neighbourIndexes, *i));
}

}

void test_neighbours_3d_vertex_touching()
{
const size_t nd = 3;
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, nd, 4);
Expand Down Expand Up @@ -513,7 +659,7 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
it->jumpTo(63);
neighbourIndexes = it->findNeighbourIndexes();
TS_ASSERT_EQUALS(7, neighbourIndexes.size());
// Is completely enclosed
// Is on edge
expected_neighbours = boost::assign::list_of(42)(43)(46)(47)(58)(59)(62).convert_to_container<
std::vector<size_t>>();

Expand Down Expand Up @@ -643,6 +789,15 @@ class MDHistoWorkspaceIteratorTestPerformance: public CxxTest::TestSuite
} while (iterator.next());
}

void test_findNeighboursFaceTouching()
{
MDHistoWorkspaceIterator iterator(small_ws, new SkipNothing());
do
{
iterator.findNeighbourIndexesFaceTouching();
} while (iterator.next());
}

};

#endif /* MANTID_MDEVENTS_MDHISTOWORKSPACEITERATORTEST_H_ */
Expand Down

0 comments on commit 6a182aa

Please sign in to comment.