Commit d50d0bdc authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Check isempty on quantities (see #11, #17): Implementation without calling *.on()

parent 62e13d1b
......@@ -59,7 +59,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% quantity.Discrete
obj = valueOriginal;
else
% empty object. this is neede for instance, to create
% empty object. this is needed for instance, to create
% quantity.Discrete([]), which is useful for creating default
% values.
obj = quantity.Discrete.empty(size(valueOriginal));
......@@ -1594,8 +1594,18 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% ISEMPTY checks if the quantity object is empty
% empty = isempty(obj)
% check if there is already an object
empty = any(size(obj) == 0) || any(cellfun(@iscell, [obj.grid]));
% check if there is any dimension which is zero
empty = any(size(obj) == 0);
% if the constructor is called without arguments, a
% quantity.Discrete is initialized without an initialization of
% the grid. Thus, the grid is not a cell:
empty = empty || ~iscell(obj(1).grid);
% in order to check this for arrays:
% scalar and array empty check has to be separated because the
% [obj.grid] does only work in the array case.
empty = empty || any(cellfun(@iscell, [obj.grid]));
end % isempty()
......@@ -2288,7 +2298,14 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% end
function s = getPropertyGroups(obj)
s = getPropertyGroups@matlab.mixin.CustomDisplay(obj(1));
% Function to display the correct values
if isempty(obj)
s = getPropertyGroups@matlab.mixin.CustomDisplay(obj);
return;
else
s = getPropertyGroups@matlab.mixin.CustomDisplay(obj(1));
end
if numel(obj) ~= 1
s.PropertyList.valueDiscrete = ...
......
......@@ -1246,9 +1246,16 @@ end
function testIsEmpty(tc)
% create an empty quantity and check if it is empty:
e = quantity.Discrete.empty([5, 0]);
tc.verifyTrue(isempty(e));
%verifyTrue(tc, isempty(quantity.Discrete()))
% create an empty object by calling the constructor without arguements.
tc.verifyTrue(isempty(quantity.Discrete()));
% create a constant quantity.Discrete. This should not be empty:
c = quantity.Discrete(1, 'grid', {}, 'gridName', {});
tc.verifyTrue(~isempty(c));
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment