function OK = mergestructs_test
%mergestructs_test unit test for mergestructs
%See also: mergestructs

clear a b c c0

a.char    = 'a';
a.num     = 1;
a.a       = 'only a has this';
a.struc   = a;

b.char    = 'b';
b.num     = 2;
b.b       = 'only b has this';
b.struc   = b;


OK = [];
%%
try
   c = mergestructs(a,b);
catch
   OK(end+1) = 1;
end
%%
clear c0
c0.char    = 'b';
c0.num     = 2;
c0.a       = a.a;
c0.struc.char = c0.char;
c0.struc.num  = c0.num;
c0.struc.b    = b.b;
c0.b          = b.b;
c = mergestructs('overwrite',a,b);
OK(end+1) = isequal(c,c0);
%%   
try
   c = mergestructs('recursive',a,b);
catch
   OK(end+1) = 1;
end
%%
   
clear c0
c0.char    = 'b';
c0.num     = 2;
c0.a       = a.a;
c0.struc.char = c0.char;
c0.struc.num  = c0.num;
c0.struc.a    = a.a; % !! extra subfield due to 'recursive'
c0.struc.b    = b.b;
c0.b          = b.b;
c = mergestructs('overwrite','recursive',a,b);
OK(end+1) = isequal(c,c0);


