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
7 changes: 4 additions & 3 deletions loadData/load_epoch.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
for ep = 1:length(session.epochs)

name{ep, 1} = session.epochs{ep}.name;
startTime(ep, 1) = session.epochs{ep}.startTime;
stopTime(ep, 1) = session.epochs{ep}.stopTime;
% force to double in case time is different type
startTime(ep, 1) = double(session.epochs{ep}.startTime);
stopTime(ep, 1) = double(session.epochs{ep}.stopTime);

if isfield(session.epochs{ep}, 'environment')
environment{ep, 1} = session.epochs{ep}.environment;
Expand Down Expand Up @@ -61,4 +62,4 @@
epochs = table(name, startTime, stopTime, environment, behavioralParadigm, ...
manipulation, stimuli, notes, basepath);

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

function test_basic_epoch_loading(testCase)

% Create temporary directory
basepath = tempname;
mkdir(basepath);

% Use real basename convention
[~, basename] = fileparts(basepath);

% Create fake session struct
session.epochs = {; ...
struct( ...
'name', 'sleep', ...
'startTime', int32(0), ...
'stopTime', int32(100), ...
'environment', 'home', ...
'behavioralParadigm', 'none', ...
'manipulation', 'none', ...
'stimuli', 'none', ...
'notes', 'baseline' ...
), ...
struct( ...
'name', 'run', ...
'startTime', single(100), ...
'stopTime', single(200) ...
); ...
};

% Save session file with correct basename
save(fullfile(basepath, [basename, '.session.mat']), 'session');

% Run function
epochs = load_epoch('basepath', basepath);

% ---- Assertions ----

verifyEqual(testCase, height(epochs), 2);

verifyEqual(testCase, epochs.name{1}, 'sleep');
verifyEqual(testCase, epochs.name{2}, 'run');

verifyClass(testCase, epochs.startTime, 'double');
verifyClass(testCase, epochs.stopTime, 'double');

verifyEqual(testCase, epochs.startTime(1), 0);
verifyEqual(testCase, epochs.stopTime(2), 200);

verifyEqual(testCase, epochs.environment{1}, 'home');
verifyEqual(testCase, epochs.environment{2}, '');

verifyEqual(testCase, epochs.behavioralParadigm{2}, '');
verifyEqual(testCase, epochs.manipulation{2}, '');
verifyEqual(testCase, epochs.stimuli{2}, '');
verifyEqual(testCase, epochs.notes{2}, '');

verifyEqual(testCase, epochs.basepath{1}, basepath);
verifyEqual(testCase, epochs.basepath{2}, basepath);

end
Loading