Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LRT_infinite_dimensional_systems
conI
Commits
d50d0bdc
Commit
d50d0bdc
authored
Dec 02, 2019
by
Ferdinand Fischer
Browse files
Check isempty on quantities (see
#11
,
#17
): Implementation without calling *.on()
parent
62e13d1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
+quantity/Discrete.m
View file @
d50d0bdc
...
...
@@ -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 neede
d
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
=
...
...
...
+unittests/+quantity/testDiscrete.m
View file @
d50d0bdc
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment