Skip to content

Commit 6b71aad

Browse files
committed
add some tests
1 parent 1f791f4 commit 6b71aad

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

src/dot/decomposeMotion.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
function [horVector, vertVector] = decomposeMotion(angleMotion)
2+
% [horVector, vertVector] = decomposeMotion(angleMotion)
3+
%
24
% decompose angle of start motion into horizontal and vertical vector
5+
%
6+
% - angleMotion: in degrees
7+
% - horVector: horizontal component of motion
8+
% - vertVector: vertical component of motion
9+
310
horVector = cos(pi * angleMotion / 180);
411
vertVector = -sin(pi * angleMotion / 180);
512
end

src/errors/errorDistanceToScreen.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function errorDistanceToScreen(cfg)
2+
3+
errorStruct.message = sprintf([
4+
'Distance to monitor seems too small.\n' ...
5+
'It should be in centimeters.\n' ...
6+
'cfg.screen.monitorDistance = %f'], cfg.screen.monitorDistance);
7+
8+
errorStruct.identifier = 'computeFOV:wrongDistanceToScreen';
9+
10+
error(errorStruct);
11+
end
12+

src/utils/computeFOV.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
% and D is the distance to the object.
1010
% The result obtained is in radians.
1111
%
12+
13+
if cfg.screen.monitorDistance < 2
14+
errorDistanceToScreen(cfg);
15+
end
1216

1317
FOV = ...
1418
180 / pi * ...

tests/test_computeFOV.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function test_suite = test_computeFOV %#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_computeFOVBasic()
10+
11+
cfg.screen.monitorWidth = 25;
12+
cfg.screen.monitorDistance = 50;
13+
14+
FOV = computeFOV(cfg);
15+
16+
expectedFOV = 28.072;
17+
18+
assertElementsAlmostEqual(expectedFOV, FOV, 'absolute', 1e-3)
19+
20+
end
21+
22+
function test_computeFOVError()
23+
24+
cfg.screen.monitorDistance = 1.2; % error as distance is most likely in meter
25+
26+
assertExceptionThrown(@()computeFOV(cfg), ...
27+
'computeFOV:wrongDistanceToScreen');
28+
29+
end
30+

tests/test_decomposeMotion.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function test_suite = test_decomposeMotion %#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_decomposeMotionBasic()
10+
11+
[horVector, vertVector] = decomposeMotion(0);
12+
expectedOutput = [1, 0];
13+
assertEqual(expectedOutput, [horVector, vertVector]);
14+
15+
[horVector, vertVector] = decomposeMotion(90);
16+
expectedOutput = [0, -1];
17+
assertElementsAlmostEqual(expectedOutput, [horVector, vertVector]);
18+
19+
[horVector, vertVector] = decomposeMotion(180);
20+
expectedOutput = [-1, 0];
21+
assertElementsAlmostEqual(expectedOutput, [horVector, vertVector]);
22+
23+
[horVector, vertVector] = decomposeMotion(270);
24+
expectedOutput = [0, 1];
25+
assertElementsAlmostEqual(expectedOutput, [horVector, vertVector]);
26+
27+
[horVector, vertVector] = decomposeMotion(360);
28+
expectedOutput = [1, 0];
29+
assertElementsAlmostEqual(expectedOutput, [horVector, vertVector]);
30+
31+
32+
end

tests/test_degToPix.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function test_suite = test_degToPix %#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_degToPixBasic()
10+
11+
fixation.width = 2;
12+
cfg.screen.ppd = 10;
13+
14+
fixation = degToPix('width', fixation, cfg);
15+
16+
expectedStruct.width = 2;
17+
expectedStruct.widthPix = 20;
18+
19+
assertEqual(expectedStruct, fixation);
20+
21+
end

0 commit comments

Comments
 (0)