1- function test_setDefaultsPTB()
2-
3- %% test basic cfg creation
1+ function test_suite = test_setDefaultsPTB % #ok<*STOUT>
2+ try % assignment of 'localfunctions' is necessary in Matlab >= 2016
3+ test_functions = localfunctions(); % #ok<*NASGU>
4+ catch % no problem; early Matlab versions can use initTestSuite fine
5+ end
6+ initTestSuite ;
7+ end
48
9+ function test_setDefaultsPtbBasic()
10+
11+ % set up
12+ cfg = setDefaultsPTB ;
13+
514 % test data
6- expectedCFG = returnExpectedCFG();
15+ expectedCfg = returnExpectedCFG();
716
817 % test
9- cfg = setDefaultsPTB ;
10- testSubFields(expectedCFG , cfg );
11-
12- %% test that values are not overwritten
18+ assertEqual(expectedCfg , cfg );
19+
20+ end
1321
14- clear cfg ;
15-
16- % test data
17- expectedCFG = returnExpectedCFG();
18- expectedCFG.screen.monitorWidth = 36 ;
22+ function test_setDefaultsPtbOverwrite()
1923
2024 % set up
2125 cfg.screen.monitorWidth = 36 ;
22-
23- % test
2426 cfg = setDefaultsPTB(cfg );
25- testSubFields(expectedCFG , cfg );
27+
28+ % test data
29+ expectedCfg = returnExpectedCFG();
30+ expectedCfg.screen.monitorWidth = 36 ;
2631
27- %% test with audio init
32+ % test
33+ assertEqual(expectedCfg , cfg );
34+
35+ end
2836
29- clear cfg ;
37+ function test_setDefaultsPtbAudio()
3038
39+ % set up
40+ cfg.audio.do = 1 ;
41+ cfg = setDefaultsPTB(cfg );
42+
3143 % test data
32- expectedCFG = returnExpectedCFG();
33- expectedCFG .audio = struct( ...
44+ expectedCfg = returnExpectedCFG();
45+ expectedCfg .audio = struct( ...
3446 ' do' , true , ...
3547 ' fs' , 44800 , ...
3648 ' channels' , 2 , ...
@@ -40,17 +52,13 @@ function test_setDefaultsPTB()
4052 ' startCue' , 0 , ...
4153 ' waitForDevice' , 1 );
4254
43- % set up
44- cfg.audio.do = 1 ;
45-
4655 % test
47- cfg = setDefaultsPTB(cfg );
48- testSubFields(expectedCFG , cfg );
49-
56+ assertEqual(expectedCfg , cfg );
57+
5058end
5159
5260function expectedCFG = returnExpectedCFG()
53-
61+
5462 expectedCFG = struct( ...
5563 ' testingDevice' , ' pc' , ...
5664 ' debug' , struct(' do' , true , ' transpWin' , true , ' smallWin' , true ), ...
@@ -60,51 +68,21 @@ function test_setDefaultsPTB()
6068 ' screen' , struct( ...
6169 ' monitorWidth' , 42 , ...
6270 ' monitorDistance' , 134 ));
63-
71+
6472 % fixation cross or dot
6573 expectedCFG.fixation.type = ' cross' ;
6674 expectedCFG.fixation.xDisplacement = 0 ;
6775 expectedCFG.fixation.yDisplacement = 0 ;
6876 expectedCFG.fixation.color = [255 255 255 ];
6977 expectedCFG.fixation.width = 1 ;
7078 expectedCFG.fixation.lineWidthPix = 5 ;
71-
79+
7280 % define visual apperture field
7381 expectedCFG.aperture.type = ' none' ;
74-
82+
7583 expectedCFG.keyboard.keyboard = [];
7684 expectedCFG.keyboard.responseBox = [];
7785 expectedCFG.keyboard.responseKey = {};
7886 expectedCFG.keyboard.escapeKey = ' ESCAPE' ;
79-
80- end
81-
82- function testSubFields(expectedStructure , cfg )
83- % check that that the structures match
84- % if it fails it check from which subfield the error comes from
85-
86- try
87-
88- assert(isequal(expectedStructure , cfg ));
89-
90- catch ME
91-
92- if isstruct(expectedStructure )
93-
94- names = fieldnames(expectedStructure );
95-
96- for i = 1 : numel(names )
97-
98- disp(names{i });
99- testSubFields(expectedStructure.(names{i }), cfg.(names{i }));
100-
101- end
102-
103- end
104-
105- expectedStructure ;
106- cfg ;
107-
108- rethrow(ME );
109- end
87+
11088end
0 commit comments