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
cd6d2714
Commit
cd6d2714
authored
9 years ago
by
Shahroz Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
updates with 'MaxNumberOfBreaks' property and ClangFormat Refs #13335
parent
9dc31927
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/Framework/CurveFitting/test/SplineSmoothingTest.h
+55
-58
55 additions, 58 deletions
.../Mantid/Framework/CurveFitting/test/SplineSmoothingTest.h
with
55 additions
and
58 deletions
Code/Mantid/Framework/CurveFitting/test/SplineSmoothingTest.h
+
55
−
58
View file @
cd6d2714
...
...
@@ -8,94 +8,92 @@
using
Mantid
::
CurveFitting
::
SplineSmoothing
;
class
SplineSmoothingTest
:
public
CxxTest
::
TestSuite
{
class
SplineSmoothingTest
:
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
SplineSmoothingTest
*
createSuite
()
{
return
new
SplineSmoothingTest
();
}
static
void
destroySuite
(
SplineSmoothingTest
*
suite
)
{
delete
suite
;
}
//Functor for generating data
struct
SplineFunc
{
double
operator
()(
double
x
,
int
)
{
return
std
::
sin
(
x
);
}
static
SplineSmoothingTest
*
createSuite
()
{
return
new
SplineSmoothingTest
();
}
static
void
destroySuite
(
SplineSmoothingTest
*
suite
)
{
delete
suite
;
}
// Functor for generating data
struct
SplineFunc
{
double
operator
()(
double
x
,
int
)
{
return
std
::
sin
(
x
);
}
};
void
test_Init
()
{
void
test_Init
()
{
SplineSmoothing
alg
;
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
()
)
TS_ASSERT
(
alg
.
isInitialized
()
)
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
())
TS_ASSERT
(
alg
.
isInitialized
())
}
void
testExec
()
{
void
testExec
()
{
using
namespace
Mantid
::
API
;
//number of derivatives and spectra
const
int
order
(
2
),
spectra
(
2
);
//
number of derivatives and spectra
const
int
order
(
2
),
spectra
(
2
);
//create a binned workspace
MatrixWorkspace_sptr
inputWorkspace
=
WorkspaceCreationHelper
::
Create2DWorkspaceFromFunction
(
SplineFunc
(),
spectra
,
0
,
5
,
0.02
,
false
);
// create a binned workspace
MatrixWorkspace_sptr
inputWorkspace
=
WorkspaceCreationHelper
::
Create2DWorkspaceFromFunction
(
SplineFunc
(),
spectra
,
0
,
5
,
0.02
,
false
);
//setup algorithm
//
setup algorithm
SplineSmoothing
alg
;
runAlgorithm
(
alg
,
order
,
inputWorkspace
);
checkOutput
(
alg
);
}
void
testExecHistogramData
()
{
void
testExecHistogramData
()
{
using
namespace
Mantid
::
API
;
//number of derivatives and spectra
const
int
order
(
2
),
spectra
(
1
);
//
number of derivatives and spectra
const
int
order
(
2
),
spectra
(
1
);
//create a binned workspace
MatrixWorkspace_sptr
inputWorkspace
=
WorkspaceCreationHelper
::
Create2DWorkspaceFromFunction
(
SplineFunc
(),
spectra
,
0
,
5
,
0.02
,
true
);
// create a binned workspace
MatrixWorkspace_sptr
inputWorkspace
=
WorkspaceCreationHelper
::
Create2DWorkspaceFromFunction
(
SplineFunc
(),
spectra
,
0
,
5
,
0.02
,
true
);
SplineSmoothing
alg
;
runAlgorithm
(
alg
,
order
,
inputWorkspace
);
checkOutput
(
alg
);
}
void
testExecMultipleHistograms
()
{
void
testExecMultipleHistograms
()
{
using
namespace
Mantid
::
API
;
//number of derivatives and spectra
const
int
order
(
2
),
spectra
(
3
);
//
number of derivatives and spectra
const
int
order
(
2
),
spectra
(
3
);
//create a binned workspace
MatrixWorkspace_sptr
inputWorkspace
=
WorkspaceCreationHelper
::
Create2DWorkspaceFromFunction
(
SplineFunc
(),
spectra
,
0
,
5
,
0.02
,
true
);
// create a binned workspace
MatrixWorkspace_sptr
inputWorkspace
=
WorkspaceCreationHelper
::
Create2DWorkspaceFromFunction
(
SplineFunc
(),
spectra
,
0
,
5
,
0.02
,
true
);
SplineSmoothing
alg
;
runAlgorithm
(
alg
,
order
,
inputWorkspace
);
checkOutput
(
alg
);
}
void
checkOutput
(
const
SplineSmoothing
&
alg
)
const
{
void
checkOutput
(
const
SplineSmoothing
&
alg
)
const
{
using
namespace
Mantid
::
API
;
MatrixWorkspace_const_sptr
ows
=
alg
.
getProperty
(
"OutputWorkspace"
);
WorkspaceGroup_const_sptr
derivs
=
alg
.
getProperty
(
"OutputWorkspaceDeriv"
);
for
(
size_t
i
=
0
;
i
<
ows
->
getNumberHistograms
();
++
i
)
{
MatrixWorkspace_const_sptr
derivsWs
=
boost
::
dynamic_pointer_cast
<
const
MatrixWorkspace
>
(
derivs
->
getItem
(
i
));
const
auto
&
xs
=
ows
->
readX
(
i
);
const
auto
&
y
s
=
ows
->
read
Y
(
i
);
const
auto
&
d1
=
derivsW
s
->
readY
(
0
);
const
auto
&
d2
=
derivsWs
->
readY
(
1
);
//check output for consistency
for
(
size_t
j
=
0
;
j
<
ys
.
size
();
++
j
)
{
for
(
size_t
i
=
0
;
i
<
ows
->
getNumberHistograms
();
++
i
)
{
MatrixWorkspace_const_sptr
derivsWs
=
boost
::
dynamic_pointer_cast
<
const
MatrixWorkspace
>
(
derivs
->
getItem
(
i
)
)
;
const
auto
&
x
s
=
ows
->
read
X
(
i
);
const
auto
&
ys
=
ow
s
->
readY
(
i
);
const
auto
&
d1
=
derivsWs
->
readY
(
0
);
const
auto
&
d2
=
derivsWs
->
readY
(
1
);
// check output for consistency
for
(
size_t
j
=
0
;
j
<
ys
.
size
();
++
j
)
{
TS_ASSERT_DELTA
(
ys
[
j
],
std
::
sin
(
xs
[
j
]),
1e-4
);
TS_ASSERT_DELTA
(
d1
[
j
],
std
::
cos
(
xs
[
j
]),
1e-1
);
TS_ASSERT_DELTA
(
d2
[
j
],
-
std
::
sin
(
xs
[
j
]),
1e-1
);
...
...
@@ -103,23 +101,22 @@ public:
}
}
void
runAlgorithm
(
SplineSmoothing
&
alg
,
int
order
,
const
Mantid
::
API
::
MatrixWorkspace_sptr
&
iws
)
const
{
void
runAlgorithm
(
SplineSmoothing
&
alg
,
int
order
,
const
Mantid
::
API
::
MatrixWorkspace_sptr
&
iws
)
const
{
alg
.
initialize
();
alg
.
setChild
(
true
);
alg
.
setPropertyValue
(
"OutputWorkspace"
,
"Anon"
);
alg
.
setPropertyValue
(
"OutputWorkspaceDeriv"
,
"AnonDerivs"
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"Error"
,
0.05
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"DerivOrder"
,
order
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"Error"
,
0.05
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"DerivOrder"
,
order
));
TS_ASSERT_THROWS_NOTHING
(
alg
.
setProperty
(
"MaxNumberOfBreaks"
,
50
));
alg
.
setProperty
(
"InputWorkspace"
,
iws
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
()
);
TS_ASSERT
(
alg
.
isExecuted
()
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
());
TS_ASSERT
(
alg
.
isExecuted
());
}
};
#endif
/* MANTID_ALGORITHMS_SPLINETEST_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