|
| 1 | +function test_suite = test_readAndFilterLogfile %#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_readAndFilterLogfileBasic() |
| 10 | + |
| 11 | + %% set up |
| 12 | + |
| 13 | + [cfg, logFile] = setUp(); |
| 14 | + |
| 15 | + % create the events file and header |
| 16 | + logFile = saveEventsFile('open', cfg, logFile); |
| 17 | + |
| 18 | + % ROW 2: normal events : all info is there |
| 19 | + logFile(1, 1).onset = 2; |
| 20 | + logFile(end, 1).trial_type = 'motion_up'; |
| 21 | + logFile(end, 1).duration = 3; |
| 22 | + logFile(end, 1).Speed = 2; |
| 23 | + logFile(end, 1).is_Fixation = true; |
| 24 | + logFile(end, 1).LHL24 = 1:12; |
| 25 | + |
| 26 | + logFile(2, 1).onset = 2; |
| 27 | + logFile(end, 1).trial_type = 'motion_down'; |
| 28 | + logFile(end, 1).duration = 3; |
| 29 | + logFile(end, 1).Speed = 2; |
| 30 | + logFile(end, 1).is_Fixation = true; |
| 31 | + logFile(end, 1).LHL24 = 2:13; |
| 32 | + |
| 33 | + logFile = saveEventsFile('save', cfg, logFile); |
| 34 | + |
| 35 | + % close the file |
| 36 | + saveEventsFile('close', cfg, logFile); |
| 37 | + |
| 38 | + % filter file |
| 39 | + outputFiltered = readAndFilterLogfile('trial_type', 'motion_down', true, cfg); |
| 40 | + |
| 41 | + %% test |
| 42 | + expectedFilename = strrep(cfg.fileName.events, '.tsv', ... |
| 43 | + ['_filteredBy-' 'trial_type' '_' 'motion_down' '.tsv']); |
| 44 | + expectedFile = fullfile(cfg.dir.outputSubject, ... |
| 45 | + cfg.fileName.modality, ... |
| 46 | + expectedFilename); |
| 47 | + |
| 48 | + assertEqual(exist(expectedFile, 'file'), 2); |
| 49 | + |
| 50 | + content = bids.util.tsvread(expectedFile); |
| 51 | + |
| 52 | + assertEqual(content.trial_type{1}, 'motion_down'); |
| 53 | + |
| 54 | +end |
| 55 | + |
| 56 | +function test_readAndFilterLogfileFromFile() |
| 57 | + |
| 58 | + %% set up |
| 59 | + |
| 60 | + inputFile = fullfile(fileparts(mfilename('fullpath')), 'dummyData', ... |
| 61 | + 'sub-blind01_ses-01_task-vislocalizer_events.tsv'); |
| 62 | + |
| 63 | + % filter file |
| 64 | + outputFiltered = readAndFilterLogfile('trial_type', 'VisStat', true, inputFile); |
| 65 | + |
| 66 | + %% test |
| 67 | + expectedFile = strrep(inputFile, '.tsv', ... |
| 68 | + ['_filteredBy-' 'trial_type' '_' 'VisStat' '.tsv']); |
| 69 | + |
| 70 | + assertEqual(exist(expectedFile, 'file'), 2); |
| 71 | + |
| 72 | + content = bids.util.tsvread(expectedFile); |
| 73 | + |
| 74 | + assertEqual(content.trial_type{1}, 'VisStat'); |
| 75 | + |
| 76 | +end |
0 commit comments