-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinferParams_test.m
74 lines (62 loc) · 2.43 KB
/
inferParams_test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%inferParams test
expDefPath = fullfile(getOr(dat.paths,'rigbox'), 'tests', 'fixtures', 'expDefinitions');
% preconditions
parameters = exp.inferParameters(@nop);
correct = struct('numRepeats', 1000, 'defFunction', which('nop'), 'type', 'custom');
assert(isequal(parameters, correct),'Fundamental problem: inferParameters not returning pars')
%% Test 1: advancedChoiceWorld
% Test an experiment definition that has conditional parameters, an
% experiment panel function file and various default paramters data types
pars = exp.inferParameters([expDefPath filesep 'advancedChoiceWorld.m']);
load(fullfile(expDefPath, 'advancedChoiceWorld_parameters.mat'));
assert(strcmp(pars.defFunction, [expDefPath filesep 'advancedChoiceWorld.m']), ...
'Incorrect expDef path')
% Remove defFunction field before comparison
pars = rmfield(pars, 'defFunction');
parameters = rmfield(parameters, 'defFunction');
assert(isequal(pars, parameters), 'Unexpected parameter struct returned')
%% Test 2: choiceWorld
% Test an experiment definition that has no conditional parameters
pars = exp.inferParameters([expDefPath filesep 'choiceWorld.m']);
load(fullfile(expDefPath, 'choiceWorld_parameters.mat'));
% Remove defFunction field before comparison
pars = rmfield(pars, 'defFunction');
parameters = rmfield(parameters, 'defFunction');
assert(isequal(pars, parameters), 'Unexpected parameter struct returned')
%% Test 3: single global parameter
% Test an experiment definition that has single parameter which is a
% character array
pars = exp.inferParameters(@singleCharParam);
parameters = struct(...
'char', 'charecter array',...
'numRepeats', 1000,...
'defFunction', '',...
'type', 'custom');
assert(isequal(pars, parameters), 'Unexpected parameter struct returned')
%% Test 4: reserved names
% Test an experiment definition that uses reserved parameter names
try
pars = exp.inferParameters(@reservedParams);
id = '';
catch ex
id = ex.identifier;
end
assert(strcmp(id, 'exp:InferParameters:ReservedParameters'), ...
'Failed to throw reserved parameter name error')
%% Helper functions
function singleCharParam(~, ~, p, varargin)
% Helper function to test an expDef where there is a single parameter which
% is a charecter array
p.char
p.char = 'charecter array';
end
function reservedParams(~, ~, p, varargin)
% Helper function to test use of reserved parameter names
p.randomiseConditions;
p.services;
p.expPanelFun;
p.numRepeats;
p.defFunction;
p.waterType;
p.isPassive;
end