@@ -32,12 +32,15 @@ class RemovePromptPulseTest : public CxxTest::TestSuite {
32
32
std::string inWSName;
33
33
std::string outWSName;
34
34
35
- void makeFakeEventWorkspace (const std::string &wsName) {
35
+ void makeFakeEventWorkspace (const std::string &wsName, int shift = 0 ) {
36
36
// Make an event workspace with 2 events in each bin.
37
37
EventWorkspace_sptr test_in =
38
38
WorkspaceCreationHelper::createEventWorkspace (NUMPIXELS, NUMBINS, NUMEVENTS, 1000 ., BIN_DELTA, 2 );
39
39
// Fake a TOF unit in the data.
40
40
test_in->getAxis (0 )->unit () = UnitFactory::Instance ().create (" TOF" );
41
+ for (size_t i = 0 ; i < test_in->dataX (0 ).size (); ++i) {
42
+ test_in->dataX (0 )[i] += shift;
43
+ }
41
44
test_in->setInstrument (ComponentCreationHelper::createTestInstrumentCylindrical (NUMPIXELS / 9 ));
42
45
// Make sure the detector IDs are ok
43
46
for (int i = 0 ; i < NUMPIXELS; i++)
@@ -92,14 +95,16 @@ class RemovePromptPulseTest : public CxxTest::TestSuite {
92
95
return ;
93
96
94
97
// Verify the results
95
- // drop events 36 spectra, 2 events/bin, 10 bins/pulse, 9 pulses
96
- TS_ASSERT_EQUALS (num_events - 36 * 2 * 10 * 9 , ws->getNumberEvents ());
98
+ // drop events 36 spectra, 2 events/bin, 10 bins/pulse, 10 pulses
99
+ TS_ASSERT_EQUALS (num_events - 36 * 2 * 10 * 10 , ws->getNumberEvents ());
100
+
101
+ std::cout << " num_events = " << ws->getNumberEvents () << std::endl;
97
102
98
103
AnalysisDataService::Instance ().remove (inWSName);
99
104
AnalysisDataService::Instance ().remove (outWSName);
100
105
}
101
106
102
- void test_exec_hit () {
107
+ void test_exec_hit_tmin () {
103
108
inWSName = " RemovePromptPulseTest_InputWS_hit" ;
104
109
outWSName = inWSName; // "RemovePromptPulseTest_OutputWS_hit";
105
110
this ->makeFakeEventWorkspace (inWSName);
@@ -131,4 +136,72 @@ class RemovePromptPulseTest : public CxxTest::TestSuite {
131
136
// Clean up
132
137
AnalysisDataService::Instance ().remove (inWSName);
133
138
}
139
+
140
+ void test_exec_miss_tmin () {
141
+ inWSName = " RemovePromptPulseTest_InputWS_miss_tmin" ;
142
+ outWSName = " RemovePromptPulseTest_OutputWS_miss_tmin" ;
143
+ this ->makeFakeEventWorkspace (inWSName, -1100 );
144
+
145
+ EventWorkspace_sptr ws;
146
+ TS_ASSERT_THROWS_NOTHING (ws = AnalysisDataService::Instance ().retrieveWS <EventWorkspace>(inWSName));
147
+ std::size_t num_events = ws->getNumberEvents ();
148
+ RemovePromptPulse alg;
149
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ())
150
+ TS_ASSERT (alg.isInitialized ())
151
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" InputWorkspace" , inWSName));
152
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" OutputWorkspace" , outWSName));
153
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" Width" , " 1000." ));
154
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" Frequency" , " 100" ));
155
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" TMin" , " -100" ));
156
+
157
+ TS_ASSERT_THROWS_NOTHING (alg.execute (););
158
+ TS_ASSERT (alg.isExecuted ());
159
+
160
+ // Retrieve the workspace from data service.
161
+ TS_ASSERT_THROWS_NOTHING (ws = AnalysisDataService::Instance ().retrieveWS <EventWorkspace>(outWSName));
162
+ TS_ASSERT (ws);
163
+ if (!ws)
164
+ return ;
165
+
166
+ // Verify the results
167
+ // drop events 36 spectra, 2 events/bin, 10 bins/pulse, 10 pulses
168
+ TS_ASSERT_EQUALS (num_events - 36 * 2 * 10 * 10 , ws->getNumberEvents ());
169
+
170
+ AnalysisDataService::Instance ().remove (inWSName);
171
+ AnalysisDataService::Instance ().remove (outWSName);
172
+ }
173
+
174
+ void test_exec_hit_negative_tmin () {
175
+ inWSName = " RemovePromptPulseTest_InputWS_tmin" ;
176
+ outWSName = inWSName;
177
+ this ->makeFakeEventWorkspace (inWSName, -1100 );
178
+
179
+ EventWorkspace_sptr ws;
180
+ TS_ASSERT_THROWS_NOTHING (ws = AnalysisDataService::Instance ().retrieveWS <EventWorkspace>(inWSName));
181
+ std::size_t num_events = ws->getNumberEvents ();
182
+
183
+ RemovePromptPulse alg;
184
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ())
185
+ TS_ASSERT (alg.isInitialized ())
186
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" InputWorkspace" , inWSName));
187
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" OutputWorkspace" , outWSName));
188
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" Width" , " 1000." ));
189
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" Frequency" , " 200" ));
190
+ TS_ASSERT_THROWS_NOTHING (alg.setPropertyValue (" TMin" , " -100" ));
191
+
192
+ TS_ASSERT_THROWS_NOTHING (alg.execute (););
193
+ TS_ASSERT (alg.isExecuted ());
194
+
195
+ // Retrieve the workspace from data service. TODO: Change to your desired
196
+ // type
197
+ TS_ASSERT_THROWS_NOTHING (ws = AnalysisDataService::Instance ().retrieveWS <EventWorkspace>(outWSName));
198
+ TS_ASSERT (ws);
199
+ if (!ws)
200
+ return ;
201
+
202
+ // Verify the results
203
+ TS_ASSERT (num_events > ws->getNumberEvents ()); // should drop events
204
+ // Clean up
205
+ AnalysisDataService::Instance ().remove (inWSName);
206
+ }
134
207
};
0 commit comments