2 % Consistency tests
for the DataTree.IdMapNode
class
5 % - 2. initialize with cell array
6 % - 3. initialize with struct
7 % - 4. initialize with struct in flat mode (default mergefun)
8 % - 5. initialize with struct in flat mode (custom mergefun)
9 % - 5b. overwrite with given DataTree.IdMapNode
object from (3.) in flat
10 % mode with different mergefun than before
14 idmap = {
'a', {
'b', {
'c',
'd'}},
'e'};
16 vals2 =
struct(
'a', 1,
'b', 2,
'c', 3,
'd', 4,
'e', 5);
17 vals2_incomplete =
struct(
'a', 1,
'b', 2,
'd', 4,
'e', 5);
23 ref5b = [1 2.75 2.75 2.75 5]
';
26 ic2 = DataTree.IdMapNode(idmap, vals1);
27 a = get_flat_struct(ic2);
28 vals = structfun(@(x) x, a);
33 ok = ok & scalar(ic2, @(x)mean([x{:}])) == 2;
36 disp(getReport(exception));
42 ic3 = DataTree.IdMapNode(idmap, vals2);
43 a= get_flat_struct(ic3);
44 vals = structfun(@(x) x, a);
49 ok = ok & scalar(ic3, @(x)mean([x{:}])) == mean([1,5,2.75]);
52 disp(getReport(exception));
57 ic4 = DataTree.IdMapNode(idmap, vals2, []);
58 a = get_flat_struct(ic4);
59 vals = structfun(@(x) x, a);
60 ok = ok & all(vals == ref4);
67 disp(getReport(exception));
72 ic5 = DataTree.IdMapNode(idmap, vals2, @(x) max([x{:}]));
73 a = get_flat_struct(ic5);
74 vals = structfun(@(x) x, a);
75 ok = ok & all(vals == ref5a);
76 set(ic5, [], ic3, @(x) mean([x{:}]));
78 disp('Test5a failed
');
81 a = get_flat_struct(ic5);
82 vals = structfun(@(x) x, a);
84 disp('Test5b failed
');
89 disp(getReport(exception));