Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ jobs:
assert(EEG.nbchan == size(EEG.data, 1));
assert(EEG.pnts == size(EEG.data, 2));

- name: Run MATLAB regression tests
if: steps.matlab.outputs.available == 'true'
uses: matlab-actions/run-command@v2
with:
command: |
cd(getenv('GITHUB_WORKSPACE'));
results = runtests('tests');
assertSuccess(results);

- name: Skip MATLAB smoke
if: steps.matlab.outputs.available != 'true'
run: |
Expand Down
3 changes: 1 addition & 2 deletions functions/popfunc/pop_selectevent.m
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
Iepoch = ~Iepoch;
end
Iepoch = find(Iepoch == 0);
if strcmpi(g.erroronempty, 'on')
if isempty(Iepoch) && strcmpi(g.erroronempty, 'on')
error('All epochs have been removed, empty dataset')
end
if nargin < 2
Expand Down Expand Up @@ -596,4 +596,3 @@
tmpvarvalue = cell2mat(tmpvarvalue);
end
% ======== JRI BUGFIX 3/6/14

83 changes: 83 additions & 0 deletions tests/test_pop_selectevent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function tests = test_pop_selectevent
tests = functiontests(localfunctions);
end

function setupOnce(testCase)
root = fileparts(fileparts(mfilename('fullpath')));
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(root));
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(fullfile(root, 'functions'), 'IncludingSubfolders', true));
end

function testRetainsMatchingEpochs(testCase)
EEG = fixture;
selected = pop_selectevent(EEG, 'type', 'target', 'deleteepochs', 'on');
verifyEqual(testCase, selected.trials, 2);
verifyEqual(testCase, selected.data, EEG.data(:, :, [1 3]));
verifyEqual(testCase, numel(selected.event), 4);
verifyEqual(testCase, [selected.event.epoch], [1 1 2 2]);
end

function testEmptySelectionErrorsByDefault(testCase)
verifyError(testCase, @() pop_selectevent(fixture, 'type', 'absent', 'deleteepochs', 'on'), '');
end

function testEmptySelectionAllowed(testCase)
selected = pop_selectevent(fixture, 'type', 'absent', 'deleteepochs', 'on', 'erroronempty', 'off');
verifyEmpty(testCase, selected.data);
verifyEmpty(testCase, selected.event);
end

function testInverseEpochSelection(testCase)
EEG = fixture;
selected = pop_selectevent(EEG, 'type', 'target', 'deleteepochs', 'on', 'invertepochs', 'on');
verifyEqual(testCase, selected.data, EEG.data(:, :, [2 4]));
verifyEqual(testCase, selected.trials, 2);
end

function testDeleteUnselectedEvents(testCase)
selected = pop_selectevent(fixture, 'type', 'target', 'deleteepochs', 'on', 'deleteevents', 'on');
verifyEqual(testCase, {selected.event.type}, {'target' 'target'});
verifyEqual(testCase, [selected.event.epoch], [1 2]);
end

function testKeepEpochsWhenDeletingOnlyEvents(testCase)
EEG = fixture;
selected = pop_selectevent(EEG, 'type', 'target', 'deleteepochs', 'off', 'deleteevents', 'on');
verifyEqual(testCase, selected.data, EEG.data);
verifyEqual(testCase, numel(selected.event), 2);
end

function testExplicitErrorOptionWithNonemptySelection(testCase)
EEG = fixture;
selected = pop_selectevent(EEG, 'type', 'target', 'deleteepochs', 'on', 'erroronempty', 'on');
verifyEqual(testCase, selected.data, EEG.data(:, :, [1 3]));
end

function testDatasetArray(testCase)
EEG = fixture;
selected = pop_selectevent([EEG EEG], 'type', 'target', 'deleteepochs', 'on');
verifyEqual(testCase, numel(selected), 2);
verifyEqual(testCase, [selected.trials], [2 2]);
verifyEqual(testCase, selected(1).data, EEG.data(:, :, [1 3]));
verifyEqual(testCase, selected(2).data, EEG.data(:, :, [1 3]));
end

function EEG = fixture
EEG = eeg_emptyset;
EEG.setname = 'selection regression';
EEG.nbchan = 1;
EEG.srate = 1000;
EEG.pnts = 10;
EEG.trials = 4;
EEG.xmin = 0;
EEG.xmax = 0.009;
EEG.data = reshape(single(1:40), 1, 10, 4);
EEG.event = struct('type', {}, 'latency', {}, 'epoch', {});
for trial = 1:4
type = 'other';
if mod(trial, 2), type = 'target'; end
EEG.event(2*trial-1) = struct('type', type, 'latency', (trial-1)*10+3, 'epoch', trial);
EEG.event(2*trial) = struct('type', 'distractor', 'latency', (trial-1)*10+7, 'epoch', trial);
end
EEG = eeg_checkset(EEG, 'eventconsistency');
end
Loading