11function test_saveEventsFileSave()
2-
2+
33 %% write things in it
44 clear ;
5-
5+
66 outputDir = fullfile(fileparts(mfilename(' fullpath' )), ' ..' , ' output' );
7-
7+
88 % %% set up
9-
9+
1010 cfg.subject.subjectNb = 1 ;
1111 cfg.subject.runNb = 1 ;
1212 cfg.task.name = ' testtask' ;
1313 cfg.dir.output = outputDir ;
14-
14+
1515 cfg.testingDevice = ' mri' ;
16-
16+
1717 cfg = createFilename(cfg );
18-
18+
1919 logFile.extraColumns.Speed.length = 1 ;
2020 logFile.extraColumns.LHL24.length = 12 ;
2121 logFile.extraColumns.is_Fixation.length = 1 ;
22-
22+
2323 % create the events file and header
2424 logFile = saveEventsFile(' open' , cfg , logFile );
25-
25+
2626 % %% do stuff
27-
27+
2828 % ROW 2: normal events : all info is there
2929 logFile(1 , 1 ).onset = 2 ;
3030 logFile(end , 1 ).trial_type = ' motion_up' ;
3131 logFile(end , 1 ).duration = 3 ;
3232 logFile(end , 1 ).Speed = 2 ;
3333 logFile(end , 1 ).is_Fixation = true ;
3434 logFile(end , 1 ).LHL24 = 1 : 12 ;
35-
35+
3636 logFile = saveEventsFile(' save' , cfg , logFile );
37-
37+
3838 % ROW 3: missing info (speed, LHL24)
3939 logFile(1 , 1 ).onset = 3 ;
4040 logFile(end , 1 ).trial_type = ' static' ;
4141 logFile(end , 1 ).duration = 4 ;
4242 logFile(end , 1 ).is_Fixation = false ;
43-
43+
4444 % ROW 4: missing info (duration is missing and speed is empty)
4545 logFile(2 , 1 ).onset = 4 ;
4646 logFile(end , 1 ).trial_type = ' motion_up' ;
4747 logFile(end , 1 ).Speed = [];
4848 logFile(end , 1 ).is_Fixation = true ;
4949 logFile(end , 1 ).LHL24 = 1 : 12 ;
50-
50+
5151 % empty events
5252 logFile(3 , 1 ).onset = [];
5353 logFile(end , 1 ).trial_type = [];
5454 logFile(end , 1 ).duration = 3 ;
55-
55+
5656 logFile(4 , 1 ).onset = 1 ;
5757 logFile(end , 1 ).trial_type = ' ' ;
58-
58+
5959 % ROW 5: missing info (array is too short)
6060 logFile(5 , 1 ).onset = 5 ;
6161 logFile(end , 1 ).trial_type = ' jazz' ;
6262 logFile(end , 1 ).duration = 3 ;
6363 logFile(end , 1 ).LHL24 = rand(1 , 10 );
64-
64+
6565 % ROW 6: too much info (array is too long)
6666 % logFile(5, 1).onset = 5;
6767 % logFile(end, 1).trial_type = 'blues';
6868 % logFile(end, 1).duration = 3;
6969 % logFile(end, 1).LHL24 = rand(1, 15);
70-
70+
7171 saveEventsFile(' save' , cfg , logFile );
72-
72+
7373 % close the file
7474 saveEventsFile(' close' , cfg , logFile );
75-
75+
7676 % %% test section
77-
77+
7878 % check the extra columns of the header and some of the content
7979 nbExtraCol = ...
8080 logFile(1 ).extraColumns.Speed.length + ...
8181 logFile(1 ).extraColumns.LHL24.length + ...
8282 logFile(1 ).extraColumns.is_Fixation.length;
83-
83+
8484 funcDir = fullfile(cfg .dir .outputSubject , cfg .fileName .modality );
8585 eventFilename = cfg .fileName .events ;
8686 FID = fopen(fullfile(funcDir , eventFilename ), ' r' );
8787 C = textscan(FID , repmat(' %s ' , 1 , nbExtraCol + 3 ), ' Delimiter' , ' \t ' , ' EndOfLine' , ' \n ' );
88-
88+
8989 % event 1/ ROW 2: check that values are entered correctly
9090 assert(isequal(C{1 }{2 }, sprintf(' %f ' , 2 )));
9191 assert(isequal(C{3 }{2 }, ' motion_up' ));
@@ -94,22 +94,22 @@ function test_saveEventsFileSave()
9494 assert(isequal(C{5 }{2 }, sprintf(' %f ' , 1 )));
9595 assert(isequal(C{16 }{2 }, sprintf(' %f ' , 12 )));
9696 assert(isequal(C{17 }{2 }, ' true' ));
97-
97+
9898 % event 2 / ROW 3: missing info replaced by nans
9999 assert(isequal(C{4 }{3 }, ' n/a' ));
100100 assert(isequal(C{5 }{3 }, ' n/a' ));
101101 assert(isequal(C{16 }{3 }, ' n/a' ));
102102 assert(isequal(C{17 }{3 }, ' false' ));
103-
103+
104104 % event 3 / ROW 4: missing info (duration is missing and speed is empty)
105105 assert(isequal(C{2 }{4 }, ' n/a' ));
106106 assert(isequal(C{4 }{4 }, ' n/a' ));
107-
107+
108108 % event 4-5 / ROW 5-6: skip empty events
109109 assert(~isequal(C{1 }{5 }, ' n/a' ));
110-
110+
111111 % check values entered properly
112112 assert(isequal(C{15 }{5 }, ' n/a' ));
113113 assert(isequal(C{16 }{5 }, ' n/a' ));
114-
114+
115115end
0 commit comments