Skip to content

Commit

Permalink
TST+RF: refactor test for EEGLAB I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
nno committed Feb 7, 2017
1 parent 0b51763 commit 6fa2494
Showing 1 changed file with 79 additions and 16 deletions.
95 changes: 79 additions & 16 deletions tests/test_meeg_io.m
Expand Up @@ -304,7 +304,13 @@ function test_meeg_ft_io_exceptions()


function test_eeglab_io()
args=cosmo_cartprod(repmat({{true;false}},1,3));
datatypes={'timef','erp'};

args=cosmo_cartprod({{true,false},...
{true,false},...
datatypes});


ncombi=size(args,1);
for k=1:ncombi
arg=args(k,:);
Expand Down Expand Up @@ -338,7 +344,12 @@ function test_eeglab_io()

function test_eeglab_io_trials()

args=cosmo_cartprod(repmat({{true;false}},1,3));
datatypes={'timef','erp'};

args=cosmo_cartprod({{true,false},...
{true,false},...
datatypes});

ncombi=size(args,1);
for k=1:ncombi
arg=args(k,:);
Expand Down Expand Up @@ -382,7 +393,7 @@ function test_eeglab_io_exceptions()
aet_m2m=@(varargin)assertExceptionThrown(@()...
cosmo_map2meeg(varargin{:}),'');

s=build_eeglab_dataset_struct(true,true,true);
s=build_eeglab_dataset_struct(true,true,'timef');

% bad datatype
s.datatype='foo';
Expand All @@ -408,16 +419,33 @@ function test_eeglab_io_exceptions()
end




function [s,ds,ext]=build_eeglab_dataset_struct(has_ica,has_freq,has_trial)
function [s,ds,ext]=build_eeglab_dataset_struct(has_ica,has_trial,datatype)
% trial dimension
if has_trial
trial_dim=randint();
else
trial_dim=1;
end

if strcmp(datatype,'ersp')
builder=@build_eeglab_dataset_struct;
[s1,ds1,ext]=builder(has_ica,has_trial,'ersp_nobaseline');
[s2,ds2]=builder(has_ica,has_trial,'erspbase');

keys=s2.chanlabels;
for k=1:numel(keys)
key=keys{k};
assert(~isfield(s1,key));
s1.(key)=s2.(key);
end

s=s1;
ds={ds1,ds2};
return;
end




% channel / component dimension
chan_dim=randint();
Expand All @@ -433,10 +461,26 @@ function test_eeglab_io_exceptions()
make_chan_prefix_func=@randstr;
end

if has_freq
chan_suffix='_timef';
else
chan_suffix='';
has_freq=2;

switch datatype
case 'timef'
chan_suffix='_timef';

case 'erp'
chan_suffix='';

case 'ersp_nobaseline'
chan_suffix='_ersp';

case 'erspbase'
chan_suffix='_erspbase';

case 'itc';
chan_suffix='_itc';

otherwise
assert(false);
end

make_chan_label=@(idx) sprintf('%s%d',make_chan_prefix_func(),idx);
Expand All @@ -446,24 +490,43 @@ function test_eeglab_io_exceptions()
'UniformOutput',false)};

% frequency dimension
switch datatype
case {'timef','ersp','itc'}
has_freq=true;


case {'erp','erspbase'};
has_freq=false;

otherwise
assert(false);
end

if has_freq
freq_dim=randint();
freq_label={'freq'};
freq_value={(1:freq_dim)*2};
samples_type='timefreq';
ext_suffix='timef';
else
freq_dim=[];
freq_label={};
freq_value={};
samples_type='timelock';
ext_suffix='erp';
end

% time dimensions
time_dim=randint();
time_label={'time'};
time_value={(1:time_dim())*.2-.1};
ext_suffix=datatype;

if strcmp(datatype,'erspbase')
% no time dimension
time_dim=[];
time_label={};
time_value={};
else
% include time dimension
time_dim=randint();
time_label={'time'};
time_value={(1:time_dim())*.2-.1};
end

% data
dim_sizes=[trial_dim,chan_dim,freq_dim,time_dim];
Expand Down

0 comments on commit 6fa2494

Please sign in to comment.