Skip to content

Commit

Permalink
move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Apr 13, 2024
1 parent 3a10402 commit 37a4433
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 141 deletions.
2 changes: 1 addition & 1 deletion tests/test_transformers/test_transformers_compute.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

function write_definition(input, output, trans, stack)
test_name = stack.name;
% write_test_definition_to_file(input, output, trans, test_name, 'compute');
% write_test_definition_to_file(input, output, trans, test_name, 'compute');
end

%% multi step
Expand Down
111 changes: 107 additions & 4 deletions tests/test_transformers/test_transformers_munge.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ function write_definition(input, output, trans, stack, suffix)

end

%% single step

% ordered alphabetically

function test_Assign_with_target_attribute()

transformers = struct('Name', 'Assign', ...
Expand Down Expand Up @@ -145,6 +141,113 @@ function test_Replace_string_in_numeric_output()

end

function test_multi_touch()

% GIVEN
tsvFile = fullfile(dummy_data_dir(), 'sub-01_task-TouchBefore_events.tsv');
tsv_content = bids.util.tsvread(tsvFile);

transformers{1} = struct('Name', 'Threshold', ...
'Input', 'duration', ...
'Binarize', true, ...
'Output', 'tmp');
transformers{2} = struct('Name', 'Replace', ...
'Input', 'tmp', ...
'Output', 'duration', ...
'Attribute', 'duration', ...
'Replace', struct('key', 1, ...
'value', 1));
transformers{3} = struct('Name', 'Delete', ...
'Input', {{'tmp'}});

% WHEN
[new_content, json] = bids.transformers(transformers, tsv_content);

% THEN
% TODO assert whole content
assertEqual(fieldnames(tsv_content), fieldnames(new_content));
assertEqual(json, struct('Transformer', ['bids-matlab_' bids.internal.get_version], ...
'Instructions', {transformers}));

end

function test_multi_combine_columns()

% GIVEN
tsvFile = fullfile(dummy_data_dir(), 'sub-01_task-FaceRepetitionBefore_events.tsv');
tsv_content = bids.util.tsvread(tsvFile);

transformers{1} = struct('Name', 'Filter', ...
'Input', 'face_type', ...
'Query', 'face_type==famous', ...
'Output', 'Famous');
transformers{2} = struct('Name', 'Filter', ...
'Input', 'repetition_type', ...
'Query', 'repetition_type==1', ...
'Output', 'FirstRep');
transformers{3} = struct('Name', 'And', ...
'Input', {{'Famous', 'FirstRep'}}, ...
'Output', 'tmp');
transformers{4} = struct('Name', 'Replace', ...
'Input', 'tmp', ...
'Output', 'trial_type', ...
'Replace', struct('key', 'tmp_1', ...
'value', 'FamousFirstRep'));
transformers{5} = struct('Name', 'Delete', ...
'Input', {{'tmp', 'Famous', 'FirstRep'}});

% WHEN
data = tsv_content;
new_content = bids.transformers(transformers, data);

% THEN
% TODO assert whole content
assertEqual(fieldnames(tsv_content), fieldnames(new_content));
assertEqual(unique(new_content.trial_type), {'face'});

end

function test_multi_complex_filter_with_and()

%% GIVEN
tsvFile = fullfile(dummy_data_dir(), 'sub-01_task-FaceRepetitionBefore_events.tsv');
tsv_content = bids.util.tsvread(tsvFile);

transformers{1} = struct('Name', 'Filter', ...
'Input', 'face_type', ...
'Query', 'face_type==famous', ...
'Output', 'Famous');
transformers{2} = struct('Name', 'Filter', ...
'Input', 'repetition_type', ...
'Query', 'repetition_type==1', ...
'Output', 'FirstRep');

% WHEN
data = tsv_content;
new_content = bids.transformers(transformers, data);

% THEN
assert(all(ismember({'Famous'; 'FirstRep'}, fieldnames(new_content))));
assertEqual(sum(strcmp(new_content.Famous, 'famous')), 52);

if ~isempty(which('nansum'))
assertEqual(bids.internal.nansum(new_content.FirstRep), 52);
end

%% GIVEN
transformers{3} = struct('Name', 'And', ...
'Input', {{'Famous', 'FirstRep'}}, ...
'Output', 'FamousFirstRep');

% WHEN
data = tsv_content;
new_content = bids.transformers(transformers, data);

% THEN
assertEqual(sum(new_content.FamousFirstRep), 26);

end

%% Helper functions

function cfg = set_up()
Expand Down
136 changes: 0 additions & 136 deletions tests/test_transformers/test_transformers_munge_multi.m

This file was deleted.

0 comments on commit 37a4433

Please sign in to comment.