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
8b7e7030
Commit
8b7e7030
authored
9 years ago
by
Dan Nixon
Browse files
Options
Downloads
Patches
Plain Diff
Add unit test for original fault
Refs #8935
parent
d1f88211
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/Framework/DataHandling/test/RenameLogTest.h
+78
-31
78 additions, 31 deletions
Code/Mantid/Framework/DataHandling/test/RenameLogTest.h
with
78 additions
and
31 deletions
Code/Mantid/Framework/DataHandling/test/RenameLogTest.h
+
78
−
31
View file @
8b7e7030
...
@@ -23,7 +23,6 @@ public:
...
@@ -23,7 +23,6 @@ public:
static
RenameLogTest
*
createSuite
()
{
return
new
RenameLogTest
();
}
static
RenameLogTest
*
createSuite
()
{
return
new
RenameLogTest
();
}
static
void
destroySuite
(
RenameLogTest
*
suite
)
{
delete
suite
;
}
static
void
destroySuite
(
RenameLogTest
*
suite
)
{
delete
suite
;
}
void
test_Init
()
void
test_Init
()
{
{
RenameLog
renlog
;
RenameLog
renlog
;
...
@@ -32,37 +31,39 @@ public:
...
@@ -32,37 +31,39 @@ public:
TS_ASSERT
(
renlog
.
isInitialized
());
TS_ASSERT
(
renlog
.
isInitialized
());
}
}
void
test_Rename
(){
void
test_Rename
()
{
// 1. Generate workspace & 2 logs
// 1. Generate workspace & 2 logs
API
::
MatrixWorkspace_sptr
m
WS
=
API
::
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
1
,
100
,
100
);
API
::
MatrixWorkspace_sptr
test
WS
=
generateTestWorkspace
(
);
Kernel
::
TimeSeriesProperty
<
double
>
*
p1
=
new
Kernel
::
TimeSeriesProperty
<
double
>
(
"OriginalLog"
);
// 2. Add workspace to data serive
AnalysisDataService
::
Instance
().
addOrReplace
(
"TestDummy"
,
testWS
);
int64_t
t1_ns
=
1000000
;
// 3. Running
int64_t
dt_ns
=
400
;
RenameLog
renlog
;
double
v1
=
-
1.0
;
renlog
.
initialize
();
size_t
num1
=
10
;
std
::
vector
<
Kernel
::
DateAndTime
>
rawtimes
;
std
::
vector
<
double
>
rawvalues
;
for
(
size_t
i
=
0
;
i
<
num1
;
i
++
){
TS_ASSERT_THROWS_NOTHING
(
renlog
.
setPropertyValue
(
"Workspace"
,
"TestDummy"
));
Kernel
::
DateAndTime
time
(
t1_ns
);
TS_ASSERT_THROWS_NOTHING
(
renlog
.
setProperty
(
"OriginalLogName"
,
"OriginalLog"
)
);
p1
->
addValue
(
ti
me
,
v1
);
TS_ASSERT_THROWS_NOTHING
(
renlog
.
setProperty
(
"NewLogNa
me
"
,
"NewLog"
)
);
rawtimes
.
push_back
(
time
);
renlog
.
execute
(
);
rawvalues
.
push_back
(
v1
);
TS_ASSERT
(
renlog
.
isExecuted
()
);
t1_ns
+=
dt_ns
;
// 4. Check
v1
=
-
v1
;
API
::
MatrixWorkspace_sptr
resultWS
=
AnalysisDataService
::
Instance
().
retrieveWS
<
API
::
MatrixWorkspace
>
(
"TestDummy"
);
}
verifyLog
(
resultWS
,
"NewLog"
);
}
mWS
->
mutableRun
().
addProperty
(
p1
);
// 2. Add workspace to data serive
void
test_RenameCloned
()
AnalysisDataService
::
Instance
().
addOrReplace
(
"TestDummy"
,
mWS
);
{
API
::
MatrixWorkspace_sptr
testWS
=
generateTestWorkspace
();
API
::
MatrixWorkspace_sptr
clonedWS
=
WorkspaceFactory
::
Instance
().
create
(
testWS
);
AnalysisDataService
::
Instance
().
addOrReplace
(
"TestDummy"
,
testWS
);
AnalysisDataService
::
Instance
().
addOrReplace
(
"TestClonedDummy"
,
clonedWS
);
// 3. Running
RenameLog
renlog
;
RenameLog
renlog
;
renlog
.
initialize
();
renlog
.
initialize
();
...
@@ -73,23 +74,69 @@ public:
...
@@ -73,23 +74,69 @@ public:
renlog
.
execute
();
renlog
.
execute
();
TS_ASSERT
(
renlog
.
isExecuted
());
TS_ASSERT
(
renlog
.
isExecuted
());
// 4. Check
// Verify modified logs on original workspace
API
::
MatrixWorkspace_sptr
rWS
=
AnalysisDataService
::
Instance
().
retrieveWS
<
API
::
MatrixWorkspace
>
(
"TestDummy"
);
API
::
MatrixWorkspace_sptr
resultWS
=
AnalysisDataService
::
Instance
().
retrieveWS
<
API
::
MatrixWorkspace
>
(
"TestDummy"
);
verifyLog
(
resultWS
,
"NewLog"
);
// Verify original logs on cloned workspace
resultWS
=
AnalysisDataService
::
Instance
().
retrieveWS
<
API
::
MatrixWorkspace
>
(
"TestClonedDummy"
);
verifyLog
(
resultWS
,
"OriginalLog"
);
}
private
:
API
::
MatrixWorkspace_sptr
generateTestWorkspace
()
{
API
::
MatrixWorkspace_sptr
testWS
=
API
::
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
1
,
100
,
100
);
Kernel
::
TimeSeriesProperty
<
double
>
*
p1
=
new
Kernel
::
TimeSeriesProperty
<
double
>
(
"OriginalLog"
);
int64_t
t1_ns
=
1000000
;
int64_t
dt_ns
=
400
;
double
v1
=
-
1.0
;
m_num1
=
10
;
m_rawTimes
.
clear
();
m_rawValues
.
clear
();
for
(
size_t
i
=
0
;
i
<
m_num1
;
i
++
)
{
Kernel
::
DateAndTime
time
(
t1_ns
);
p1
->
addValue
(
time
,
v1
);
m_rawTimes
.
push_back
(
time
);
m_rawValues
.
push_back
(
v1
);
t1_ns
+=
dt_ns
;
v1
=
-
v1
;
}
testWS
->
mutableRun
().
addProperty
(
p1
);
return
testWS
;
}
void
verifyLog
(
API
::
MatrixWorkspace_sptr
resultWS
,
const
std
::
string
logName
)
{
Kernel
::
TimeSeriesProperty
<
double
>
*
rp
;
Kernel
::
TimeSeriesProperty
<
double
>
*
rp
;
TS_ASSERT_THROWS_NOTHING
(
rp
=
dynamic_cast
<
Kernel
::
TimeSeriesProperty
<
double
>*
>
(
rWS
->
run
().
getProperty
(
"NewLog"
)));
TS_ASSERT_THROWS_NOTHING
(
rp
=
dynamic_cast
<
Kernel
::
TimeSeriesProperty
<
double
>*
>
(
r
esult
WS
->
run
().
getProperty
(
logName
)));
rp
=
dynamic_cast
<
Kernel
::
TimeSeriesProperty
<
double
>*
>
(
rWS
->
run
().
getProperty
(
"NewLog"
));
rp
=
dynamic_cast
<
Kernel
::
TimeSeriesProperty
<
double
>*
>
(
r
esult
WS
->
run
().
getProperty
(
logName
));
std
::
vector
<
Kernel
::
DateAndTime
>
newtimes
=
rp
->
timesAsVector
();
std
::
vector
<
Kernel
::
DateAndTime
>
newtimes
=
rp
->
timesAsVector
();
TS_ASSERT_EQUALS
(
newtimes
.
size
(),
num1
);
TS_ASSERT_EQUALS
(
newtimes
.
size
(),
m_num1
);
for
(
size_t
i
=
0
;
i
<
num1
;
i
++
){
for
(
size_t
i
=
0
;
i
<
m_num1
;
i
++
)
{
double
newvalue
;
double
newvalue
;
TS_ASSERT_THROWS_NOTHING
(
newvalue
=
rp
->
getSingleValue
(
raw
t
imes
[
i
]));
TS_ASSERT_THROWS_NOTHING
(
newvalue
=
rp
->
getSingleValue
(
m_
raw
T
imes
[
i
]));
newvalue
=
rp
->
getSingleValue
(
raw
t
imes
[
i
]);
newvalue
=
rp
->
getSingleValue
(
m_
raw
T
imes
[
i
]);
TS_ASSERT_DELTA
(
newvalue
,
raw
v
alues
[
i
],
1.0E-8
);
TS_ASSERT_DELTA
(
newvalue
,
m_
raw
V
alues
[
i
],
1.0E-8
);
}
}
}
}
size_t
m_num1
;
std
::
vector
<
Kernel
::
DateAndTime
>
m_rawTimes
;
std
::
vector
<
double
>
m_rawValues
;
};
};
...
...
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