diff --git a/+quantity/Discrete.m b/+quantity/Discrete.m index 637d810ba3e13bc82a08f0d4190649aeed240b6f..34a0c6cb32c042283936ef402b6df214b93168cf 100644 --- a/+quantity/Discrete.m +++ b/+quantity/Discrete.m @@ -99,9 +99,12 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... % the case if all values are empty. This is required for % the initialization of quantity.Function and % quantity.Symbolic objects - assert( all( cellfun(@isempty, valueOriginal ), 'all' ) || ... - numGridElements(myDomain) == numel(valueOriginal{1}), ... - 'grids do not fit to valueOriginal'); + assert(isempty(myDomain) ... % constant case + || all( cellfun(@isempty, valueOriginal ), 'all' ) ... % empty case + || isequal([myDomain.n], size(valueOriginal{1}, 1 : max(1, numel(myDomain)))) ... % usual case + || (isrow(valueOriginal{1}) && ... % row-vector case (including next line) + isequal([1, myDomain.n], size(valueOriginal{1}, 1 : max(1, numel(myDomain)+1)))), ... + 'grids do not fit to valueOriginal'); % allow initialization of empty objects valueOriginalSize = size(valueOriginal); @@ -2610,13 +2613,15 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... parameters = struct(A); gridSize = A.domain.gridLength(); end - end + end % innerInputNormalizer() q = innerInputNormalizer(b, a); p = innerInputNormalizer(a, b); - end + end % inputNormalizer() + end %% (Static) + methods(Access = protected) function [valDiscrete] = expandValueDiscrete(obj, newDomain) diff --git a/+quantity/Domain.m b/+quantity/Domain.m index 46cb748905f142b54ecc3e96461d98022521e3ba..187f6eac0eee8cb217e9aca186d7f80adcb059bf 100644 --- a/+quantity/Domain.m +++ b/+quantity/Domain.m @@ -191,7 +191,7 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ... function n = numGridElements(obj) % NUMGRIDLEMENTS returns the number of the elements of the grid n = prod([obj.n]); - end + end % numGridElements() function s = gridLength(obj) %GRIDLENGTH number of discretization points for each grid in the diff --git a/+unittests/+quantity/testDiscrete.m b/+unittests/+quantity/testDiscrete.m index 874fe02655cc8188889b864166c03c08e1a0ff33..3f060228c99c7659d94f85d84ee8857382095967 100644 --- a/+unittests/+quantity/testDiscrete.m +++ b/+unittests/+quantity/testDiscrete.m @@ -1333,7 +1333,7 @@ testCase.verifyEqual( on( TZX + XTZ ), on( 2 * TZX ), 'AbsTol', eps ) end -function testInit(testCase) +function testInit(tc) %% z = linspace(0,1).'; t = linspace(0,1,101); @@ -1347,7 +1347,7 @@ a = quantity.Discrete(v, [Z, T]); b = quantity.Discrete(V, [Z, T]); % -verifyTrue(testCase, all(a.on() == b.on(), 'all')); +verifyTrue(tc, all(a.on() == b.on(), 'all')); %% zeta = T.grid; @@ -1355,9 +1355,10 @@ zeta = T.grid; Z = quantity.Domain("z", z); Zeta = quantity.Domain("zeta", zeta); -c = quantity.Discrete(zGrid, [Z, Zeta], 'name', 'a'); -d = quantity.Discrete(zetaGrid', [Z, Zeta], 'name', 'b'); -%TODO write test case, the last line should not work +c = quantity.Discrete(zGrid, [Z, Zeta], 'name', 'a'); % this should work +tc.verifyError(... + @() quantity.Discrete(zetaGrid.', [Z, Zeta], 'name', 'd'), ...% this should not work + ''); end