1- classdef ParamEditor_test < matlab .unittest .TestCase
1+ classdef (SharedTestFixtures = {matlab .unittest .fixtures .PathFixture(...
2+ [fileparts(mfilename(' fullpath' )) ' \f ixtures' ])}) ... % add 'fixtures' folder as test fixture
3+ ParamEditor_test < matlab .unittest .TestCase
24
35 properties
46 % Figure visibility setting before running tests
@@ -24,19 +26,8 @@ function setup(testCase)
2426 % Hide figures and add teardown function to restore settings
2527 testCase.FigureVisibleDefault = get(0 ,' DefaultFigureVisible' );
2628 set(0 ,' DefaultFigureVisible' ,' off' );
27- testCase .addTeardown(@set , 0 , ' DefaultFigureVisible' , testCase .FigureVisibleDefault );
28-
29- % add a teardown for pre-test path:
30- % (first arg is fixture instance (i.e. environment - when to
31- % teardown (when this is out of scope)))
32- % (second arg is tearDownFcn (i.e. what to execute during teardown))
33- p = path ;
34- testCase .addTeardown(@path ,p );
35-
36- % add the the 'helpers' folder in the 'tests' folder for using the
37- % 'tests' folder's version of 'dat.paths'
38- curpath = fileparts(mfilename(' fullpath' ));
39- addpath([curpath ' \helpers' ])
29+ testCase .addTeardown(@set , 0 ,...
30+ ' DefaultFigureVisible' , testCase .FigureVisibleDefault );
4031
4132 % Loads validation data
4233 % Graph data is a cell array where each element is the graph number
@@ -45,7 +36,8 @@ function setup(testCase)
4536 testCase.Parameters = exp .choiceWorldParams ;
4637
4738 % Check paths file
48- assert(endsWith(which(' dat.paths' ), fullfile(' tests' , ' helpers' , ' +dat' , ' paths.m' )));
39+ assert(endsWith(which(' dat.paths' ),...
40+ fullfile(' tests' , ' fixtures' , ' +dat' , ' paths.m' )));
4941 % Create stand-alone panel
5042 testCase.ParamEditor = eui .ParamEditor ;
5143 testCase.Figure = gcf();
@@ -68,7 +60,8 @@ function buildParams(testCase)
6860 PE .buildUI(pars );
6961 % Number of global parameters: find all text labels
7062 nGlobalLabels = numel(findobj(testCase .Figure , ' Style' , ' text' ));
71- nGlobalInput = numel(findobj(testCase .Figure , ' Style' , ' checkbox' , ' -or' , ' Style' , ' edit' ));
63+ nGlobalInput = numel(findobj(testCase .Figure , ' Style' , ' checkbox' ,...
64+ ' -or' , ' Style' , ' edit' ));
7265 % Ensure all global params have UI input and label
7366 testCase .fatalAssertTrue(nGlobalLabels == numel(PE .Parameters .GlobalNames ))
7467 testCase .fatalAssertTrue(nGlobalInput == numel(PE .Parameters .GlobalNames ))
@@ -95,7 +88,8 @@ function test_makeConditional(testCase)
9588 testCase .assertTrue(~testCase .Changed , ' Changed flag incorrect' )
9689 % Number of global parameters: find all text labels
9790 gLabels = @()findobj(testCase .Figure , ' Style' , ' text' );
98- gInputs = @()findobj(testCase .Figure , ' Style' , ' checkbox' , ' -or' , ' Style' , ' edit' );
91+ gInputs = @()findobj(testCase .Figure , ' Style' , ' checkbox' ,...
92+ ' -or' , ' Style' , ' edit' );
9993 nGlobalLabels = numel(gLabels());
10094 nGlobalInputs = numel(gInputs());
10195 tableSz = size(testCase .Table .Data );
@@ -140,7 +134,8 @@ function test_paramValue2Control(testCase)
140134 PE = testCase .ParamEditor ;
141135 % Test function handle
142136 testCase .verifyEqual(PE .paramValue2Control(@nop ), ' nop' )
143- testCase .verifyEqual(PE .controlValue2Param(@nop , ' identity' ), @identity )
137+ testCase .verifyEqual(PE .controlValue2Param(@nop , ' identity' ),...
138+ @identity )
144139
145140 % Test logical array
146141 testCase .verifyEqual(PE .paramValue2Control(true(1 ,2 )), true(1 ,2 ))
@@ -163,7 +158,6 @@ function test_paramValue2Control(testCase)
163158 % Test string data
164159 % TODO Outcome will change in near future
165160 testCase .verifyEqual(PE .paramValue2Control(" hello" ), ' hello' )
166- % testCase.verifyEqual(PE.controlValue2Param("hello", "Goodbye"), "Goodbye")
167161
168162 % Test numeric data
169163 testCase .verifyEqual(PE .paramValue2Control(pi ), ' 3.1416' )
@@ -185,14 +179,17 @@ function test_newCondition(testCase)
185179 % Set the focused object to one of the parameter labels
186180 set(testCase .Figure , ' CurrentObject' , ...
187181 findobj(testCase .Figure , ' Tag' , ' experimentFun' ))
188- feval(pick(findobj(testCase .Figure , ' Text' , ' Make Conditional' ), ' MenuSelectedFcn' ))
182+ feval(pick(findobj(testCase .Figure , ' Text' , ' Make Conditional' ),...
183+ ' MenuSelectedFcn' ))
189184
190185 % Reset Changed flag
191186 testCase.Changed = false ;
192187
193188 % Retrieve function handle for new condition
194- fn = pick(findobj(testCase .Figure , ' String' , ' New condition' ), ' Callback' );
195- testCase .verifyWarningFree(fn , ' Warning encountered adding trial condition' )
189+ fn = pick(findobj(testCase .Figure , ' String' , ' New condition' ),...
190+ ' Callback' );
191+ testCase .verifyWarningFree(fn ,...
192+ ' Warning encountered adding trial condition' )
196193
197194 % Verify change in table data
198195 testCase .verifyEqual(size(testCase .Table .Data , 1 ), tableRows + 1 , ...
@@ -222,15 +219,17 @@ function test_deleteCondition(testCase)
222219 selection_fn([],event )
223220
224221 % Retrieve function handle for delete condition
225- callback_fn = pick(findobj(testCase .Figure , ' String' , ' Delete condition' ), ' Callback' );
226- testCase .verifyWarningFree(callback_fn , ' Warning encountered deleting trial conditions' )
222+ callback_fn = pick(findobj(testCase .Figure ,...
223+ ' String' , ' Delete condition' ), ' Callback' );
224+ testCase .verifyWarningFree(callback_fn ,...
225+ ' Warning encountered deleting trial conditions' )
227226
228227 % Verify change in table data
229228 testCase .verifyEqual(size(testCase .Table .Data , 1 ), tableRows - 5 , ...
230229 ' Unexpected number of trial conditions' )
231230
232231 % Verify change in Parameters object for conditional
233- testCase .assertEqual(size(testCase .Table .Data ), ...
232+ testCase .assertEqual(size(testCase .Table .Data ),...
234233 [PE .Parameters .numTrialConditions , numel(PE .Parameters .TrialSpecificNames )])
235234
236235 % Verify Changed event triggered
@@ -241,7 +240,8 @@ function test_deleteCondition(testCase)
241240 event.Indices = [(1 : PE .Parameters .numTrialConditions - 1 )' ...
242241 ones(PE .Parameters .numTrialConditions - 1 ,1 )];
243242 selection_fn([],event )
244- testCase .verifyWarningFree(callback_fn , ' Warning encountered deleting trial conditions' )
243+ testCase .verifyWarningFree(callback_fn ,...
244+ ' Warning encountered deleting trial conditions' )
245245
246246 % Verify change in table data
247247 testCase .verifyEmpty(testCase .Table .Data , ...
@@ -268,8 +268,10 @@ function test_globaliseParam(testCase)
268268 selection_fn([],event )
269269
270270 % Retrieve function handle for new condition
271- callback_fn = pick(findobj(testCase .Figure , ' String' , ' Globalise parameter' ), ' Callback' );
272- testCase .verifyWarningFree(callback_fn , ' Warning encountered globalising params' )
271+ callback_fn = pick(findobj(testCase .Figure ,...
272+ ' String' , ' Globalise parameter' ), ' Callback' );
273+ testCase .verifyWarningFree(callback_fn ,...
274+ ' Warning encountered globalising params' )
273275
274276 % Verify change in table data
275277 testCase .verifyEqual(size(testCase .Table .Data ,2 ), tableCols - 1 , ...
@@ -288,7 +290,8 @@ function test_globaliseParam(testCase)
288290 event.Indices = [ones(n ,1 ), (1 : n )' ];
289291 numRepeatsTotal = sum(PE .Parameters .Struct .numRepeats );
290292 selection_fn([],event )
291- testCase .verifyWarningFree(callback_fn , ' Warning encountered globalising params' )
293+ testCase .verifyWarningFree(callback_fn ,...
294+ ' Warning encountered globalising params' )
292295
293296 % Verify numRepeats is global
294297 testCase .verifyTrue(~PE .Parameters .isTrialSpecific(' numRepeats' ), ...
@@ -309,7 +312,8 @@ function test_globaliseParam(testCase)
309312 n = numel(PE .Parameters .TrialSpecificNames );
310313 event.Indices = [ones(n - 1 ,1 ), (2 : n )' ];
311314 selection_fn([],event )
312- testCase .verifyWarningFree(callback_fn , ' Warning encountered globalising params' )
315+ testCase .verifyWarningFree(callback_fn ,...
316+ ' Warning encountered globalising params' )
313317
314318 % Verify change in table data
315319 testCase .verifyEqual(size(testCase .Table .Data ,2 ), 1 , ...
@@ -326,7 +330,8 @@ function test_paramEdits(testCase)
326330
327331 % Retreive all global parameters labels and input controls
328332 gLabels = findobj(testCase .Figure , ' Style' , ' text' );
329- gInputs = findobj(testCase .Figure , ' Style' , ' checkbox' , ' -or' , ' Style' , ' edit' );
333+ gInputs = findobj(testCase .Figure , ' Style' , ' checkbox' ,...
334+ ' -or' , ' Style' , ' edit' );
330335
331336 % Test editing global param, 'edit' UI
332337 idx = find(strcmp({gInputs .Style }, ' edit' ), 1 );
@@ -409,7 +414,8 @@ function test_interactivity(testCase)
409414 % Find all disabled controls
410415 disabled = findobj(testCase .Figure , ' Enable' , ' off' );
411416 % Verify buttons greyed out
412- testCase .verifyEmpty(disabled , ' Unexpected number of disabled ui elements' )
417+ testCase .verifyEmpty(disabled ,...
418+ ' Unexpected number of disabled ui elements' )
413419
414420 % Test disabling param editor altogether
415421 PE.Enable = false ;
0 commit comments