|
1 | | -function test_checkCFG() |
| 1 | +function test_suite = test_checkCFG %#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 |
2 | 8 |
|
| 9 | +function test_checkCfgDefault() |
| 10 | + |
| 11 | + %% set up |
3 | 12 | cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); |
4 | 13 | cfg = checkCFG(cfg); |
5 | | - |
6 | | - expectedStructure = returnExpectedStructure(); |
| 14 | + |
| 15 | + %% create test data |
| 16 | + expectedStructure = returnExpectedCfgStructure(); |
7 | 17 | expectedStructure.dir.output = cfg.dir.output; |
8 | 18 | expectedStructure.testingDevice = 'pc'; |
9 | | - |
10 | | - testSubFields(expectedStructure, cfg); |
11 | | - |
12 | | - %% |
13 | | - fprintf('\n--------------------------------------------------------------------'); |
14 | | - |
15 | | - clear; |
16 | | - |
| 19 | + |
| 20 | + %% test |
| 21 | + checkSubFields(expectedStructure, cfg); |
| 22 | + |
| 23 | +end |
| 24 | + |
| 25 | +function test_checkCfgBasic() |
| 26 | + |
| 27 | + %% set up |
17 | 28 | outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); |
18 | | - |
| 29 | + |
| 30 | + cfg.verbose = false; |
| 31 | + |
19 | 32 | cfg.subject.subjectNb = 1; |
20 | 33 | cfg.subject.runNb = 1; |
21 | | - |
| 34 | + |
22 | 35 | cfg.task.name = 'test task'; |
23 | | - |
| 36 | + |
24 | 37 | cfg.dir.output = outputDir; |
25 | | - |
| 38 | + |
26 | 39 | cfg.bids.datasetDescription.Name = 'dummy'; |
27 | 40 | cfg.bids.datasetDescription.BIDSVersion = '1.0.0'; |
28 | 41 | cfg.bids.datasetDescription.Authors = {'Jane Doe', 'John Doe'}; |
29 | | - |
| 42 | + |
30 | 43 | cfg.mri.repetitionTime = 1.56; |
31 | | - |
| 44 | + |
32 | 45 | cfg.testingDevice = 'mri'; |
33 | | - |
| 46 | + |
34 | 47 | cfg = checkCFG(cfg); |
35 | | - |
36 | | - %%% test |
37 | | - |
38 | | - % test data |
39 | | - expectedStructure = returnExpectedStructure(); |
| 48 | + |
| 49 | + %% create test data |
| 50 | + expectedStructure = returnExpectedCfgStructure(); |
40 | 51 | expectedStructure.subject.subjectNb = 1; |
41 | 52 | expectedStructure.subject.runNb = 1; |
42 | | - |
| 53 | + |
43 | 54 | expectedStructure.dir.output = outputDir; |
44 | | - |
| 55 | + |
45 | 56 | expectedStructure.task.name = 'test task'; |
46 | | - |
| 57 | + |
47 | 58 | expectedStructure.testingDevice = 'mri'; |
48 | | - |
| 59 | + |
49 | 60 | expectedStructure.mri.repetitionTime = 1.56; |
50 | | - |
| 61 | + |
51 | 62 | expectedStructure.fileName.task = 'testTask'; |
52 | | - |
| 63 | + |
53 | 64 | expectedStructure.bids.mri.RepetitionTime = 1.56; |
54 | 65 | expectedStructure.bids.mri.TaskName = 'test Task'; |
55 | | - |
| 66 | + |
56 | 67 | expectedStructure.bids.meg.TaskName = 'test Task'; |
57 | | - |
| 68 | + |
58 | 69 | expectedStructure.bids.datasetDescription.Name = 'dummy'; |
59 | 70 | expectedStructure.bids.datasetDescription.BIDSVersion = '1.0.0'; |
60 | 71 | expectedStructure.bids.datasetDescription.Authors = {'Jane Doe', 'John Doe'}; |
61 | | - |
| 72 | + |
62 | 73 | expectedStructure = orderfields(expectedStructure); |
63 | | - |
64 | | - testSubFields(expectedStructure, cfg); |
65 | | - |
66 | | - fprintf('\n'); |
67 | | - |
68 | | -end |
69 | | - |
70 | | -function expectedStructure = returnExpectedStructure() |
71 | | - |
72 | | - expectedStructure.subject.subjectGrp = ''; |
73 | | - expectedStructure.subject.sessionNb = 1; |
74 | | - expectedStructure.subject.askGrpSess = [true true]; |
75 | | - |
76 | | - expectedStructure.verbose = 0; |
77 | | - |
78 | | - expectedStructure.fileName.task = ''; |
79 | | - expectedStructure.fileName.zeroPadding = 3; |
80 | | - expectedStructure.fileName.dateFormat = 'yyyymmddHHMM'; |
81 | | - |
82 | | - expectedStructure.eyeTracker.do = false; |
83 | | - |
84 | | - expectedStructure.mri.contrastEnhancement = []; |
85 | | - expectedStructure.mri.phaseEncodingDirection = []; |
86 | | - expectedStructure.mri.reconstruction = []; |
87 | | - expectedStructure.mri.echo = []; |
88 | | - expectedStructure.mri.acquisition = []; |
89 | | - expectedStructure.mri.repetitionTime = []; |
90 | | - |
91 | | - expectedStructure.bids.mri.RepetitionTime = []; |
92 | | - expectedStructure.bids.mri.SliceTiming = ''; |
93 | | - expectedStructure.bids.mri.TaskName = ''; |
94 | | - expectedStructure.bids.mri.Instructions = ''; |
95 | | - expectedStructure.bids.mri.TaskDescription = ''; |
96 | | - |
97 | | - expectedStructure.bids.meg.TaskName = ''; |
98 | | - expectedStructure.bids.meg.SamplingFrequency = []; |
99 | | - expectedStructure.bids.meg.PowerLineFrequency = []; |
100 | | - expectedStructure.bids.meg.DewarPosition = []; |
101 | | - expectedStructure.bids.meg.SoftwareFilters = []; |
102 | | - expectedStructure.bids.meg.DigitizedLandmarks = []; |
103 | | - expectedStructure.bids.meg.DigitizedHeadPoints = []; |
104 | | - |
105 | | - expectedStructure.bids.datasetDescription.Name = ''; |
106 | | - expectedStructure.bids.datasetDescription.BIDSVersion = ''; |
107 | | - expectedStructure.bids.datasetDescription.License = ''; |
108 | | - expectedStructure.bids.datasetDescription.Authors = {''}; |
109 | | - expectedStructure.bids.datasetDescription.Acknowledgements = ''; |
110 | | - expectedStructure.bids.datasetDescription.HowToAcknowledge = ''; |
111 | | - expectedStructure.bids.datasetDescription.Funding = {''}; |
112 | | - expectedStructure.bids.datasetDescription.ReferencesAndLinks = {''}; |
113 | | - expectedStructure.bids.datasetDescription.DatasetDOI = ''; |
114 | | - |
115 | | - expectedStructure = orderfields(expectedStructure); |
116 | | - |
| 74 | + |
| 75 | + %% test |
| 76 | + checkSubFields(expectedStructure, cfg); |
| 77 | + |
117 | 78 | end |
118 | 79 |
|
119 | | -function testSubFields(expectedStructure, cfg) |
120 | | - % check that that the structures match |
121 | | - % if it fails it check from which subfield the error comes from |
122 | | - |
123 | | - try |
124 | | - |
125 | | - assert(isequal(expectedStructure, cfg)); |
126 | | - |
127 | | - catch ME |
128 | | - |
129 | | - if isstruct(expectedStructure) |
130 | | - |
131 | | - names = fieldnames(expectedStructure); |
132 | 80 |
|
133 | | - for i = 1:numel(names) |
134 | 81 |
|
135 | | - disp(names{i}); |
136 | | - testSubFields(expectedStructure.(names{i}), cfg.(names{i})); |
137 | | - |
138 | | - end |
139 | | - |
140 | | - end |
141 | | - |
142 | | - expectedStructure; |
143 | | - cfg; |
144 | | - |
145 | | - rethrow(ME); |
146 | | - end |
147 | | -end |
0 commit comments