99 Figure
1010 % Handle to trial conditions UI Table
1111 Table
12+ % Test parameter structure
13+ Parameters
1214 end
1315
14- properties % (MethodSetupParameter)
15- Parameters
16+ properties (SetAccess = private )
17+ % Flag set to true each time the ParamEditor's Changed event is
18+ % notified
19+ Changed = false
1620 end
1721
1822 methods (TestClassSetup )
@@ -21,7 +25,7 @@ function setup(testCase)
2125 testCase.FigureVisibleDefault = get(0 ,' DefaultFigureVisible' );
2226% set(0,'DefaultFigureVisible','off');
2327 testCase .addTeardown(@set , 0 , ' DefaultFigureVisible' , testCase .FigureVisibleDefault );
24-
28+
2529 % Loads validation data
2630 % Graph data is a cell array where each element is the graph number
2731 % (1:3) and within each element is a cell of X- and Y- axis values
@@ -59,6 +63,13 @@ function buildParams(testCase)
5963 % Ensure all conditional params have column in table
6064 testCase .fatalAssertTrue(isequal(size(testCase .Table .Data ), ...
6165 [PE .Parameters .numTrialConditions , numel(PE .Parameters .TrialSpecificNames )]))
66+ % Add callback for verifying that Changed event listeners are
67+ % notified
68+ callback = @(~,~)testCase .setChanged(true );
69+ lh = event .listener(testCase .ParamEditor , ' Changed' , callback );
70+ testCase .addTeardown(@delete , lh );
71+ % Reset the Changed flag
72+ testCase.Changed = false ;
6273 end
6374 end
6475
@@ -69,6 +80,7 @@ function test_makeConditional(testCase)
6980 % conditional, and that the underlying Parameters object is also
7081 % affected
7182 PE = testCase .ParamEditor ;
83+ testCase .assertTrue(~testCase .Changed , ' Changed flag incorrect' )
7284 % Number of global parameters: find all text labels
7385 gLabels = @()findobj(testCase .Figure , ' Style' , ' text' );
7486 gInputs = @()findobj(testCase .Figure , ' Style' , ' checkbox' , ' -or' , ' Style' , ' edit' );
@@ -80,9 +92,12 @@ function test_makeConditional(testCase)
8092 c = findobj(testCase .Figure , ' Text' , ' Make Conditional' );
8193 % Set the focused object to one of the parameter labels
8294 set(testCase .Figure , ' CurrentObject' , ...
83- findobj(testCase .Figure , ' String ' , ' rewardVolume' ))
95+ findobj(testCase .Figure , ' Tag ' , ' rewardVolume' ))
8496 testCase .verifyWarningFree(c .MenuSelectedFcn , ...
8597 ' Problem making parameter conditional' );
98+ % Verify Changed event triggered
99+ testCase .verifyTrue(testCase .Changed , ...
100+ ' Failed to notify listeners of parameter change' )
86101 % Verify change in UI elements
87102 testCase .verifyTrue(numel(gLabels()) == nGlobalLabels - 1 , ...
88103 ' Global parameter UI element not removed' )
@@ -152,15 +167,17 @@ function test_paramValue2Control(testCase)
152167
153168 function test_newCondition(testCase )
154169 PE = testCase .ParamEditor ;
155-
156170 tableRows = size(testCase .Table .Data , 1 );
157171
158172 % Make function handle param conditional to test default value
159173 % Set the focused object to one of the parameter labels
160174 set(testCase .Figure , ' CurrentObject' , ...
161- findobj(testCase .Figure , ' String ' , ' experimentFun' ))
175+ findobj(testCase .Figure , ' Tag ' , ' experimentFun' ))
162176 feval(pick(findobj(testCase .Figure , ' Text' , ' Make Conditional' ), ' MenuSelectedFcn' ))
163177
178+ % Reset Changed flag
179+ testCase.Changed = false ;
180+
164181 % Retrieve function handle for new condition
165182 fn = pick(findobj(testCase .Figure , ' String' , ' New condition' ), ' Callback' );
166183 testCase .verifyWarningFree(fn , ' Warning encountered adding trial condition' )
@@ -177,11 +194,15 @@ function test_newCondition(testCase)
177194 [~ , trialParams ] = PE .Parameters .assortForExperiment ;
178195 testCase .verifyTrue(isequal(struct2cell(trialParams(end )), ...
179196 {@nop ; zeros(2 ,1 ); zeros(3 ,1 ); false ; 0 }))
197+
198+ % Verify listeners WEREN'T notified
199+ testCase .verifyTrue(~testCase .Changed , ...
200+ ' Shouldn'' t have notified listeners of parameter change' )
180201 end
181202
182203 function test_deleteCondition(testCase )
183204 PE = testCase .ParamEditor ;
184-
205+ testCase .assertTrue(~ testCase . Changed , ' Changed flag incorrect ' )
185206 tableRows = size(testCase .Table .Data , 1 );
186207 % Select some cells to delete
187208 event.Indices = [(1 : 5 )' ones(5 ,1 )];
@@ -200,6 +221,10 @@ function test_deleteCondition(testCase)
200221 testCase .assertEqual(size(testCase .Table .Data ), ...
201222 [PE .Parameters .numTrialConditions , numel(PE .Parameters .TrialSpecificNames )])
202223
224+ % Verify Changed event triggered
225+ testCase .verifyTrue(testCase .Changed , ...
226+ ' Failed to notify listeners of parameter change' )
227+
203228 % Test behaviour when < 2 conditions remain
204229 event.Indices = [(1 : PE .Parameters .numTrialConditions - 1 )' ...
205230 ones(PE .Parameters .numTrialConditions - 1 ,1 )];
@@ -216,13 +241,14 @@ function test_deleteCondition(testCase)
216241
217242 function test_setValues(testCase )
218243 % TODO Add test for the set values button. For now let's fail this
244+ testCase .assertTrue(~testCase .Changed , ' Changed flag incorrect' )
219245 PE = testCase .ParamEditor ;
220246 testCase .assertTrue(false , ' Test not implemented' )
221247 end
222248
223249 function test_globaliseParam(testCase )
224250 PE = testCase .ParamEditor ;
225-
251+ testCase .assertTrue(~ testCase . Changed , ' Changed flag incorrect ' )
226252 tableCols = size(testCase .Table .Data , 2 );
227253 % Globalize one param
228254 event.Indices = [1 , 2 ];
@@ -240,6 +266,10 @@ function test_globaliseParam(testCase)
240266 testCase .verifyEqual(size(testCase .Table .Data ), ...
241267 [PE .Parameters .numTrialConditions , numel(PE .Parameters .TrialSpecificNames )])
242268
269+ % Verify Changed event triggered
270+ testCase .verifyTrue(testCase .Changed , ...
271+ ' Failed to notify listeners of parameter change' )
272+
243273 % Test removal of all but numRepeats: numRepeats should automatically
244274 % globalize
245275 n = numel(PE .Parameters .TrialSpecificNames )-1 ;
@@ -280,6 +310,7 @@ function test_globaliseParam(testCase)
280310 function test_paramEdits(testCase )
281311 % Test basic edits to Global UI controls and Condition table
282312 PE = testCase .ParamEditor ;
313+ testCase .assertTrue(~testCase .Changed , ' Changed flag incorrect' )
283314
284315 % Retreive all global parameters labels and input controls
285316 gLabels = findobj(testCase .Figure , ' Style' , ' text' );
@@ -302,6 +333,10 @@ function test_paramEdits(testCase)
302333 par = strcmpi(PE .Parameters .GlobalNames , strrep(gLabels(idx ).String, ' ' , ' ' ));
303334 testCase .verifyEqual(PE .Parameters .Struct.(PE.Parameters.GlobalNames{par }), 666 , ...
304335 ' UI edit failed to update parameters struct' )
336+ % Verify Changed event triggered
337+ testCase .verifyTrue(testCase .Changed , ...
338+ ' Failed to notify listeners of parameter change' )
339+ testCase.Changed = false ;
305340
306341 % Test editing global param, 'checkbox' UI
307342 idx = find(strcmp({gInputs .Style }, ' checkbox' ), 1 );
@@ -319,6 +354,10 @@ function test_paramEdits(testCase)
319354 testCase .verifyEqual(...
320355 PE .Parameters .Struct.(PE.Parameters.GlobalNames{par }), gInputs(idx ).Value== true , ...
321356 ' UI checkbox failed to update parameters struct' )
357+ % Verify Changed event triggered
358+ testCase .verifyTrue(testCase .Changed , ...
359+ ' Failed to notify listeners of parameter change' )
360+ testCase.Changed = false ;
322361
323362 % Test edits to conditions table
324363 callback_fcn = testCase .Table .CellEditCallback ;
@@ -333,6 +372,9 @@ function test_paramEdits(testCase)
333372 value = PE .Parameters .Struct.(PE.Parameters.TrialSpecificNames{1 });
334373 testCase .verifyEqual(value(: ,1 ), [0 ;5], ...
335374 ' Table UI failed to update parameters struct' )
375+ % Verify Changed event triggered
376+ testCase .verifyTrue(testCase .Changed , ...
377+ ' Failed to notify listeners of parameter change' )
336378 end
337379
338380 function test_interactivity(testCase )
@@ -374,4 +416,10 @@ function test_interactivity(testCase)
374416
375417 end
376418
419+ methods
420+ function setChanged(testCase , value )
421+ testCase.Changed = value ;
422+ end
423+ end
424+
377425end
0 commit comments