Skip to content

Commit 4c9b67f

Browse files
author
jaib1
committed
renamed folder 'helpers' to 'fixtures'; added 'SharedTestFixtures' to test classes
1 parent d1ded06 commit 4c9b67f

14 files changed

+76
-79
lines changed

+eui/ConditionPanel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function clear(obj)
136136

137137
function delete(obj)
138138
% DELETE Deletes the UI container
139-
% Called when this object or its parant ParamEditor is deleted
139+
% Called when this object or its parent ParamEditor is deleted
140140
% See also CLEAR
141141
delete(obj.UIPanel);
142142
end

+eui/FieldPanel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function makeConditional(obj, name)
156156

157157
function delete(obj)
158158
% DELETE Deletes the UI container
159-
% Called when this object or its parant ParamEditor is deleted
159+
% Called when this object or its parent ParamEditor is deleted
160160
% See also CLEAR
161161
delete(obj.UIPanel);
162162
end

+eui/ParamEditor.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
% the trial conditions within a ui table
2323
ConditionalUI
2424
% Handle to the parent container for the ParamEditor. If constructor
25-
% called with no parant input, then this will be a figure handle, the
25+
% called with no parent input, then this will be a figure handle, the
2626
% same as Root
2727
Parent
2828
% Handle to the figure within which the ParamEditor is displayed
@@ -45,8 +45,8 @@
4545
function obj = ParamEditor(pars, parent)
4646
% PARAMEDITOR GUI for visualizing and editing experiment parameters
4747
% The input pars is expected to be an instance of the exp.Parameters
48-
% class. Parant is a handle to a parent figure or UI Panel. If no
49-
% parant is given, the editor is created in a new figure.
48+
% class. Parent is a handle to a parent figure or UI Panel. If no
49+
% parent is given, the editor is created in a new figure.
5050
%
5151
% See also EUI.FIELDPANEL, EUI.CONDITIONPANEL
5252
if nargin == 0; pars = []; end
@@ -81,7 +81,7 @@
8181

8282
function delete(obj)
8383
% DELETE Deletes all panels
84-
% Called when the ParamEditor object is deleted or its parant figure
84+
% Called when the ParamEditor object is deleted or its parent figure
8585
% is closed. Deletes all UI elements and data.
8686
% See also CLEAR
8787
delete(obj.GlobalUI);

tests/ParamEditor_perfTest.m

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
classdef ParamEditor_perfTest < matlab.perftest.TestCase
1+
classdef (SharedTestFixtures={matlab.unittest.fixtures.PathFixture(...
2+
[fileparts(mfilename('fullpath')) '\fixtures'])})... % add 'fixtures' folder as test fixture
3+
ParamEditor_perfTest < matlab.perftest.TestCase
24

35
properties
46
% Figure visibility setting before running tests
@@ -18,19 +20,8 @@ function setup(testCase)
1820
% Hide figures and add teardown function to restore settings
1921
testCase.FigureVisibleDefault = get(0,'DefaultFigureVisible');
2022
set(0,'DefaultFigureVisible','off');
21-
testCase.addTeardown(@set, 0, 'DefaultFigureVisible', testCase.FigureVisibleDefault);
22-
23-
% add a teardown for pre-test path:
24-
% (first arg is fixture instance (i.e. environment - when to
25-
% teardown (when this is out of scope)))
26-
% (second arg is tearDownFcn (i.e. what to execute during teardown))
27-
p = path;
28-
testCase.addTeardown(@path,p);
29-
30-
% add the the 'helpers' folder in the 'tests' folder for using the
31-
% 'tests' folder's version of 'dat.paths'
32-
curpath = fileparts(mfilename('fullpath'));
33-
addpath([curpath '\helpers'])
23+
testCase.addTeardown(@set, 0,...
24+
'DefaultFigureVisible', testCase.FigureVisibleDefault);
3425

3526
% Loads validation data
3627
% Graph data is a cell array where each element is the graph number
@@ -39,7 +30,8 @@ function setup(testCase)
3930
testCase.Parameters = exp.choiceWorldParams;
4031

4132
% Check paths file
42-
assert(endsWith(which('dat.paths'), fullfile('tests', 'helpers', '+dat', 'paths.m')));
33+
assert(endsWith(which('dat.paths'),...
34+
fullfile('tests', 'fixtures', '+dat', 'paths.m')));
4335
% Create stand-alone panel
4436
testCase.ParamEditor = eui.ParamEditor;
4537
testCase.Figure = gcf();
@@ -62,7 +54,8 @@ function buildParams(testCase)
6254
PE.buildUI(pars);
6355
% Number of global parameters: find all text labels
6456
nGlobalLabels = numel(findobj(testCase.Figure, 'Style', 'text'));
65-
nGlobalInput = numel(findobj(testCase.Figure, 'Style', 'checkbox', '-or', 'Style', 'edit'));
57+
nGlobalInput = numel(findobj(testCase.Figure,...
58+
'Style', 'checkbox', '-or', 'Style', 'edit'));
6659
% Ensure all global params have UI input and label
6760
assert(nGlobalLabels == numel(PE.Parameters.GlobalNames))
6861
assert(nGlobalInput == numel(PE.Parameters.GlobalNames))
@@ -99,7 +92,8 @@ function test_makeConditional(testCase)
9992
PE = testCase.ParamEditor;
10093
% Number of global parameters: find all text labels
10194
gLabels = @()findobj(testCase.Figure, 'Style', 'text');
102-
gInputs = @()findobj(testCase.Figure, 'Style', 'checkbox', '-or', 'Style', 'edit');
95+
gInputs = @()findobj(testCase.Figure, 'Style', 'checkbox',...
96+
'-or', 'Style', 'edit');
10397
nGlobalLabels = numel(gLabels());
10498
nGlobalInputs = numel(gInputs());
10599
tableSz = size(testCase.Table.Data);
@@ -140,10 +134,12 @@ function test_newCondition(testCase)
140134
% Set the focused object to one of the parameter labels
141135
set(testCase.Figure, 'CurrentObject', ...
142136
findobj(testCase.Figure, 'Tag', 'experimentFun'))
143-
feval(pick(findobj(testCase.Figure, 'Text', 'Make Conditional'), 'MenuSelectedFcn'))
137+
feval(pick(findobj(testCase.Figure, 'Text', 'Make Conditional'),...
138+
'MenuSelectedFcn'))
144139

145140
% Retrieve function handle for new condition
146-
fn = pick(findobj(testCase.Figure, 'String', 'New condition'), 'Callback');
141+
fn = pick(findobj(testCase.Figure, 'String', 'New condition'),...
142+
'Callback');
147143
testCase.startMeasuring();
148144
fn()
149145
testCase.stopMeasuring();
@@ -166,7 +162,8 @@ function test_deleteCondition(testCase)
166162
selection_fn([],event)
167163

168164
% Retrieve function handle for delete condition
169-
callback_fn = pick(findobj(testCase.Figure, 'String', 'Delete condition'), 'Callback');
165+
callback_fn = pick(findobj(testCase.Figure,...
166+
'String', 'Delete condition'), 'Callback');
170167
testCase.startMeasuring();
171168
callback_fn()
172169
testCase.stopMeasuring();
@@ -189,7 +186,8 @@ function test_globaliseParam(testCase)
189186
selection_fn([],event)
190187

191188
% Retrieve function handle for new condition
192-
callback_fn = pick(findobj(testCase.Figure, 'String', 'Globalise parameter'), 'Callback');
189+
callback_fn = pick(findobj(testCase.Figure, 'String',...
190+
'Globalise parameter'), 'Callback');
193191
testCase.startMeasuring();
194192
callback_fn()
195193
testCase.stopMeasuring();
@@ -208,7 +206,8 @@ function test_paramEdits(testCase)
208206

209207
% Retreive all global parameters labels and input controls
210208
gLabels = findobj(testCase.Figure, 'Style', 'text');
211-
gInputs = findobj(testCase.Figure, 'Style', 'checkbox', '-or', 'Style', 'edit');
209+
gInputs = findobj(testCase.Figure, 'Style', 'checkbox',...
210+
'-or', 'Style', 'edit');
212211

213212
% Test editing global param, 'edit' UI
214213
idx = find(strcmp({gInputs.Style}, 'edit'), 1);
@@ -226,7 +225,8 @@ function test_paramEdits(testCase)
226225
testCase.verifyEqual(gLabels(idx).ForegroundColor, [1 0 0], ...
227226
'Unexpected label colour')
228227
% Verify change in underlying param struct
229-
par = strcmpi(PE.Parameters.GlobalNames, strrep(gLabels(idx).String, ' ', ''));
228+
par = strcmpi(PE.Parameters.GlobalNames,...
229+
strrep(gLabels(idx).String, ' ', ''));
230230
testCase.verifyEqual(PE.Parameters.Struct.(PE.Parameters.GlobalNames{par}), 666, ...
231231
'UI edit failed to update parameters struct')
232232

tests/ParamEditor_test.m

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
classdef ParamEditor_test < matlab.unittest.TestCase
1+
classdef (SharedTestFixtures={matlab.unittest.fixtures.PathFixture(...
2+
[fileparts(mfilename('fullpath')) '\fixtures'])})... % 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;

tests/Parameters_test.m

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
classdef Parameters_test < matlab.unittest.TestCase
1+
classdef (SharedTestFixtures={matlab.unittest.fixtures.PathFixture(...
2+
[fileparts(mfilename('fullpath')) '\fixtures'])})... % add 'fixtures' folder as test fixture
3+
Parameters_test < matlab.unittest.TestCase
24

35
properties
46
% Parameters object
@@ -32,21 +34,10 @@ function loadData(testCase)
3234
'functionParam', @(pars,rig)exp.configureChoiceExperiment(exp.ChoiceWorld,pars,rig));
3335
end
3436

35-
function setupClass(testCase)
36-
% add a teardown for pre-test path:
37-
% (first arg is fixture instance (i.e. environment - when to
38-
% teardown (when this is out of scope)))
39-
% (second arg is tearDownFcn (i.e. what to execute during teardown))
40-
p = path;
41-
testCase.addTeardown(@path,p);
42-
43-
% add the the 'helpers' folder in the 'tests' folder for using the
44-
% 'tests' folder's version of 'dat.paths'
45-
curpath = fileparts(mfilename('fullpath'));
46-
addpath([curpath '\helpers'])
47-
37+
function setupClass(testCase)
4838
% Check paths file
49-
assert(endsWith(which('dat.paths'), fullfile('tests', 'helpers', '+dat', 'paths.m')));
39+
assert(endsWith(which('dat.paths'), fullfile('tests', 'fixtures',...
40+
'+dat', 'paths.m')));
5041
% Create stand-alone panel
5142
testCase.Parameters = exp.Parameters();
5243
testCase.fatalAssertTrue(isa(testCase.Parameters, 'exp.Parameters'))
File renamed without changes.

0 commit comments

Comments
 (0)