44% * History
55% Written in 2019 by Ivan Rojkov (University of Zurich)
66% Updated in 2024 by Teddy
7+ % Updated in 2026 by Bernhard von Raußendorf
8+
9+ properties (Constant )
10+ input_filename = fullfile(fileparts(mfilename(' fullpath' )), ' ImportTestData' , ' ecg2hb' , ' test_ecg_outlier_data_short_hb.mat' );
11+ backup_filename = fullfile(fileparts(mfilename(' fullpath' )),' ImportTestData' , ' ecg2hb' , ' test_backup.mat' );
12+ end
13+
14+ methods (TestClassSetup )
15+ function backup(this )
16+ this .assertTrue(isfile(this .input_filename ), ...
17+ sprintf(' Input file not found: %s ' , this .input_filename ));
18+
19+ [sts , msg ] = copyfile(this .input_filename , this .backup_filename );
20+ this .assertTrue(sts , msg );
21+ end
22+ end
23+
24+ methods (TestMethodSetup )
25+ function reset_input_file(this )
26+ [sts , msg ] = copyfile(this .backup_filename , this .input_filename );
27+ this .assertTrue(sts , msg );
28+ end
29+ end
30+
31+ % Tests
732methods (Test )
833function invalid_input(this )
9- files = {...
10- fullfile(' ImportTestData' , ' ecg2hb' , ' test_ecg_outlier_data_short.mat' ),...
11- fullfile(' ImportTestData' , ' ecg2hb' , ' test_hb2hp_data1.mat' ),...
12- fullfile(' ImportTestData' , ' ecg2hb' , ' test_hb2hp_data2.mat' )...
13- };
1434 % Verify no input
1535 this .verifyWarning(@() pspm_convert_hb2hp(), ' ID:invalid_input' );
1636 % Verify not a string filename
@@ -21,18 +41,74 @@ function invalid_input(this)
2141 this .verifyWarning(@() pspm_convert_hb2hp(' abc' ,' abc' ), ' ID:invalid_input' );
2242 % Verify not a numeric channel
2343 this .verifyWarning(@() pspm_convert_hb2hp(' abc' ,2 ,' abc' ), ' ID:invalid_input' );
24- % Verify that call of pspm_load_data fails
25- this .verifyWarning(@() pspm_convert_hb2hp(files{1 },100 ), ' ID:nonexistent_file' );
26- % Verify that interpolation does not have enough points
27- % this.verifyWarning(@() pspm_convert_hb2hp(files{2}, 100), 'ID:too_strict_limits');
28- % Verify that call of pspm_write_channel fails
29- options.channel_action = ' abc' ;
30- this .verifyWarning(@() pspm_convert_hb2hp(files{3 },100 ,[],options ),' ID:invalid_input' );
31- % options.channel_action = 'add';
32- % this.verifyWarningFree(@()pspm_convert_hb2hp(files{1},100,[],options));
44+
45+ %
46+ % % Verify that call of pspm_load_data fails
47+ % this.verifyWarning(@() pspm_convert_hb2hp(files{1},100), 'ID:nonexistent_file');
48+ % % Verify that interpolation does not have enough points
49+ % % this.verifyWarning(@() pspm_convert_hb2hp(files{2}, 100), 'ID:too_strict_limits');
50+ % % Verify that call of pspm_write_channel fails
51+ % options.channel_action = 'abc';
52+ % this.verifyWarning(@() pspm_convert_hb2hp(files{3},100,[],options),'ID:invalid_input');
53+ % %options.channel_action = 'add';
54+ % %this.verifyWarningFree(@()pspm_convert_hb2hp(files{1},100,[],options));
55+
56+ end
57+
58+ function basic_conversion(this )
59+ sr = 1000 ;
60+
61+ % this.verifyWarningFree(@() pspm_convert_hb2hp(this.input_filename, sr));
62+
63+ [sts , outchannel ] = pspm_convert_hb2hp(this .input_filename , sr );
64+
65+ this .verifyEqual(sts , 1 );
66+ this .verifyTrue(isnumeric(outchannel ));
67+ this .verifyGreaterThan(outchannel , 0 );
68+ end
69+
70+ function too_strict_limits(this )
71+ % fn = fullfile('ImportTestData', 'ecg2hb', 'test_hb2hp_data2.mat');
72+ sr = 100 ;
73+ options = struct();
74+ options = struct(' limit_lower' , 10 , ' limit_upper' , 11 );
75+
76+ this .verifyWarning(@() pspm_convert_hb2hp(this .input_filename , sr , options ), ' ID:too_strict_limits' );
77+
78+ [sts , outchannel ] = pspm_convert_hb2hp(this .input_filename , sr , options );
79+ this .verifyEqual(sts , 1 );
80+ this .verifyTrue(isnumeric(outchannel ));
81+ this .verifyGreaterThan(outchannel , 0 );
82+ end
83+
84+ function add_channel_action(this )
85+ fn = fullfile(' ImportTestData' , ' ecg2hb' , ' test_ecg_outlier_data_short_hb.mat' );
86+ sr = 100 ;
87+ options = struct();
88+ options.channel_action = ' add' ;
89+
90+ this .verifyWarningFree(@() pspm_convert_hb2hp(fn , sr , options ));
91+
92+ [sts , outchannel ] = pspm_convert_hb2hp(fn , sr , options );
93+
94+ this .verifyEqual(sts , 1 );
95+ this .verifyTrue(isnumeric(outchannel ));
96+ this .verifyGreaterThan(outchannel , 0 );
97+ end
98+
99+
100+
33101
34102end
35103
104+ methods (TestClassTeardown )
105+ function restore(this )
106+ if isfile(this .backup_filename )
107+ [sts , msg ] = copyfile(this .backup_filename , this .input_filename );
108+ this .assertTrue(sts , msg );
109+ delete(this .backup_filename );
110+ end
111+ end
36112end
37113
38114end
0 commit comments