Skip to content

Commit

Permalink
Remove untestable/unreachable code and respective tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofachada committed Jun 27, 2023
1 parent 7c7499d commit 0cc85f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
6 changes: 0 additions & 6 deletions src/clumerge.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,9 @@
function t = common_supertype(type1, type2)

type_set = { type1, type2 };
validtypes = {'logical', 'int8', 'uint8', 'int16', 'uint16', ...
'int32', 'uint32', 'int64', 'uint64', 'char', 'single', 'double'};

if strcmp(type1, type2)
t = type1;
elseif ~string_in(type1, validtypes)
error(['Unsupported type `', type1 ,'`']);
elseif ~string_in(type2, validtypes)
error(['Unsupported type `', type2 ,'`']);
elseif string_in('char', type_set)
error('No common supertype between char and numerical type')
elseif string_in('double', type_set)
Expand Down
41 changes: 16 additions & 25 deletions tests/tests_all.m
Original file line number Diff line number Diff line change
Expand Up @@ -1775,42 +1775,33 @@
fn = @() clumerge({1, 2, 3});
assertError(fn);

% Invalid type in one of the data sets
nd = 5;
ds1 = struct(...
'points', rand(npts, nd), ...
'clusters', cell(npts, 1));
ds2 = struct(...
'points', rand(npts, nd), ...
'clusters', int64(randi(10, npts, 1)));
fn = @() clumerge({ds1, ds2});
assertError(fn);
fn = @() clumerge({ds2, ds1});
assertError(fn);

% No common supertype between char and numerical type
nd = 6;
npts1 = randi([10 100]);
npts2 = randi([10 100]);
ds1 = struct(...
'points', rand(npts, nd), ...
'clusters', int64(randi(10, npts, 1)));
'points', rand(npts1, nd), ...
'clusters', int64(randi(10, npts1, 1)));
ds2 = struct(...
'points', char(randi(255, npts, nd)), ...
'clusters', int64(randi(10, npts, 1)));
'points', char(randi(255, npts2, nd)), ...
'clusters', int64(randi(10, npts2, 1)));
fn = @() clumerge({ds1, ds2});
assertError(fn);

% There should be no problem with different compatible types
nd = 4;
npts1 = randi([10 100]);
npts2 = randi([10 100]);
ds1 = struct(...
'points', single(rand(npts, nd)), ...
'another', int16(randi(1000, npts, 1)), ...
'and_another', int16(randi(500, npts, 1)), ...
'clusters', int64(randi(10, npts, 1)));
'points', single(rand(npts1, nd)), ...
'another', int16(randi(1000, npts1, 1)), ...
'and_another', int16(randi(500, npts1, 1)), ...
'clusters', int64(randi(10, npts1, 1)));
ds2 = struct(...
'points', rand(npts, nd), ...
'another', single(randi(1000, npts, 1)), ...
'and_another', int32(randi(500, npts, 1)), ...
'clusters', int32(randi(10, npts, 1)));
'points', rand(npts2, nd), ...
'another', single(randi(1000, npts2, 1)), ...
'and_another', int32(randi(500, npts2, 1)), ...
'clusters', int32(randi(10, npts2, 1)));
lastwarn('');
mds = clumerge({ds1, ds2}, ...
'fields', {'points', 'another', 'and_another'});
Expand Down

0 comments on commit 0cc85f2

Please sign in to comment.