|
45 | 45 | funcs{end+1} = @test_set_units;
|
46 | 46 | funcs{end+1} = @test_attrs;
|
47 | 47 | funcs{end+1} = @test_compare;
|
| 48 | + funcs{end+1} = @test_filter_source; |
48 | 49 | end
|
49 | 50 |
|
50 | 51 | %% Test: Add sources by entity and id
|
|
779 | 780 | assert(t2.compare(t1) > 0);
|
780 | 781 | assert(t1.compare(t3) ~= 0);
|
781 | 782 | end
|
| 783 | + |
| 784 | +%% Test: filter sources |
| 785 | +function [] = test_filter_source( varargin ) |
| 786 | + filterName = 'filterMe'; |
| 787 | + filterType = 'filterType'; |
| 788 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 789 | + b = f.create_block('testBlock', 'nixBlock'); |
| 790 | + d = b.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Double, [2 3]); |
| 791 | + t = b.create_multi_tag('testMultiTag', 'nixMultiTag', d); |
| 792 | + s = b.create_source(filterName, 'nixSource'); |
| 793 | + t.add_source(s); |
| 794 | + filterID = s.id; |
| 795 | + s = b.create_source('testSource1', filterType); |
| 796 | + t.add_source(s); |
| 797 | + filterIDs = {filterID, s.id}; |
| 798 | + s = b.create_source('testSource2', filterType); |
| 799 | + t.add_source(s); |
| 800 | + |
| 801 | + % test empty id filter |
| 802 | + assert(isempty(f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.id, 'IdoNotExist'))); |
| 803 | + |
| 804 | + % test nix.Filter.accept_all |
| 805 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.accept_all, ''); |
| 806 | + assert(size(filtered, 1) == 3); |
| 807 | + |
| 808 | + % test nix.Filter.id |
| 809 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.id, filterID); |
| 810 | + assert(size(filtered, 1) == 1); |
| 811 | + assert(strcmp(filtered{1}.id, filterID)); |
| 812 | + |
| 813 | + % test nix.Filter.ids |
| 814 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.ids, filterIDs); |
| 815 | + assert(size(filtered, 1) == 2); |
| 816 | + assert(strcmp(filtered{1}.id, filterIDs{1}) || strcmp(filtered{1}.id, filterIDs{2})); |
| 817 | + |
| 818 | + % test nix.Filter.name |
| 819 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.name, filterName); |
| 820 | + assert(size(filtered, 1) == 1); |
| 821 | + assert(strcmp(filtered{1}.name, filterName)); |
| 822 | + |
| 823 | + % test nix.Filter.type |
| 824 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.type, filterType); |
| 825 | + assert(size(filtered, 1) == 2); |
| 826 | + |
| 827 | + % test nix.Filter.metadata |
| 828 | + mainName = 'testSubSection'; |
| 829 | + mainSource = b.create_source(mainName, 'nixSource'); |
| 830 | + t.add_source(mainSource); |
| 831 | + subName = 'testSubSection1'; |
| 832 | + s = f.create_section(subName, 'nixSection'); |
| 833 | + mainSource.set_metadata(s); |
| 834 | + subID = s.id; |
| 835 | + |
| 836 | + assert(isempty(f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.metadata, 'Do not exist'))); |
| 837 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.metadata, subID); |
| 838 | + assert(size(filtered, 1) == 1); |
| 839 | + assert(strcmp(filtered{1}.name, mainName)); |
| 840 | + |
| 841 | + % test nix.Filter.source |
| 842 | + mainName = 'testSubSource'; |
| 843 | + main = b.create_source(mainName, 'nixSource'); |
| 844 | + t.add_source(main); |
| 845 | + mainID = main.id; |
| 846 | + subName = 'testSubSource1'; |
| 847 | + s = main.create_source(subName, 'nixSource'); |
| 848 | + subID = s.id; |
| 849 | + |
| 850 | + assert(isempty(f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.source, 'Do not exist'))); |
| 851 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.source, subName); |
| 852 | + assert(size(filtered, 1) == 1); |
| 853 | + assert(strcmp(filtered{1}.id, mainID)); |
| 854 | + |
| 855 | + filtered = f.blocks{1}.multiTags{1}.filter_sources(nix.Filter.source, subID); |
| 856 | + assert(size(filtered, 1) == 1); |
| 857 | + assert(strcmp(filtered{1}.name, mainName)); |
| 858 | +end |
0 commit comments