|
43 | 43 | funcs{end+1} = @test_filter_property;
|
44 | 44 | funcs{end+1} = @test_find_section;
|
45 | 45 | funcs{end+1} = @test_find_section_filtered;
|
| 46 | + funcs{end+1} = @test_find_related; |
46 | 47 | end
|
47 | 48 |
|
48 | 49 | %% Test: Create Section
|
|
855 | 856 | assert(strcmp(ME.message, err));
|
856 | 857 | end
|
857 | 858 | end
|
| 859 | + |
| 860 | +%% Test: Find sections related to the current section |
| 861 | +function [] = test_find_related |
| 862 | + findSectionType = 'nixFindSection'; |
| 863 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 864 | + main = f.create_section('testSection', 'nixSection'); |
| 865 | + sl1 = main.create_section('sectionLvl1', 'nixSection'); |
| 866 | + |
| 867 | + sl21 = sl1.create_section('sectionLvl2_1', findSectionType); |
| 868 | + sl22 = sl1.create_section('sectionLvl2_2', findSectionType); |
| 869 | + |
| 870 | + sl31 = sl21.create_section('sectionLvl3_1', findSectionType); |
| 871 | + sl32 = sl21.create_section('sectionLvl3_2', 'nixSection'); |
| 872 | + sl33 = sl21.create_section('sectionLvl3_3', 'nixSection'); |
| 873 | + |
| 874 | + sl41 = sl31.create_section('sectionLvl4_1', findSectionType); |
| 875 | + sl42 = sl31.create_section('sectionLvl4_2', findSectionType); |
| 876 | + sl43 = sl31.create_section('sectionLvl4_3', 'nixSection'); |
| 877 | + sl44 = sl31.create_section('sectionLvl4_4', 'nixSection'); |
| 878 | + |
| 879 | + sideName = 'sideSubSection'; |
| 880 | + side = f.create_section('sideSection', 'nixSection'); |
| 881 | + side1 = side.create_section(sideName, 'nixSection'); |
| 882 | + |
| 883 | + % find first downstream by id |
| 884 | + rel = sl21.find_related(nix.Filter.id, sl44.id); |
| 885 | + assert(size(rel, 1) == 1); |
| 886 | + |
| 887 | + % find first updstream by ids |
| 888 | + rel = sl33.find_related(nix.Filter.ids, {sl21.id, sl1.id}); |
| 889 | + assert(size(rel, 1) == 1); |
| 890 | + |
| 891 | + % find first downstream by name, one occurrence |
| 892 | + rel = sl21.find_related(nix.Filter.name, 'sectionLvl4_4'); |
| 893 | + assert(size(rel, 1) == 1); |
| 894 | + |
| 895 | + % find first downstream by type, one occurrence |
| 896 | + rel = sl21.find_related(nix.Filter.type, findSectionType); |
| 897 | + assert(size(rel, 1) == 1); |
| 898 | + |
| 899 | + % find first downstream by type, multiple occurrences |
| 900 | + rel = sl31.find_related(nix.Filter.type, findSectionType); |
| 901 | + assert(size(rel, 1) == 2); |
| 902 | + |
| 903 | + % find first upstream by name, one occurrence |
| 904 | + rel = sl31.find_related(nix.Filter.name, 'sectionLvl2_1'); |
| 905 | + assert(size(rel, 1) == 1); |
| 906 | + |
| 907 | + % test fail on nix.Filter.metadata |
| 908 | + err = 'unknown or unsupported filter'; |
| 909 | + try |
| 910 | + sl1.find_related(nix.Filter.metadata, 'metadata'); |
| 911 | + catch ME |
| 912 | + assert(strcmp(ME.message, err)); |
| 913 | + end |
| 914 | + |
| 915 | + % test fail on nix.Filter.source |
| 916 | + try |
| 917 | + sl1.find_related(nix.Filter.source, 'source'); |
| 918 | + catch ME |
| 919 | + assert(strcmp(ME.message, err)); |
| 920 | + end |
| 921 | +end |
0 commit comments