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
66388159
Commit
66388159
authored
9 years ago
by
Matthew D Jones
Browse files
Options
Downloads
Patches
Plain Diff
Re #14178 Fixed logic and added tests
parent
15c7a2f2
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
Framework/Algorithms/src/AddSampleLog.cpp
+30
-12
30 additions, 12 deletions
Framework/Algorithms/src/AddSampleLog.cpp
Framework/Algorithms/test/AddSampleLogTest.h
+29
-1
29 additions, 1 deletion
Framework/Algorithms/test/AddSampleLogTest.h
with
59 additions
and
13 deletions
Framework/Algorithms/src/AddSampleLog.cpp
+
30
−
12
View file @
66388159
...
@@ -41,9 +41,11 @@ void AddSampleLog::init() {
...
@@ -41,9 +41,11 @@ void AddSampleLog::init() {
std
::
vector
<
std
::
string
>
typeOptions
;
std
::
vector
<
std
::
string
>
typeOptions
;
typeOptions
.
push_back
(
"Int"
);
typeOptions
.
push_back
(
"Int"
);
typeOptions
.
push_back
(
"Double"
);
typeOptions
.
push_back
(
"Double"
);
declareProperty
(
"NumberType"
,
"String"
,
typeOptions
.
push_back
(
""
);
declareProperty
(
"NumberType"
,
""
,
boost
::
make_shared
<
StringListValidator
>
(
typeOptions
),
boost
::
make_shared
<
StringListValidator
>
(
typeOptions
),
"Force LogText to be interpreted as a number of type
\"
int
\"
or
\"
double
\"
."
);
"Force LogText to be interpreted as a number of type
\"
int
\"
"
"or
\"
double
\"
."
);
}
}
void
AddSampleLog
::
exec
()
{
void
AddSampleLog
::
exec
()
{
...
@@ -60,8 +62,10 @@ void AddSampleLog::exec() {
...
@@ -60,8 +62,10 @@ void AddSampleLog::exec() {
std
::
string
propType
=
getPropertyValue
(
"LogType"
);
std
::
string
propType
=
getPropertyValue
(
"LogType"
);
std
::
string
propNumberType
=
getPropertyValue
(
"NumberType"
);
std
::
string
propNumberType
=
getPropertyValue
(
"NumberType"
);
if
(
!
propNumberType
.
empty
()
&&
(
propType
!=
"Number"
))
{
if
(
!
propNumberType
.
empty
()
&&
throw
std
::
invalid_argument
(
"You may only use NumberType property if LogType is
\"
Number
\"
"
);
((
propType
!=
"Number"
)
&&
(
propType
!=
"Number Series"
)))
{
throw
std
::
invalid_argument
(
"You may only use NumberType property if "
"LogType is 'Number' or 'Number Series'"
);
}
}
// Remove any existing log
// Remove any existing log
...
@@ -75,18 +79,32 @@ void AddSampleLog::exec() {
...
@@ -75,18 +79,32 @@ void AddSampleLog::exec() {
return
;
return
;
}
}
bool
valueIsInt
(
false
);
int
intVal
;
int
intVal
;
double
dblVal
;
double
dblVal
;
if
(
Strings
::
convert
(
propValue
,
intVal
))
{
bool
value_is_int
=
false
;
valueIsInt
=
true
;
}
else
if
(
!
Strings
::
convert
(
propValue
,
dblVal
))
{
if
(
!
propNumberType
.
empty
())
{
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
value_is_int
=
(
propNumberType
==
"Int"
);
"' as a number."
);
if
(
value_is_int
)
{
if
(
!
Strings
::
convert
(
propValue
,
intVal
))
{
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as NumberType Int."
);
}
}
else
if
(
!
Strings
::
convert
(
propValue
,
dblVal
))
{
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as NumberType Double."
);
}
}
else
{
if
(
Strings
::
convert
(
propValue
,
intVal
))
{
value_is_int
=
true
;
}
else
if
(
!
Strings
::
convert
(
propValue
,
dblVal
))
{
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as a number."
);
}
}
}
if
(
propType
==
"Number"
)
{
if
(
propType
==
"Number"
)
{
if
(
value
IsI
nt
)
if
(
value
_is_i
nt
)
theRun
.
addLogData
(
new
PropertyWithValue
<
int
>
(
propName
,
intVal
));
theRun
.
addLogData
(
new
PropertyWithValue
<
int
>
(
propName
,
intVal
));
else
else
theRun
.
addLogData
(
new
PropertyWithValue
<
double
>
(
propName
,
dblVal
));
theRun
.
addLogData
(
new
PropertyWithValue
<
double
>
(
propName
,
dblVal
));
...
@@ -98,7 +116,7 @@ void AddSampleLog::exec() {
...
@@ -98,7 +116,7 @@ void AddSampleLog::exec() {
// Swallow the error - startTime will just be 0
// Swallow the error - startTime will just be 0
}
}
if
(
value
IsI
nt
)
{
if
(
value
_is_i
nt
)
{
auto
tsp
=
new
TimeSeriesProperty
<
int
>
(
propName
);
auto
tsp
=
new
TimeSeriesProperty
<
int
>
(
propName
);
tsp
->
addValue
(
startTime
,
intVal
);
tsp
->
addValue
(
startTime
,
intVal
);
theRun
.
addLogData
(
tsp
);
theRun
.
addLogData
(
tsp
);
...
...
This diff is collapsed.
Click to expand it.
Framework/Algorithms/test/AddSampleLogTest.h
+
29
−
1
View file @
66388159
...
@@ -84,11 +84,32 @@ public:
...
@@ -84,11 +84,32 @@ public:
"stringUnit"
);
"stringUnit"
);
}
}
void
test_number_type
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ws
->
mutableRun
().
setStartAndEndTime
(
DateAndTime
(
"2013-12-18T13:40:00"
),
DateAndTime
(
"2013-12-18T13:42:00"
));
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"1.234"
,
1.234
,
false
,
"myUnit"
,
"Double"
);
ExecuteAlgorithm
(
ws
,
"My New Name"
,
"Number"
,
"963"
,
963
,
false
,
"differentUnit"
,
"Int"
);
// Can force '963' to be interpreted as a double
ExecuteAlgorithm
(
ws
,
"My New Name"
,
"Number"
,
"963"
,
963.0
,
false
,
"differentUnit"
,
"Double"
);
// Should throw error as NumberType defined for a String
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
,
true
,
"stringUnit"
,
"Double"
,
true
);
// Should throw error trying to interpret '1.234' as Int
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"1.234"
,
1.234
,
true
,
"myUnit"
,
"Int"
,
true
);
}
template
<
typename
T
>
template
<
typename
T
>
void
ExecuteAlgorithm
(
MatrixWorkspace_sptr
testWS
,
std
::
string
LogName
,
void
ExecuteAlgorithm
(
MatrixWorkspace_sptr
testWS
,
std
::
string
LogName
,
std
::
string
LogType
,
std
::
string
LogText
,
std
::
string
LogType
,
std
::
string
LogText
,
T
expectedValue
,
bool
fails
=
false
,
T
expectedValue
,
bool
fails
=
false
,
std
::
string
LogUnit
=
""
)
{
std
::
string
LogUnit
=
""
,
std
::
string
NumberType
=
""
,
bool
throws
=
false
)
{
// add the workspace to the ADS
// add the workspace to the ADS
AnalysisDataService
::
Instance
().
addOrReplace
(
"AddSampleLogTest_Temporary"
,
AnalysisDataService
::
Instance
().
addOrReplace
(
"AddSampleLogTest_Temporary"
,
testWS
);
testWS
);
...
@@ -96,6 +117,8 @@ public:
...
@@ -96,6 +117,8 @@ public:
// execute algorithm
// execute algorithm
AddSampleLog
alg
;
AddSampleLog
alg
;
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
());
TS_ASSERT_THROWS_NOTHING
(
alg
.
initialize
());
if
(
throws
)
alg
.
setRethrows
(
true
);
TS_ASSERT
(
alg
.
isInitialized
())
TS_ASSERT
(
alg
.
isInitialized
())
alg
.
setPropertyValue
(
"Workspace"
,
"AddSampleLogTest_Temporary"
);
alg
.
setPropertyValue
(
"Workspace"
,
"AddSampleLogTest_Temporary"
);
...
@@ -103,6 +126,11 @@ public:
...
@@ -103,6 +126,11 @@ public:
alg
.
setPropertyValue
(
"LogText"
,
LogText
);
alg
.
setPropertyValue
(
"LogText"
,
LogText
);
alg
.
setPropertyValue
(
"LogUnit"
,
LogUnit
);
alg
.
setPropertyValue
(
"LogUnit"
,
LogUnit
);
alg
.
setPropertyValue
(
"LogType"
,
LogType
);
alg
.
setPropertyValue
(
"LogType"
,
LogType
);
alg
.
setPropertyValue
(
"NumberType"
,
NumberType
);
if
(
throws
)
{
TS_ASSERT_THROWS_ANYTHING
(
alg
.
execute
())
return
;
}
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
())
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
())
if
(
fails
)
{
if
(
fails
)
{
TS_ASSERT
(
!
alg
.
isExecuted
())
TS_ASSERT
(
!
alg
.
isExecuted
())
...
...
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