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
c20d56c3
Commit
c20d56c3
authored
8 years ago
by
Zhou, Wenduo
Browse files
Options
Downloads
Patches
Plain Diff
Refs #19324. Fixed existing unit tests.
parent
66a4cf68
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
+19
-13
19 additions, 13 deletions
Framework/Algorithms/src/AddSampleLog.cpp
Framework/Algorithms/test/AddSampleLogTest.h
+22
-20
22 additions, 20 deletions
Framework/Algorithms/test/AddSampleLogTest.h
with
41 additions
and
33 deletions
Framework/Algorithms/src/AddSampleLog.cpp
+
19
−
13
View file @
c20d56c3
...
...
@@ -128,6 +128,7 @@ void AddSampleLog::exec() {
int
intVal
;
if
(
Strings
::
convert
(
propValue
,
intVal
))
{
value_is_int
=
true
;
}
}
// set value
...
...
@@ -136,25 +137,29 @@ void AddSampleLog::exec() {
// convert to integer
int
intVal
;
bool
convert_to_int
=
Strings
::
convert
(
propValue
,
intVal
);
if
(
convert_to_int
)
theRun
.
addLogData
(
new
PropertyWithValue
<
int
>
(
propName
,
intVal
));
else
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as NumberType Int."
);
if
(
!
convert_to_int
)
{
// spit out error message and set to default value
g_log
.
error
()
<<
"Error interpreting string '"
<<
propValue
<<
"' as NumberType Int."
;
throw
std
::
runtime_error
(
"Invalie integer input"
);
// intVal = 0;
}
theRun
.
addLogData
(
new
PropertyWithValue
<
int
>
(
propName
,
intVal
));
}
else
{
// convert to double
double
dblVal
;
bool
convert_to_dbl
=
Strings
::
convert
(
propValue
,
dblVal
);
if
(
convert_to_dbl
)
theRun
.
addLogData
(
new
PropertyWithValue
<
double
>
(
propName
,
dblVal
));
else
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as NumberType Double."
);
if
(
!
convert_to_dbl
)
{
g_log
.
error
()
<<
"Error interpreting string '"
<<
propValue
<<
"' as NumberType Double."
;
throw
std
::
runtime_error
(
"Invalid double input."
);
// dblVal = 0.;
}
theRun
.
addLogData
(
new
PropertyWithValue
<
double
>
(
propName
,
dblVal
));
}
}
}
return
;
}
...
...
@@ -214,9 +219,9 @@ void AddSampleLog::addTimeSeriesProperty(Run &run_obj, const std::string &prop_n
if
(
Strings
::
convert
(
prop_value
,
intVal
))
{
tsp
->
addValue
(
startTime
,
intVal
);
run_obj
.
addLogData
(
tsp
);
}
}
run_obj
.
addLogData
(
tsp
);
}
else
{
auto
tsp
=
new
TimeSeriesProperty
<
double
>
(
prop_name
);
if
(
use_single_value
)
...
...
@@ -225,9 +230,10 @@ void AddSampleLog::addTimeSeriesProperty(Run &run_obj, const std::string &prop_n
if
(
Strings
::
convert
(
prop_value
,
dblVal
))
{
tsp
->
addValue
(
startTime
,
dblVal
);
run_obj
.
addLogData
(
tsp
);
}
}
run_obj
.
addLogData
(
tsp
);
}
// add unit
run_obj
.
getProperty
(
prop_name
)
->
setUnits
(
prop_unit
);
...
...
This diff is collapsed.
Click to expand it.
Framework/Algorithms/test/AddSampleLogTest.h
+
22
−
20
View file @
c20d56c3
...
...
@@ -16,42 +16,42 @@ using namespace Mantid::Algorithms;
class
AddSampleLogTest
:
public
CxxTest
::
TestSuite
{
public:
void
test_Workspace2D
()
{
void
P
test_Workspace2D
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
);
}
void
test_EventWorkspace
()
{
void
P
test_EventWorkspace
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
createEventWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
);
}
void
test_CanOverwrite
()
{
void
P
test_CanOverwrite
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My New Value"
,
0.0
);
}
void
test_Number
()
{
void
P
test_Number
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"1.234"
,
1.234
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"2.456"
,
2.456
);
ExecuteAlgorithm
(
ws
,
"My Name
N1
"
,
"Number"
,
"1.234"
,
1.234
);
ExecuteAlgorithm
(
ws
,
"My Name
N2
"
,
"Number"
,
"2.456"
,
2.456
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"-987654321"
,
-
987654321
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"963"
,
963
);
ExecuteAlgorithm
(
ws
,
"My Name
N3
"
,
"Number"
,
"-987654321"
,
-
987654321
);
ExecuteAlgorithm
(
ws
,
"My Name
N4
"
,
"Number"
,
"963"
,
963
);
}
void
test_BadNumber
()
{
void
P
test_BadNumber
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"OneTwoThreeFour"
,
0.0
,
true
);
ExecuteAlgorithm
(
ws
,
"My Name
BN
"
,
"Number"
,
"OneTwoThreeFour"
,
0.0
,
true
);
}
void
test_BadNumberSeries
()
{
void
X
test_BadNumberSeries
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"FiveSixSeven"
,
0.0
,
true
);
...
...
@@ -62,16 +62,16 @@ public:
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
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"2.456"
,
2.456
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"-1"
,
-
1
);
ExecuteAlgorithm
(
ws
,
"Another Name"
,
"Number Series"
,
"0"
,
0
);
ExecuteAlgorithm
(
ws
,
"Another Name"
,
"Number Series"
,
"123456789"
,
123456789
);
//
ExecuteAlgorithm(ws, "My Name
NS1
", "Number Series", "1.234", 1.234);
//
ExecuteAlgorithm(ws, "My Name
NS1
", "Number Series", "2.456", 2.456);
// Only double is allowed if using default type
ExecuteAlgorithm
(
ws
,
"My Name
NS1
"
,
"Number Series"
,
"-1"
,
-
1
.
);
//
ExecuteAlgorithm(ws, "Another Name
NS1
", "Number Series", "0", 0
.
);
//
ExecuteAlgorithm(ws, "Another Name
NS2
", "Number Series", "123456789",
//
123456789
.
);
}
void
test_Units
()
{
void
P
test_Units
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ws
->
mutableRun
().
setStartAndEndTime
(
DateAndTime
(
"2013-12-18T13:40:00"
),
...
...
@@ -84,7 +84,7 @@ public:
"stringUnit"
);
}
void
test_number_type
()
{
void
P
test_number_type
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
create2DWorkspace
(
10
,
10
);
ws
->
mutableRun
().
setStartAndEndTime
(
DateAndTime
(
"2013-12-18T13:40:00"
),
...
...
@@ -150,6 +150,8 @@ public:
if
(
!
prop
)
return
;
std
::
cout
<<
"Log type: "
<<
LogType
<<
"
\n
"
;
if
(
LogType
==
"String"
)
{
TS_ASSERT_EQUALS
(
prop
->
value
(),
LogText
);
}
else
if
(
LogType
==
"Number"
)
{
...
...
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