Skip to content

Commit 1c341cc

Browse files
committed
add test for nanPadding and checkInput
1 parent 147aaf9 commit 1c341cc

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

miss_hit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ copyright_entity: "CPP_BIDS developers"
66

77
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
88
metric "cnest": limit 4
9-
metric "file_length": limit 550
9+
metric "file_length": limit 500
1010
metric "cyc": limit 15
1111
metric "parameters": limit 6

src/utils/nanPadding.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
% (C) Copyright 2020 CPP_BIDS developers
22

33
function data = nanPadding(cfg, data, expectedLength)
4-
4+
%
55
% For numeric data that don't have the expected length, it will be padded
66
% with NaNs. If the vector is too long it will be truncated
7+
%
8+
% USAGE::
9+
%
10+
% data = nanPadding(cfg, data, expectedLength)
11+
%
12+
%
713

814
if nargin < 2
915
expectedLength = [];

tests/test_checkInput.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
% (C) Copyright 2020 CPP_BIDS developers
2+
3+
function test_suite = test_checkInput %#ok<*STOUT>
4+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
5+
test_functions = localfunctions(); %#ok<*NASGU>
6+
catch % no problem; early Matlab versions can use initTestSuite fine
7+
end
8+
initTestSuite;
9+
end
10+
11+
function test_checkInputBasic()
12+
13+
data = checkInput(1);
14+
assertEqual(data, 1);
15+
16+
data = checkInput('test');
17+
assertEqual(data, 'test');
18+
19+
data = checkInput('');
20+
assertEqual(data, 'n/a');
21+
22+
data = checkInput(' ');
23+
assertEqual(data, 'n/a');
24+
25+
data = checkInput([]);
26+
assertEqual(data, nan);
27+
28+
data = checkInput(true());
29+
assertEqual(data, 'true');
30+
31+
data = checkInput(false());
32+
assertEqual(data, 'false');
33+
34+
end

tests/test_nanPadding.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
% (C) Copyright 2020 CPP_BIDS developers
2+
3+
function test_suite = test_nanPadding %#ok<*STOUT>
4+
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
5+
test_functions = localfunctions(); %#ok<*NASGU>
6+
catch % no problem; early Matlab versions can use initTestSuite fine
7+
end
8+
initTestSuite;
9+
end
10+
11+
function test_nanPaddingBasic()
12+
13+
cfg.verbose = 1;
14+
15+
%%
16+
data = 'test';
17+
expectedLength = 2;
18+
19+
data = nanPadding(cfg, data, expectedLength);
20+
21+
assertEqual(data, 'test');
22+
23+
%%
24+
data = [1 0];
25+
expectedLength = 2;
26+
27+
data = nanPadding(cfg, data, expectedLength);
28+
29+
assertEqual(data, [1 0]);
30+
31+
%%
32+
data = [1 0];
33+
expectedLength = 3;
34+
35+
data = nanPadding(cfg, data, expectedLength);
36+
37+
assertEqual(data, [1 0 NaN]);
38+
39+
%%
40+
%%
41+
data = [1 0 1];
42+
expectedLength = 2;
43+
44+
data = nanPadding(cfg, data, expectedLength);
45+
46+
assertEqual(data, [1 0]);
47+
48+
end

0 commit comments

Comments
 (0)