Skip to content

Commit ba591d1

Browse files
committed
add test save stim tsv
1 parent ba192e6 commit ba591d1

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

tests/test_createDataDictionary.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function test_createDataDictionaryBasic()
6161
% data to test against
6262
expectedStruct = bids.util.jsondecode( ...
6363
fullfile( ...
64-
pwd, '..', 'tests', ...
64+
pwd, ...
6565
'testData', ...
6666
'eventsDataDictionary.json'));
6767

@@ -128,8 +128,6 @@ function test_createDataDictionaryStim()
128128
expectedStruct = bids.util.jsondecode( ...
129129
fullfile( ...
130130
pwd, ...
131-
'..', ...
132-
'tests', ...
133131
'testData', ...
134132
'stimDataDictionary.json'));
135133

tests/test_createJson.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ function test_createJsonExtra()
169169
fileName));
170170

171171
% data to test against
172-
% JsonContent = [
173-
% '{"Instructions": "","RepetitionTime": [],"SliceTiming": [],', ...
174-
% '"TaskDescription": "","TaskName": "testtask",', ...
175-
% '"extraInfo": {"nestedExtraInfo": "something extra"}', ...
176-
% '}'];
177-
% system(sprintf("echo %s%s%s > extra_bold.json", "'", JsonContent, "'"));
178-
179-
172+
% JsonContent = [
173+
% '{"Instructions": "","RepetitionTime": [],"SliceTiming": [],', ...
174+
% '"TaskDescription": "","TaskName": "testtask",', ...
175+
% '"extraInfo": {"nestedExtraInfo": "something extra"}', ...
176+
% '}'];
177+
% system(sprintf("echo %s%s%s > extra_bold.json", "'", JsonContent, "'"));
178+
179+
ls
180180
expectedStruct = bids.util.jsondecode(fullfile(pwd, 'extra_bold.json'));
181181

182182
% test

tests/test_saveEventsFileSave.m

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,63 @@ function test_saveEventsFileSaveBasic()
4646

4747
end
4848

49+
function test_saveEventsFileSaveStim()
50+
51+
%% set up
52+
53+
cfg.verbose = 2;
54+
55+
cfg.subject.subjectNb = 1;
56+
cfg.subject.runNb = 1;
57+
58+
cfg.task.name = 'testtask';
59+
60+
cfg.testingDevice = 'mri';
61+
62+
cfg = createFilename(cfg);
63+
64+
logFile.extraColumns = {'Speed', 'LHL24', 'is_Fixation'};
65+
66+
logFile = saveEventsFile('init_stim', cfg, logFile);
67+
68+
logFile.extraColumns.Speed.length = 1;
69+
logFile.extraColumns.LHL24.length = 3;
70+
logFile.extraColumns.is_Fixation.length = 1;
71+
72+
% create the events file and header
73+
logFile = saveEventsFile('open', cfg, logFile);
74+
75+
% ROW 2: normal events : all info is there
76+
logFile(1, 1).onset = 2;
77+
logFile(end, 1).trial_type = 'motion_up';
78+
logFile(end, 1).duration = 3;
79+
logFile(end, 1).Speed = 2;
80+
logFile(end, 1).LHL24 = 1:3;
81+
logFile(end, 1).is_Fixation = true;
82+
83+
logFile = saveEventsFile('save', cfg, logFile);
84+
85+
% close the file
86+
saveEventsFile('close', cfg, logFile);
87+
88+
% check the extra columns of the header and some of the content
89+
nbExtraCol = ...
90+
logFile(1).extraColumns.Speed.length + ...
91+
logFile(1).extraColumns.LHL24.length + ...
92+
logFile(1).extraColumns.is_Fixation.length;
93+
94+
funcDir = fullfile(cfg.dir.outputSubject, cfg.fileName.modality);
95+
96+
FID = fopen(fullfile(funcDir, logFile.filename), 'r');
97+
content = textscan(FID, repmat('%s', 1, nbExtraCol), 'Delimiter', '\t', 'EndOfLine', '\n');
98+
99+
% event 1/ ROW 2: check that values are entered correctly
100+
assertEqual(content{1}{1}, sprintf('%f', 2));
101+
assertEqual(content{4}{1}, sprintf('%f', 3));
102+
assertEqual(content{5}{1}, 'true');
103+
104+
end
105+
49106
function test_saveEventsFileSaveSkipEmptyEvents()
50107

51108
%% set up

0 commit comments

Comments
 (0)