Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
9333b9b6
Commit
9333b9b6
authored
9 years ago
by
Matt King
Browse files
Options
Downloads
Patches
Plain Diff
Starting Unit tests for CompactMD
Refs #13508
parent
7294ba52
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Code/Mantid/Framework/MDAlgorithms/test/CompactMDTest.h
+120
-17
120 additions, 17 deletions
Code/Mantid/Framework/MDAlgorithms/test/CompactMDTest.h
with
121 additions
and
17 deletions
Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
+
1
−
0
View file @
9333b9b6
...
...
@@ -257,6 +257,7 @@ set ( TEST_FILES
CentroidPeaksMDTest.h
CloneMDWorkspaceTest.h
CompareMDWorkspacesTest.h
CompactMDTest.h
ConvertCWPDMDToSpectraTest.h
ConvertCWSDExpToMomentumTest.h
ConvertEventsToMDTest.h
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/MDAlgorithms/test/CompactMDTest.h
+
120
−
17
View file @
9333b9b6
#ifndef MANTID_MDALGORITHMS_COMPACTMD_H_
#define MANTID_MDALGORITHMS_COMPACTMD_H_
#ifndef MANTID_MDALGORITHMS_COMPACTMD
TEST
_H_
#define MANTID_MDALGORITHMS_COMPACTMD
TEST
_H_
#include
<cxxtest/TestSuite.h>
#include
"MantidMDAlgorithms/CompactMD.h"
#include
"MantidDataObjects/MDHistoWorkspace.h"
#include
"MantidTestHelpers/MDEventsTestHelper.h"
...
...
@@ -8,22 +9,124 @@
using
Mantid
::
MDAlgorithms
::
CompactMD
;
using
namespace
Mantid
::
API
;
class
CompactMDTest
:
public
CxxTest
::
TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static
CompactMDTest
*
createSuite
(){
return
new
CompactMDTest
();}
static
void
destroySuite
(
CompactMDTest
*
suite
)
{
delete
suite
;}
namespace
{
void
test_Init
()
{
CompactMD
alg
;
TSM_ASSERT_THROWS_NOTHING
(
alg
.
initialize
()
);
TS_ASSERT
(
alg
);
}
};
// This helper sets the signal values to the linear index to have some
// variety
void
resetSignalsToLinearIndexValue
(
IMDHistoWorkspace_sptr
ws
)
{
auto
numberOfIndices
=
static_cast
<
size_t
>
(
ws
->
getNPoints
());
for
(
size_t
i
=
0
;
i
<
numberOfIndices
;
++
i
)
{
auto
&
signal
=
ws
->
signalAt
(
i
);
signal
=
static_cast
<
Mantid
::
signal_t
>
(
i
);
}
}
}
//==================
// Functional Tests
//==================
class
CompactMDTest
:
public
CxxTest
::
TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static
CompactMDTest
*
createSuite
()
{
return
new
CompactMDTest
();
}
static
void
destroySuite
(
CompactMDTest
*
suite
)
{
delete
suite
;
}
#endif // !MANTID_MDALGORITHMS_COMPACTMD_H_
void
test_Init
()
{
CompactMD
alg
;
TSM_ASSERT_THROWS_NOTHING
(
"Instance of CompactMD threw: "
,
alg
.
initialize
());
TSM_ASSERT
(
"Instance of CompactMD was not initialised: "
,
alg
.
isInitialized
());
}
void
test_that_all_non_zero_signals_are_kept_with_data_concentrated_in_the_centre
()
{
/*
*testing the effectiveness of CompactMD when the data looks like this:
*------------------
* Input structure:
*------------------
* -------------
* | | | |
* -------------
* | |///| |
* -------------
* | | | |
* -------------
* -3-2-1 0 1 2 3
*---------------------------
* Expected output structure:
*----------------------------
* should trim until the first non-zero value.
* -------
* |/////|
* -------
* -1 0 1
*/
using
namespace
Mantid
::
DataObjects
;
const
size_t
numDims
=
1
;
const
double
signal
=
0.0
;
const
double
errorSquared
=
1.3
;
size_t
numBins
[
static_cast
<
int
>
(
numDims
)]
=
{
3
};
Mantid
::
coord_t
min
[
static_cast
<
int
>
(
numDims
)]
=
{
-
3
};
Mantid
::
coord_t
max
[
static_cast
<
int
>
(
numDims
)]
=
{
3
};
const
std
::
string
name
(
"test"
);
auto
inWS
=
MDEventsTestHelper
::
makeFakeMDHistoWorkspaceGeneral
(
numDims
,
signal
,
errorSquared
,
numBins
,
min
,
max
,
name
);
inWS
->
setSignalAt
(
1
,
1.0
);
// set middle bin signal to one
CompactMD
alg
;
alg
.
setChild
(
true
);
alg
.
setRethrows
(
true
);
alg
.
initialize
();
alg
.
setProperty
(
"InputWorkspace"
,
inWS
);
alg
.
setProperty
(
"OutputWorkspace"
,
"out"
);
alg
.
execute
();
// output workspace should be cropped so extents ~ [-1,1]
IMDHistoWorkspace_sptr
outputWorkspace
=
alg
.
getProperty
(
"OutputWorkspace"
);
TSM_ASSERT_EQUALS
(
"Should have a signal of 1.0: "
,
outputWorkspace
->
getSignalAt
(
0
),
1
);
TSM_ASSERT_EQUALS
(
"Minimum should be cropped to -1: "
,
outputWorkspace
->
getDimension
(
0
)
->
getMinimum
(),
-
1.0
);
TSM_ASSERT_EQUALS
(
"Maximum should be cropped to 1: "
,
outputWorkspace
->
getDimension
(
0
)
->
getMaximum
(),
1.0
);
TSM_ASSERT_EQUALS
(
"Number of Bins should be 1 : "
,
outputWorkspace
->
getDimension
(
0
)
->
getNBins
(),
1.0
);
TSM_ASSERT_EQUALS
(
"Bin width should be consistent: "
,
outputWorkspace
->
getDimension
(
0
)
->
getBinWidth
(),
inWS
->
getDimension
(
0
)
->
getBinWidth
());
}
void
test__all_non_zero_signals_are_kept_with_data_in_each_corner
(){
/*
*testing the effectiveness of CompactMD when the data looks like this:
*------------------
* Input structure:
*------------------
* -------------
* |///| |///|
* -------------
* | | | |
* -------------
* |///| |///|
* -------------
* -3-2-1 0 1 2 3
*---------------------------
* Expected output structure:
*----------------------------
* should not trim the workspace at all.
* -------------
* |///| |///|
* -------------
* | | | |
* -------------
* |///| |///|
* -------------
* -3-2-1 0 1 2 3
*/
}
};
//===================
// Performance Tests
//===================
//TODO:
#endif // !MANTID_MDALGORITHMS_COMPACTMDTEST_H_
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment