Skip to content

Commit 3e886af

Browse files
committed
write test for initFixation
1 parent ff40059 commit 3e886af

File tree

4 files changed

+104
-11
lines changed

4 files changed

+104
-11
lines changed

src/fixation/initFixation.m

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
11
function cfg = initFixation(cfg)
2-
2+
% cfg = initFixation(cfg)
3+
%
4+
% prepare details for fixation "cross"
5+
%
6+
% the fixation has a width defined by
7+
% cfg.fixation.width : in degrees of visual
8+
%
9+
% The horizontal and vertical offset (in degrees of visual) with respect to the center of the
10+
% screen is defined by
11+
% cfg.fixation.xDisplacement
12+
% cfg.fixation.yDisplacement
13+
%
14+
% for cfg.fixation.type == 'bestFixation'
15+
% Code adapted from:
16+
% "What is the best fixation target?"
17+
% DOI 10.1016/j.visres.2012.10.012
18+
%
19+
20+
321
% Convert some values from degrees to pixels
422
cfg.fixation = degToPix('width', cfg.fixation, cfg);
523
cfg.fixation = degToPix('xDisplacement', cfg.fixation, cfg);
624
cfg.fixation = degToPix('yDisplacement', cfg.fixation, cfg);
7-
25+
826
% Prepare fixation cross
927
xLine = [-cfg.fixation.widthPix cfg.fixation.widthPix 0 0] / 2;
1028
yLine = [0 0 -cfg.fixation.widthPix cfg.fixation.widthPix] / 2;
11-
29+
1230
cfg.fixation.xCoords = xLine + cfg.fixation.xDisplacementPix;
1331
cfg.fixation.yCoords = yLine + cfg.fixation.yDisplacementPix;
14-
32+
1533
cfg.fixation.allCoords = [cfg.fixation.xCoords; cfg.fixation.yCoords];
16-
34+
35+
1736
switch cfg.fixation.type
18-
37+
1938
case 'bestFixation'
20-
39+
2140
% Code adapted from:
2241
% What is the best fixation target?
2342
% DOI 10.1016/j.visres.2012.10.012
24-
43+
2544
cfg.fixation.outerOval = [ ...
2645
cfg.screen.center(1) - cfg.fixation.widthPix / 2, ...
2746
cfg.screen.center(2) - cfg.fixation.widthPix / 2, ...
2847
cfg.screen.center(1) + cfg.fixation.widthPix / 2, ...
2948
cfg.screen.center(2) + cfg.fixation.widthPix / 2];
30-
49+
3150
cfg.fixation.innerOval = [ ...
3251
cfg.screen.center(1) - cfg.fixation.widthPix / 6, ...
3352
cfg.screen.center(2) - cfg.fixation.widthPix / 6, ...
3453
cfg.screen.center(1) + cfg.fixation.widthPix / 6, ...
3554
cfg.screen.center(2) + cfg.fixation.widthPix / 6];
36-
55+
3756
end
38-
57+
3958
end
File renamed without changes.

src/waitForTrigger.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ function waitForTrigger(varargin)
33
%
44
% Counts a certain number of triggers coming from the scanner before returning.
55
%
6+
% If you are not using the quietMode, it flips and waits for half a TR before starting to
7+
% check for the next trigger (unless this was the last trigger to wait for and in
8+
% this case it returns immediately).
9+
%
610
% Will print the count down in the command line and on the PTB window if one is
711
% opened.
812
%

tests/test_initFixation.m

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
function test_suite = test_initFixation %#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
8+
9+
function test_initFixationBasic()
10+
11+
cfg.screen.ppd = 10;
12+
cfg.fixation.type = 'cross';
13+
cfg.fixation.width = 1;
14+
cfg.fixation.xDisplacement = 1;
15+
cfg.fixation.yDisplacement = 1;
16+
17+
cfg = initFixation(cfg);
18+
19+
cfg.fixation
20+
21+
expectedStruct.screen.ppd = 10;
22+
expectedStruct.fixation.type = 'cross';
23+
expectedStruct.fixation.width = 1;
24+
expectedStruct.fixation.xDisplacement = 1;
25+
expectedStruct.fixation.yDisplacement = 1;
26+
expectedStruct.fixation.widthPix = 10;
27+
expectedStruct.fixation.xDisplacementPix = 10;
28+
expectedStruct.fixation.yDisplacementPix = 10;
29+
expectedStruct.fixation.xCoords = [5 15 10 10];
30+
expectedStruct.fixation.yCoords = [10 10 5 15];
31+
expectedStruct.fixation.allCoords = [5 15 10 10; 10 10 5 15];
32+
33+
assertEqual(expectedStruct, cfg)
34+
35+
36+
end
37+
38+
39+
function test_initFixationBestFixation()
40+
41+
cfg.screen.ppd = 10;
42+
cfg.screen.center = [100 100];
43+
cfg.fixation.type = 'bestFixation';
44+
cfg.fixation.width = 1;
45+
cfg.fixation.xDisplacement = 1;
46+
cfg.fixation.yDisplacement = 1;
47+
48+
cfg = initFixation(cfg);
49+
50+
cfg.fixation
51+
52+
expectedStruct.screen.ppd = 10;
53+
expectedStruct.screen.center = [100 100];
54+
expectedStruct.fixation.type = 'bestFixation';
55+
expectedStruct.fixation.width = 1;
56+
expectedStruct.fixation.xDisplacement = 1;
57+
expectedStruct.fixation.yDisplacement = 1;
58+
expectedStruct.fixation.widthPix = 10;
59+
expectedStruct.fixation.xDisplacementPix = 10;
60+
expectedStruct.fixation.yDisplacementPix = 10;
61+
expectedStruct.fixation.xCoords = [5 15 10 10];
62+
expectedStruct.fixation.yCoords = [10 10 5 15];
63+
expectedStruct.fixation.allCoords = [5 15 10 10; 10 10 5 15];
64+
expectedStruct.fixation.outerOval = [95 95 105 105];
65+
expectedStruct.fixation.innerOval = [100 - 10 / 6, 100 - 10 / 6, 100 + 10 / 6, 100 + 10 / 6];
66+
67+
assertEqual(expectedStruct, cfg)
68+
69+
70+
end

0 commit comments

Comments
 (0)