|
42 | 42 | funcs{end+1} = @test_open_metadata;
|
43 | 43 | funcs{end+1} = @test_retrieve_data;
|
44 | 44 | funcs{end+1} = @test_retrieve_data_idx;
|
| 45 | + funcs{end+1} = @test_retrieve_feature_data; |
45 | 46 | funcs{end+1} = @test_retrieve_feature_data_idx;
|
46 | 47 | funcs{end+1} = @test_set_units;
|
47 | 48 | funcs{end+1} = @test_attrs;
|
|
767 | 768 | assert(isequal(t.retrieve_data_idx(2, 1), raw2(1:2, 3:6)), 'Retrieve pos 3, ref 2 fail');
|
768 | 769 | end
|
769 | 770 |
|
| 771 | +%% Test: Retrieve feature data by id or name |
| 772 | +function [] = test_retrieve_feature_data( varargin ) |
| 773 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 774 | + b = f.create_block('testBlock', 'nixBlock'); |
| 775 | + |
| 776 | + % create feature data arrays |
| 777 | + raw_feat1 = [11 12 13 14 15 16 17 18]; |
| 778 | + da_feat1 = b.create_data_array_from_data('feature1', 'nixDataArray', raw_feat1); |
| 779 | + da_feat1.append_sampled_dimension(1); |
| 780 | + |
| 781 | + raw_feat2 = [21 22 23 24 25 26 27 28]; |
| 782 | + da_feat2 = b.create_data_array_from_data('feature2', 'nixDataArray', raw_feat2); |
| 783 | + da_feat2.append_sampled_dimension(1); |
| 784 | + |
| 785 | + % create referenced data array |
| 786 | + raw_feat3 = [31 32 33 34 35 36 37 38]; |
| 787 | + da_feat3 = b.create_data_array_from_data('reference', 'nixDataArray', raw_feat3); |
| 788 | + da_feat3.append_sampled_dimension(1); |
| 789 | + |
| 790 | + % create position, extents DA and multi tag |
| 791 | + pos = [0; 3; 5]; |
| 792 | + ext = [1; 1; 3]; |
| 793 | + |
| 794 | + da_pos = b.create_data_array_from_data('positions', 'nixDataArray', pos); |
| 795 | + da_ext = b.create_data_array_from_data('extents', 'nixDataArray', ext); |
| 796 | + |
| 797 | + da_pos.append_sampled_dimension(0); |
| 798 | + da_ext.append_sampled_dimension(0); |
| 799 | + |
| 800 | + t = b.create_multi_tag('testMultiTag', 'nixMultiTag', da_pos); |
| 801 | + t.set_extents(da_ext); |
| 802 | + |
| 803 | + % add feature data_arrays |
| 804 | + t.add_feature(da_feat1, nix.LinkType.Untagged); |
| 805 | + t.add_feature(da_feat2, nix.LinkType.Tagged); |
| 806 | + t.add_feature(da_feat3, nix.LinkType.Indexed); |
| 807 | + |
| 808 | + % test invalid position idx |
| 809 | + try |
| 810 | + t.retrieve_feature_data(100, ''); |
| 811 | + catch ME |
| 812 | + assert(isempty(strfind(ME.message, 'ounds of positions or extents')), ... |
| 813 | + 'Invalid position index failed'); |
| 814 | + end |
| 815 | + assert(exist('ME') == 1, 'Invalid position index fail, error not raised'); |
| 816 | + clear ME; |
| 817 | + |
| 818 | + % test invalid name or id |
| 819 | + try |
| 820 | + t.retrieve_feature_data(0, 'I do not exist'); |
| 821 | + catch ME |
| 822 | + assert(~isempty(strfind(ME.message, 'no Feature with the specified name or id')), ... |
| 823 | + 'Invalid reference name failed'); |
| 824 | + end |
| 825 | + assert(exist('ME') == 1, 'Invalid reference name fail, error not raised'); |
| 826 | + clear ME; |
| 827 | + |
| 828 | + % test untagged ignores position and returns full data |
| 829 | + retData = t.retrieve_feature_data(100, da_feat1.name); |
| 830 | + assert(isequal(raw_feat1, retData), 'Untagged fail'); |
| 831 | + |
| 832 | + % test tagged properly applies position and extents |
| 833 | + retData = t.retrieve_feature_data(0, da_feat2.id); |
| 834 | + assert(isequal(retData, [21]), 'Tagged pos 1 fail'); |
| 835 | + |
| 836 | + retData = t.retrieve_feature_data(1, da_feat2.name); |
| 837 | + assert(isequal(retData, [24]), 'Tagged pos 2 fail'); |
| 838 | + |
| 839 | + retData = t.retrieve_feature_data(2, da_feat2.id); |
| 840 | + assert(isequal(retData, [26, 27, 28]), 'Tagged pos 3 fail'); |
| 841 | + |
| 842 | + % test indexed returns first and last index value |
| 843 | + retData = t.retrieve_feature_data(0, da_feat3.id); |
| 844 | + assert(isequal(retData, raw_feat3(1)), 'Indexed first pos fail'); |
| 845 | + |
| 846 | + retData = t.retrieve_feature_data(7, da_feat3.name); |
| 847 | + assert(isequal(retData, raw_feat3(end)), 'Indexed last pos fail'); |
| 848 | + |
| 849 | + % test indexed fail when accessing position > length of referenced array |
| 850 | + try |
| 851 | + t.retrieve_feature_data(size(raw_feat3, 2) + 1, da_feat3.id); |
| 852 | + catch ME |
| 853 | + assert(~isempty(strfind(ME.message, 'than the data stored in the feature')), ... |
| 854 | + 'Indexed out of length fail'); |
| 855 | + end |
| 856 | + assert(exist('ME') == 1, 'Indexed out of length fail, error not raised'); |
| 857 | + clear ME; |
| 858 | +end |
| 859 | + |
770 | 860 | %% Test: Retrieve feature data
|
771 | 861 | function [] = test_retrieve_feature_data_idx( varargin )
|
772 | 862 | f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
|
|
0 commit comments