|
41 | 41 | funcs{end+1} = @test_compare;
|
42 | 42 | funcs{end+1} = @test_filter_section;
|
43 | 43 | funcs{end+1} = @test_filter_property;
|
| 44 | + funcs{end+1} = @test_find_section; |
| 45 | + funcs{end+1} = @test_find_section_filtered; |
44 | 46 | end
|
45 | 47 |
|
46 | 48 | %% Test: Create Section
|
|
734 | 736 | assert(strcmp(ME.message, err));
|
735 | 737 | end
|
736 | 738 | end
|
| 739 | + |
| 740 | +%% Test: Find sections w/o filter |
| 741 | +function [] = test_find_section |
| 742 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 743 | + main = f.create_section('testSection', 'nixSection'); |
| 744 | + sl1 = main.create_section('sectionLvl1', 'nixSection'); |
| 745 | + |
| 746 | + sl21 = sl1.create_section('sectionLvl2_1', 'nixSection'); |
| 747 | + sl22 = sl1.create_section('sectionLvl2_2', 'nixSection'); |
| 748 | + |
| 749 | + sl31 = sl21.create_section('sectionLvl3_1', 'nixSection'); |
| 750 | + sl32 = sl21.create_section('sectionLvl3_2', 'nixSection'); |
| 751 | + sl33 = sl21.create_section('sectionLvl3_3', 'nixSection'); |
| 752 | + |
| 753 | + sl41 = sl31.create_section('sectionLvl4_1', 'nixSection'); |
| 754 | + sl42 = sl31.create_section('sectionLvl4_2', 'nixSection'); |
| 755 | + sl43 = sl31.create_section('sectionLvl4_3', 'nixSection'); |
| 756 | + sl44 = sl31.create_section('sectionLvl4_4', 'nixSection'); |
| 757 | + |
| 758 | + side = f.create_section('sideSection', 'nixSection'); |
| 759 | + side1 = side.create_section('sideSubSection', 'nixSection'); |
| 760 | + |
| 761 | + % Check invalid entry |
| 762 | + err = 'Provide a valid search depth'; |
| 763 | + try |
| 764 | + sl1.find_sections('hurra'); |
| 765 | + catch ME |
| 766 | + assert(strcmp(ME.message, err)); |
| 767 | + end |
| 768 | + |
| 769 | + % find all |
| 770 | + filtered = sl1.find_sections(4); |
| 771 | + assert(size(filtered, 1) == 10); |
| 772 | + |
| 773 | + % find until level 4 |
| 774 | + filtered = sl1.find_sections(3); |
| 775 | + assert(size(filtered, 1) == 10); |
| 776 | + |
| 777 | + % find until level 3 |
| 778 | + filtered = sl1.find_sections(2); |
| 779 | + assert(size(filtered, 1) == 6); |
| 780 | + |
| 781 | + % find until level 2 |
| 782 | + filtered = sl1.find_sections(1); |
| 783 | + assert(size(filtered, 1) == 3); |
| 784 | + |
| 785 | + % find until level 1 |
| 786 | + filtered = sl1.find_sections(0); |
| 787 | + assert(size(filtered, 1) == 1); |
| 788 | +end |
| 789 | + |
| 790 | +%% Test: Find sections with filters |
| 791 | +function [] = test_find_section_filtered |
| 792 | + findSection = 'nixFindSection'; |
| 793 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 794 | + main = f.create_section('testSection', 'nixSection'); |
| 795 | + sl1 = main.create_section('sectionLvl1', 'nixSection'); |
| 796 | + |
| 797 | + sl21 = sl1.create_section('sectionLvl2_1', 'nixSection'); |
| 798 | + sl22 = sl1.create_section('sectionLvl2_2', findSection); |
| 799 | + |
| 800 | + sl31 = sl21.create_section('sectionLvl3_1', findSection); |
| 801 | + sl32 = sl21.create_section('sectionLvl3_2', 'nixSection'); |
| 802 | + sl33 = sl21.create_section('sectionLvl3_3', 'nixSection'); |
| 803 | + |
| 804 | + sl41 = sl31.create_section('sectionLvl4_1', findSection); |
| 805 | + sl42 = sl31.create_section('sectionLvl4_2', 'nixSection'); |
| 806 | + sl43 = sl31.create_section('sectionLvl4_3', 'nixSection'); |
| 807 | + sl44 = sl31.create_section('sectionLvl4_4', 'nixSection'); |
| 808 | + |
| 809 | + sideName = 'sideSubSection'; |
| 810 | + side = f.create_section('sideSection', 'nixSection'); |
| 811 | + side1 = side.create_section(sideName, 'nixSection'); |
| 812 | + |
| 813 | + % test find by id |
| 814 | + filtered = sl1.find_filtered_sections(0, nix.Filter.id, sl41.id); |
| 815 | + assert(isempty(filtered)); |
| 816 | + filtered = sl1.find_filtered_sections(3, nix.Filter.id, sl41.id); |
| 817 | + assert(size(filtered, 1) == 1); |
| 818 | + assert(strcmp(filtered{1}.id, sl41.id)); |
| 819 | + |
| 820 | + % test find by ids |
| 821 | + filterids = {sl1.id, sl41.id}; |
| 822 | + filtered = sl1.find_filtered_sections(0, nix.Filter.ids, filterids); |
| 823 | + assert(size(filtered, 1) == 1); |
| 824 | + filtered = sl1.find_filtered_sections(3, nix.Filter.ids, filterids); |
| 825 | + assert(size(filtered, 1) == 2); |
| 826 | + |
| 827 | + % test find by name |
| 828 | + filtered = sl1.find_filtered_sections(4, nix.Filter.name, sideName); |
| 829 | + assert(isempty(filtered)); |
| 830 | + filtered = sl1.find_filtered_sections(0, nix.Filter.name, sl41.name); |
| 831 | + assert(isempty(filtered)); |
| 832 | + filtered = sl1.find_filtered_sections(3, nix.Filter.name, sl41.name); |
| 833 | + assert(size(filtered, 1) == 1); |
| 834 | + assert(strcmp(filtered{1}.name, sl41.name)); |
| 835 | + |
| 836 | + % test find by type |
| 837 | + filtered = sl1.find_filtered_sections(0, nix.Filter.type, findSection); |
| 838 | + assert(isempty(filtered)); |
| 839 | + filtered = sl1.find_filtered_sections(3, nix.Filter.type, findSection); |
| 840 | + assert(size(filtered, 1) == 3); |
| 841 | + assert(strcmp(filtered{1}.type, findSection)); |
| 842 | + |
| 843 | + % test fail on nix.Filter.metadata |
| 844 | + err = 'unknown or unsupported filter'; |
| 845 | + try |
| 846 | + sl1.find_filtered_sections(1, nix.Filter.metadata, 'metadata'); |
| 847 | + catch ME |
| 848 | + assert(strcmp(ME.message, err)); |
| 849 | + end |
| 850 | + |
| 851 | + % test fail on nix.Filter.source |
| 852 | + try |
| 853 | + sl1.find_filtered_sections(1, nix.Filter.source, 'source'); |
| 854 | + catch ME |
| 855 | + assert(strcmp(ME.message, err)); |
| 856 | + end |
| 857 | +end |
0 commit comments