Skip to content

Commit dcf47e3

Browse files
committed
[Matlab] Fix find section tests
Closes #153 Changes introduced by nix PR #692 require updated findXXX method tests.
1 parent 173dc13 commit dcf47e3

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

+nix/Utils.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,19 @@
157157
error(err);
158158
end
159159

160+
if (maxDepth < 0)
161+
err.identifier = 'NIXMX:InvalidArgument';
162+
err.message = 'Search depth must be positive integers or logicals.';
163+
error(err);
164+
end
165+
160166
nix.Utils.validFilter(filter, val);
161167

162168
% transform matlab to c++ style index
163-
md = nix.Utils.handleIndex(maxDepth);
169+
%md = nix.Utils.handleIndex(maxDepth);
164170

165171
mxMethod = strcat(obj.alias, '::', mxMethodName);
166-
list = nix_mx(mxMethod, obj.nixhandle, md, uint8(filter), val);
172+
list = nix_mx(mxMethod, obj.nixhandle, maxDepth, uint8(filter), val);
167173
r = nix.Utils.createEntityArray(list, objConstructor);
168174
end
169175

tests/TestBlock.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,23 +1125,23 @@
11251125
end
11261126

11271127
% find all
1128-
filtered = b.findSources(5);
1129-
assert(size(filtered, 1) == 10);
1130-
1131-
% find until level 4
11321128
filtered = b.findSources(4);
11331129
assert(size(filtered, 1) == 10);
11341130

11351131
% find until level 3
11361132
filtered = b.findSources(3);
1137-
assert(size(filtered, 1) == 6);
1133+
assert(size(filtered, 1) == 10);
11381134

11391135
% find until level 2
11401136
filtered = b.findSources(2);
1141-
assert(size(filtered, 1) == 3);
1137+
assert(size(filtered, 1) == 6);
11421138

11431139
% find until level 1
11441140
filtered = b.findSources(1);
1141+
assert(size(filtered, 1) == 3);
1142+
1143+
% find until level 0
1144+
filtered = b.findSources(0);
11451145
assert(size(filtered, 1) == 1);
11461146
end
11471147

@@ -1186,9 +1186,9 @@
11861186
assert(strcmp(filtered{1}.name, sl41.name));
11871187

11881188
% test find by type
1189-
filtered = b.filterFindSources(1, nix.Filter.type, findSource);
1189+
filtered = b.filterFindSources(0, nix.Filter.type, findSource);
11901190
assert(isempty(filtered));
1191-
filtered = b.filterFindSources(4, nix.Filter.type, findSource);
1191+
filtered = b.filterFindSources(3, nix.Filter.type, findSource);
11921192
assert(size(filtered, 1) == 3);
11931193
assert(strcmp(filtered{1}.type, findSource));
11941194

tests/TestSection.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,25 +753,29 @@
753753
assert(strcmp(ME.message, err));
754754
end
755755

756-
% find all
757-
filtered = sl1.findSections(5);
758-
assert(size(filtered, 1) == 10);
756+
% Check invalid entry
757+
err = 'Search depth must be positive integers or logicals.';
758+
try
759+
sl1.findSections(-20);
760+
catch ME
761+
assert(strcmp(ME.message, err));
762+
end
759763

760-
% find until level 4
764+
% find all
761765
filtered = sl1.findSections(4);
762-
assert(size(filtered, 1) == 10);
766+
assert(size(filtered, 1) == 9);
763767

764768
% find until level 3
765769
filtered = sl1.findSections(3);
766-
assert(size(filtered, 1) == 6);
770+
assert(size(filtered, 1) == 9);
767771

768772
% find until level 2
769773
filtered = sl1.findSections(2);
770-
assert(size(filtered, 1) == 3);
774+
assert(size(filtered, 1) == 5);
771775

772776
% find until level 1
773777
filtered = sl1.findSections(1);
774-
assert(size(filtered, 1) == 1);
778+
assert(size(filtered, 1) == 2);
775779
end
776780

777781
%% Test: Find Sections with filters
@@ -805,7 +809,7 @@
805809
assert(strcmp(filtered{1}.id, sl41.id));
806810

807811
% test find by ids
808-
filterids = {sl1.id, sl41.id};
812+
filterids = {sl21.id, sl41.id};
809813
filtered = sl1.filterFindSections(1, nix.Filter.ids, filterids);
810814
assert(size(filtered, 1) == 1);
811815
filtered = sl1.filterFindSections(4, nix.Filter.ids, filterids);
@@ -821,7 +825,7 @@
821825
assert(strcmp(filtered{1}.name, sl41.name));
822826

823827
% test find by type
824-
filtered = sl1.filterFindSections(1, nix.Filter.type, findSection);
828+
filtered = main.filterFindSections(1, nix.Filter.type, findSection);
825829
assert(isempty(filtered));
826830
filtered = sl1.filterFindSections(4, nix.Filter.type, findSection);
827831
assert(size(filtered, 1) == 3);

tests/TestSource.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,23 +401,23 @@
401401
end
402402

403403
% find all
404-
filtered = s.findSources(5);
404+
filtered = s.findSources(4);
405405
assert(size(filtered, 1) == 11);
406406

407407
% find until level 3
408-
filtered = s.findSources(4);
408+
filtered = s.findSources(3);
409409
assert(size(filtered, 1) == 7);
410410

411411
% find until level 2
412-
filtered = s.findSources(3);
412+
filtered = s.findSources(2);
413413
assert(size(filtered, 1) == 4);
414414

415415
% find until level 1
416-
filtered = s.findSources(2);
416+
filtered = s.findSources(1);
417417
assert(size(filtered, 1) == 2);
418418

419419
% find until level 0
420-
filtered = s.findSources(1);
420+
filtered = s.findSources(0);
421421
assert(size(filtered, 1) == 1);
422422
end
423423

0 commit comments

Comments
 (0)