@@ -7,6 +7,48 @@ function setupClass(testCase)
77 end
88
99 methods (Test )
10+ function testEmptyTable(testCase )
11+ % validate that empty colnames should work if the number of
12+ % columns agree. (Yes, id is not considered a column so the
13+ % height of the dynamic table is still 3 but with zero
14+ % columns).
15+ types .core.TimeIntervals(...
16+ ' description' , ' test dynamic table column' ,...
17+ ' id' , types .hdmf_common.ElementIdentifiers(' data' , (0 : 2 )' ));
18+
19+ % validate that properties checking works (start_time is a
20+ % property of TimeIntervals)
21+ testCase .verifyError(@()types .core.TimeIntervals(...
22+ ' description' , ' test error' , ...
23+ ' start_time' , types .hdmf_common.VectorData( ...
24+ ' description' , ' start time column' , ...
25+ ' data' , (1 : 5 )' ...
26+ )), ...
27+ ' NWB:DynamicTable:CheckConfig:ColumnNamesMismatch' );
28+
29+ % validate that "vectordata" set checking works.
30+ testCase .verifyError(@()types .core.TimeIntervals(...
31+ ' description' , ' test error' , ...
32+ ' randomvalues' , types .hdmf_common.VectorData( ...
33+ ' description' , ' random values' , ...
34+ ' data' , mat2cell(rand(25 ,2 ), repmat(5 , 5 , 1 )))), ...
35+ ' NWB:DynamicTable:CheckConfig:ColumnNamesMismatch' );
36+ end
37+
38+ function testGetNegativeId(testCase )
39+ vector = types .hdmf_common.VectorData(' description' , ' data column' , ' data' , (1 : 10 ) .' );
40+ ids = types .hdmf_common.ElementIdentifiers(' data' , ((-9 ): 0 ) .' );
41+ testtable = types .hdmf_common.DynamicTable( ...
42+ ' description' , ' test table with DynamicTableRegion' , ...
43+ ' colnames' , {' vec' }, ...
44+ ' vec' , vector , ...
45+ ' id' , ids ...
46+ );
47+ for i = 1 : length(vector .data)
48+ testCase .verifyEqual(testtable .getRow(i ), testtable .getRow(ids .data(i ), ' useId' , true ));
49+ end
50+ end
51+
1052 function testNwbToTableWithReferencedTablesAsRowIndices(testCase )
1153 % The default mode for the toTable() method is to return the row indices
1254 % for dynamic table regions. This test verifies that the data type of
@@ -33,7 +75,35 @@ function testNwbToTableWithReferencedTablesAsTableRows(testCase)
3375 testCase .verifyClass(row1colA , ' table' )
3476 testCase .verifyClass(row1colB , ' table' )
3577 end
36-
78+
79+ function toTableNdArrayTest(testCase )
80+ % toTableNdArrayTest Test to table for a plane segmentation table
81+
82+ % Generate fake image_mask data
83+ imaging_shape = [100 , 100 ];
84+ x = imaging_shape(1 );
85+ y = imaging_shape(2 );
86+
87+ n_rois = 20 ;
88+ image_mask = zeros(y , x , n_rois );
89+ for i = 1 : n_rois
90+ start = randi(90 ,2 ,1 );
91+ image_mask(start(1 ): start(1 )+10 , start(2 ): start(2 )+10 , 1 ) = 1 ;
92+ end
93+
94+ % add data to NWB structures
95+ plane_segmentation = types .core.PlaneSegmentation( ...
96+ ' colnames' , {' image_mask' }, ...
97+ ' description' , ' output from segmenting my favorite imaging plane' , ...
98+ ' id' , types .hdmf_common.ElementIdentifiers(' data' , int64(0 : 19 )' ), ...
99+ ' image_mask' , types .hdmf_common.VectorData(' data' , image_mask , ' description' , ' image masks' ) ...
100+ );
101+
102+ T = plane_segmentation .toTable();
103+ testCase .verifyClass(T , ' table' );
104+ testCase .verifySize(T , [n_rois , 2 ]); % 2 columns, id and image_mask
105+ end
106+
37107 function testClearDynamicTable(testCase )
38108 dtr_table = testCase .createDynamicTableWithTableRegionReferences();
39109 types .util.dynamictable.clear(dtr_table )
@@ -186,6 +256,35 @@ function testAddMultipleColumnsThrowsErrorIfAnyExists(testCase)
186256 @() dynamicTable .addColumn(' newColumn' , newColumn , ' columnA' , duplicateColumn ), ...
187257 ' NWB:DynamicTable:AddColumn:ColumnExists' );
188258 end
259+
260+ function testAddDataPipeWithWrongHeightToDynamicTable(testCase )
261+
262+ % Create an expandable table where height equals 2.
263+ dynamicTable = types .hdmf_common.DynamicTable( ...
264+ ' description' , ' test expandable dynamic table' , ...
265+ ' colnames' , {' columnA' }, ...
266+ ' columnA' , types .hdmf_common.VectorData( ...
267+ ' description' , ' 1d expandable column' , ...
268+ ' data' , types .untyped.DataPipe( ...
269+ ' data' , [1 , 2 ], ...
270+ ' maxSize' , Inf )), ...
271+ ' id' , types .hdmf_common.ElementIdentifiers( ...
272+ ' data' , types .untyped.DataPipe( ...
273+ ' data' , int64([0 , 1 ]), ...
274+ ' maxSize' , Inf )));
275+
276+ % Create an expandable column where height equals 3
277+ columnB = types .hdmf_common.VectorData( ...
278+ ' description' , ' 2d expandable column vector' , ...
279+ ' data' , types .untyped.DataPipe( ...
280+ ' data' , 1 : 3 , ...
281+ ' maxSize' , Inf , ...
282+ ' axis' , 1 ));
283+
284+ testCase .verifyError( ...
285+ @() dynamicTable .addColumn(' columnB' , columnB ), ...
286+ ' NWB:DynamicTable:AddColumn:MissingRows' );
287+ end
189288 end
190289
191290 methods (Static , Access = private )
0 commit comments