|
13 | 13 | #include "MantidAlgorithms/Minus.h"
|
14 | 14 | #include "MantidAlgorithms/Plus.h"
|
15 | 15 | #include "MantidAlgorithms/Rebin.h"
|
| 16 | +#include "MantidHistogramData/HistogramBuilder.h" |
16 | 17 | #include "MantidAPI/AnalysisDataService.h"
|
17 | 18 | #include "MantidDataObjects/Workspace2D.h"
|
18 | 19 | #include "MantidAPI/WorkspaceProperty.h"
|
@@ -597,8 +598,12 @@ class @PLUSMINUSTEST_CLASS@ : public CxxTest::TestSuite
|
597 | 598 | mess << "Event";
|
598 | 599 | else
|
599 | 600 | mess << "2D";
|
600 |
| - mess << "(" << ws->getNumberHistograms() << " spectra," << ws->blocksize() << " bins,"; |
601 |
| - mess << "Y[0][0] = " << ws->y(0)[0] << ")"; |
| 601 | + mess << "(" << ws->getNumberHistograms() << " spectra, "; |
| 602 | + if (ws->isRaggedWorkspace()) |
| 603 | + mess << "Ragged"; |
| 604 | + else |
| 605 | + mess << ws->blocksize(); |
| 606 | + mess << " bins," << "Y[0][0] = " << ws->y(0)[0] << ")"; |
602 | 607 | return mess.str();
|
603 | 608 | }
|
604 | 609 |
|
@@ -784,11 +789,19 @@ class @PLUSMINUSTEST_CLASS@ : public CxxTest::TestSuite
|
784 | 789 | int loopOrientation, double expectedValue=-1.0, double expectedError=-1.0 )
|
785 | 790 | {
|
786 | 791 | TSM_ASSERT_LESS_THAN( message, 0, work_out1->getNumberHistograms());
|
787 |
| - TSM_ASSERT_LESS_THAN( message, 0, work_out1->blocksize()); |
| 792 | + if (work_out1->isRaggedWorkspace()) { |
| 793 | + TSM_ASSERT_LESS_THAN( message, 0, work_out1->y(0).size()); |
| 794 | + } else { |
| 795 | + TSM_ASSERT_LESS_THAN( message, 0, work_out1->blocksize()); |
| 796 | + } |
788 | 797 | TSM_ASSERT_EQUALS( message, work_in1->getNumberHistograms(), work_out1->getNumberHistograms());
|
789 | 798 | // Number of histograms/bins is unchanged (relative to LHS argument)
|
790 | 799 | TSM_ASSERT_EQUALS( message, work_out1->getNumberHistograms(), work_in1->getNumberHistograms());
|
791 |
| - TSM_ASSERT_EQUALS( message, work_out1->blocksize(), work_in1->blocksize()); |
| 800 | + if (work_out1->isRaggedWorkspace()) { |
| 801 | + TSM_ASSERT_EQUALS( message, work_out1->y(0).size(), work_in1->y(0).size()); |
| 802 | + } else { |
| 803 | + TSM_ASSERT_EQUALS( message, work_out1->blocksize(), work_in1->blocksize()); |
| 804 | + } |
792 | 805 |
|
793 | 806 | if (expectedValue == -1.0 && expectedError == -1.0)
|
794 | 807 | {
|
@@ -1081,6 +1094,62 @@ class @PLUSMINUSTEST_CLASS@ : public CxxTest::TestSuite
|
1081 | 1094 | }
|
1082 | 1095 |
|
1083 | 1096 |
|
| 1097 | + MatrixWorkspace_sptr create_RaggedWorkspace() |
| 1098 | + { |
| 1099 | + // create workspace with 2 histograms |
| 1100 | + MatrixWorkspace_sptr raggedWS = WorkspaceCreationHelper::create2DWorkspace(2, 1); |
| 1101 | + |
| 1102 | + // create and replace histograms with ragged ones |
| 1103 | + MantidVec x_data{100., 200., 300., 400.}; |
| 1104 | + MantidVec y_data{1., 1., 1.}; |
| 1105 | + MantidVec e_data{1., 1., 1.}; |
| 1106 | + Mantid::HistogramData::HistogramBuilder builder; |
| 1107 | + builder.setX(x_data); |
| 1108 | + builder.setY(y_data); |
| 1109 | + builder.setE(e_data); |
| 1110 | + raggedWS->setHistogram(0, builder.build()); |
| 1111 | + |
| 1112 | + MantidVec x_data2{200., 400., 600.}; |
| 1113 | + MantidVec y_data2{1., 1.}; |
| 1114 | + MantidVec e_data2{1., 1.}; |
| 1115 | + Mantid::HistogramData::HistogramBuilder builder2; |
| 1116 | + builder2.setX(x_data2); |
| 1117 | + builder2.setY(y_data2); |
| 1118 | + builder2.setE(e_data2); |
| 1119 | + raggedWS->setHistogram(1, builder2.build()); |
| 1120 | + |
| 1121 | + // quick check of the workspace |
| 1122 | + TS_ASSERT(raggedWS->isRaggedWorkspace()); |
| 1123 | + TS_ASSERT_EQUALS(raggedWS->getNumberHistograms(), 2); |
| 1124 | + TS_ASSERT_EQUALS(raggedWS->x(0).size(), 4); |
| 1125 | + TS_ASSERT_EQUALS(raggedWS->x(1).size(), 3); |
| 1126 | + TS_ASSERT_EQUALS(raggedWS->y(0).size(), 3); |
| 1127 | + TS_ASSERT_EQUALS(raggedWS->y(1).size(), 2); |
| 1128 | + return raggedWS; |
| 1129 | + } |
| 1130 | + |
| 1131 | + void test_RaggedWorkspace() |
| 1132 | + { |
| 1133 | + auto lhs = create_RaggedWorkspace(); |
| 1134 | + auto rhs = create_RaggedWorkspace(); |
| 1135 | + auto result = performTest(lhs, rhs, false, false, DO_PLUS ? 2.0 : 0.0, 1.4142135625); |
| 1136 | + TS_ASSERT(result->isRaggedWorkspace()); |
| 1137 | + } |
| 1138 | + |
| 1139 | + void test_RaggedWorkspace_and_single_value() |
| 1140 | + { |
| 1141 | + auto lhs = create_RaggedWorkspace(); |
| 1142 | + auto rhs = WorkspaceCreationHelper::createWorkspaceSingleValue(2); |
| 1143 | + auto result = performTest(lhs, rhs, false, false, DO_PLUS ? 3.0 : -1.0, 1.7320508071); |
| 1144 | + TS_ASSERT(result->isRaggedWorkspace()); |
| 1145 | + } |
| 1146 | + |
| 1147 | + void test_RaggedWorkspace_not_compatible_x() |
| 1148 | + { |
| 1149 | + auto lhs = create_RaggedWorkspace(); |
| 1150 | + auto rhs = WorkspaceCreationHelper::create2DWorkspace(2, 4); |
| 1151 | + performTest_fails(lhs, rhs); |
| 1152 | + } |
1084 | 1153 |
|
1085 | 1154 | }; // end of class @PLUSMINUSTEST_CLASS@
|
1086 | 1155 |
|
|
0 commit comments