-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from haoershi/main
update unit tests
- Loading branch information
Showing
86 changed files
with
29,577 additions
and
29,842 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
%% Test Class Definition | ||
classdef authTest < matlab.unittest.TestCase | ||
%% Test Method Block | ||
methods (Test) | ||
% includes unit test functions | ||
function testAuth(testCase) | ||
% see https://www.mathworks.com/help/matlab/matlab_prog/types-of-qualifications.html | ||
% for qualification method | ||
% addpath(genpath('./../..')); % always add to ensure loading of other files/func | ||
paths; | ||
assert(exist(USER_DIR,'dir') == 7); | ||
if ~isempty(getenv('GITHUB_ACTIONS')) | ||
% Use GitHub secrets to retrieve credentials | ||
config.usr = getenv('IEEG_USERNAME'); | ||
config.pwd = getenv('IEEG_PASSWORD'); | ||
pwd_path = fullfile(USER_DIR, strcat(config.usr(1:3), '_ieeglogin.bin')); | ||
PATH = IEEGSession.createPwdFile(config.usr, config.pwd, pwd_path); | ||
config.pwd = strcat(config.usr(1:3), '_ieeglogin.bin'); | ||
file_name = fullfile(USER_DIR, strcat(config.usr(1:3), '_config.json')); | ||
jsonStr = jsonencode(config); | ||
fid = fopen(file_name, 'w'); | ||
fprintf(fid, '%s', jsonStr); | ||
fclose(fid); | ||
fprintf('-- -- IEEG user config file saved -- --\n'); | ||
user_data_dir = fullfile(DATA_DIR, config.usr(1:3)); | ||
end | ||
files = dir(fullfile(USER_DIR,'*.json')); | ||
if isempty(files) | ||
error('Login info unavailable.') | ||
else | ||
for i = 1:length(files) | ||
f = fullfile(files(i).folder, files(i).name); | ||
login = jsondecode(fileread(f)); | ||
assert(exist(fullfile(USER_DIR,login.pwd))) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
classdef bandPowerTest < matlab.unittest.TestCase | ||
|
||
methods (Test) | ||
function testBandPowerAbsolute(tc) | ||
addpath(genpath('./..')); | ||
% Generate example data with known band power in the alpha range | ||
fs = 250; | ||
duration = 10; % seconds | ||
time = [0:1/fs:duration-1/fs]'; | ||
alpha_band = [8, 12]; | ||
alpha_power = 0.5; % Known alpha band power | ||
|
||
data = zeros(length(time), 1); | ||
data = data + sin(2*pi*10*time) + 0.1 * randn(size(time)); % Alpha band (10 Hz) | ||
|
||
% Call the function under test | ||
bp = band_power(data, fs, alpha_band); | ||
|
||
% Assertions | ||
tc.verifyEqual(bp, alpha_power, 'Alpha band power mismatch', 'AbsTol', 0.1); % Allow some tolerance | ||
|
||
% Generate example data | ||
data = randn(100, 5); | ||
fs = 250; | ||
band = [1, 30]; | ||
|
||
% Call the function under test | ||
bp = band_power(data, fs, band); | ||
|
||
% Assertions | ||
tc.verifyEqual(size(bp), [1, size(data, 2)], 'Band power size mismatch'); | ||
tc.verifyGreaterThan(bp, 0, 'Band power should be greater than zero'); | ||
end | ||
|
||
function testBandPowerRelative(tc) | ||
addpath(genpath('./..')); | ||
% Generate example data with known band power in the alpha range | ||
fs = 250; | ||
duration = 10; % seconds | ||
time = [0:1/fs:duration-1/fs]'; | ||
|
||
% Simulate data with power in two frequency bands | ||
alpha_band = [8, 12]; | ||
beta_band = [15, 30]; | ||
alpha_power = 0.6; % Known power ratio | ||
beta_power = 0.4; % Known power ratio | ||
|
||
data_alpha = sin(2*pi*10*time); % Alpha band (10 Hz) | ||
data_beta = sin(2*pi*20*time); % Beta band (20 Hz) | ||
|
||
data = alpha_power * data_alpha + beta_power * data_beta + 0.1 *randn(size(time)); | ||
% Call the function under test with relative power | ||
bp = band_power(data, fs, alpha_band, [], true); | ||
|
||
% Assertions | ||
tc.verifyEqual(bp, alpha_power, 'Relative alpha band power mismatch', 'AbsTol', 0.1); % Allow some tolerance | ||
|
||
|
||
% Generate example data | ||
data = randn(100, 5); | ||
fs = 250; | ||
band = [1, 30]; | ||
|
||
% Call the function under test with relative power | ||
bp = band_power(data, fs, band, [], true); | ||
|
||
% Assertions | ||
tc.verifyEqual(size(bp), [1, size(data, 2)], 'Relative band power size mismatch'); | ||
tc.verifyGreaterThanOrEqual(bp, 0, 'Relative band power should be greater than or equal to zero'); | ||
tc.verifyLessThanOrEqual(bp, 1, 'Relative band power should be less than or equal to one'); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
classdef bandpassFilterTest < matlab.unittest.TestCase | ||
|
||
methods (Test) | ||
function test_BandpassFilter(tc) | ||
% Test with default parameters | ||
|
||
addpath(genpath('./..')); % always add to ensure loading of other files/func | ||
paths; | ||
load(fullfile(TESTDATA_DIR,'sampleData.mat')); | ||
values = bandpass_filter(old_values, fs); | ||
tc.verifyEqual(size(values), size(old_values), 'Output size mismatch'); | ||
values = bandpass_filter(old_values, fs, 5, 50, 6); | ||
tc.verifyEqual(size(values), size(old_values), 'Output size mismatch'); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.