|
41 | 41 | funcs{end+1} = @test_set_metadata;
|
42 | 42 | funcs{end+1} = @test_open_metadata;
|
43 | 43 | funcs{end+1} = @test_retrieve_data_idx;
|
44 |
| - funcs{end+1} = @test_retrieve_feature_data; |
| 44 | + funcs{end+1} = @test_retrieve_feature_data_idx; |
45 | 45 | funcs{end+1} = @test_set_units;
|
46 | 46 | funcs{end+1} = @test_attrs;
|
47 | 47 | funcs{end+1} = @test_compare;
|
|
704 | 704 | end
|
705 | 705 |
|
706 | 706 | %% Test: Retrieve feature data
|
707 |
| -function [] = test_retrieve_feature_data( varargin ) |
708 |
| - % TODO |
709 |
| - disp('Test MultiTag: retrieve feature ... TODO (proper testfile)'); |
| 707 | +function [] = test_retrieve_feature_data_idx( varargin ) |
| 708 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 709 | + b = f.create_block('testBlock', 'nixBlock'); |
| 710 | + |
| 711 | + % create feature data arrays |
| 712 | + raw_feat1 = [11 12 13 14 15 16 17 18]; |
| 713 | + da_feat1 = b.create_data_array_from_data('feature1', 'nixDataArray', raw_feat1); |
| 714 | + da_feat1.append_sampled_dimension(1); |
| 715 | + |
| 716 | + raw_feat2 = [21 22 23 24 25 26 27 28]; |
| 717 | + da_feat2 = b.create_data_array_from_data('feature2', 'nixDataArray', raw_feat2); |
| 718 | + da_feat2.append_sampled_dimension(1); |
| 719 | + |
| 720 | + % create referenced data array |
| 721 | + raw_feat3 = [31 32 33 34 35 36 37 38]; |
| 722 | + da_feat3 = b.create_data_array_from_data('reference', 'nixDataArray', raw_feat3); |
| 723 | + da_feat3.append_sampled_dimension(1); |
| 724 | + |
| 725 | + % create position, extents DA and multi tag |
| 726 | + pos = [0; 3; 5]; |
| 727 | + ext = [1; 1; 3]; |
| 728 | + |
| 729 | + da_pos = b.create_data_array_from_data('positions', 'nixDataArray', pos); |
| 730 | + da_ext = b.create_data_array_from_data('extents', 'nixDataArray', ext); |
| 731 | + |
| 732 | + da_pos.append_sampled_dimension(0); |
| 733 | + da_ext.append_sampled_dimension(0); |
| 734 | + |
| 735 | + t = b.create_multi_tag('testMultiTag', 'nixMultiTag', da_pos); |
| 736 | + t.set_extents(da_ext); |
| 737 | + |
| 738 | + % add feature data_arrays |
| 739 | + t.add_feature(da_feat1, nix.LinkType.Untagged); |
| 740 | + t.add_feature(da_feat2, nix.LinkType.Tagged); |
| 741 | + t.add_feature(da_feat3, nix.LinkType.Indexed); |
| 742 | + |
| 743 | + % test invalid position idx |
| 744 | + try |
| 745 | + t.retrieve_feature_data_idx(100, 1); |
| 746 | + catch ME |
| 747 | + assert(isempty(strfind(ME.message, 'ounds of positions or extents')), ... |
| 748 | + 'Invalid position index failed'); |
| 749 | + end |
| 750 | + assert(exist('ME') == 1, 'Invalid position index fail, error not raised'); |
| 751 | + clear ME; |
| 752 | + |
| 753 | + % test invalid feature idx |
| 754 | + try |
| 755 | + t.retrieve_feature_data_idx(0, 100); |
| 756 | + catch ME |
| 757 | + assert(~isempty(strfind(ME.message, 'out of bounds')), ... |
| 758 | + 'Invalid reference index failed'); |
| 759 | + end |
| 760 | + assert(exist('ME') == 1, 'Invalid reference index fail, error not raised'); |
| 761 | + clear ME; |
| 762 | + |
| 763 | + % test untagged ignores position and returns full data |
| 764 | + retData = t.retrieve_feature_data_idx(100, 0); |
| 765 | + assert(isequal(raw_feat1, retData), 'Untagged fail'); |
| 766 | + |
| 767 | + % test tagged properly applies position and extents |
| 768 | + retData = t.retrieve_feature_data_idx(0, 1); |
| 769 | + assert(isequal(retData, [21]), 'Tagged pos 1 fail'); |
| 770 | + |
| 771 | + retData = t.retrieve_feature_data_idx(1, 1); |
| 772 | + assert(isequal(retData, [24]), 'Tagged pos 2 fail'); |
| 773 | + |
| 774 | + retData = t.retrieve_feature_data_idx(2, 1); |
| 775 | + assert(isequal(retData, [26, 27, 28]), 'Tagged pos 3 fail'); |
| 776 | + |
| 777 | + % test indexed returns first and last index value |
| 778 | + retData = t.retrieve_feature_data_idx(0, 2); |
| 779 | + assert(isequal(retData, raw_feat3(1)), 'Indexed first pos fail'); |
| 780 | + |
| 781 | + retData = t.retrieve_feature_data_idx(7, 2); |
| 782 | + assert(isequal(retData, raw_feat3(end)), 'Indexed last pos fail'); |
| 783 | + |
| 784 | + % test indexed fail when accessing position > length of referenced array |
| 785 | + try |
| 786 | + t.retrieve_feature_data_idx(size(raw_feat3, 2) + 1, 2); |
| 787 | + catch ME |
| 788 | + assert(~isempty(strfind(ME.message, 'than the data stored in the feature')), ... |
| 789 | + 'Indexed out of length fail'); |
| 790 | + end |
| 791 | + assert(exist('ME') == 1, 'Indexed out of length fail, error not raised'); |
| 792 | + clear ME; |
710 | 793 | end
|
711 | 794 |
|
712 | 795 | %% Test: nix.MultiTag has feature by ID
|
|
0 commit comments