Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
m-unit-tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
m-unit-tests
Commits
1453c9fb
Commit
1453c9fb
authored
10 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Rewrote dassert.
Added comparison of struct and cell arrays (with recursive calls).
parent
a965878f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dassert.m
+39
-20
39 additions, 20 deletions
src/dassert.m
with
39 additions
and
20 deletions
src/dassert.m
+
39
−
20
View file @
1453c9fb
...
...
@@ -25,38 +25,57 @@ else
use_isequal_matlab_builtin
=
0
;
end
[
nA
,
mA
]
=
size
(
A
);
[
nB
,
mB
]
=
size
(
B
);
% Shape.
nA
=
ndims
(
A
);
nB
=
ndims
(
B
);
if
nA
-
nB
error
(
'assert:: Dimensions of compared objects A and B don
''
t match!'
)
end
% Dimensions.
sA
=
size
(
A
);
sB
=
size
(
B
);
% Object type.
cA
=
class
(
A
);
cB
=
class
(
B
);
% Number of elements.
nn
=
prod
(
sA
);
if
mA
-
mB
error
(
'assert:: Dimensions of compared objects A and B don
''
t match!'
)
if
~
(
isequal
(
nA
,
nB
)
&&
isequal
(
sA
,
sB
))
error
(
'
d
assert:: Dimensions of compared objects A and B don
''
t match!'
)
end
if
is
struct
(
B
)
&&
~
isstruct
(
A
)
error
(
'assert:: Compared objects are not of the same type!'
)
if
is
equal
(
cA
,
cB
)
error
(
'
d
assert:: Compared objects are not of the same type!'
)
end
if
iscell
(
B
)
&&
~
iscell
(
A
)
error
(
'assert:: Compared objects are not of the same type!'
)
end
if
use_isequal_matlab_builtin
t
=
isequal
(
A
,
B
);
if
~
t
t
=
isequalwithequalnans
(
A
,
B
);
end
else
t
=
1
;
if
~
(
isstruct
(
B
)
||
iscell
(
B
))
if
isa
(
cA
,
'double'
)
if
use_isequal_matlab_builtin
t
=
isequal
(
A
,
B
);
if
~
t
t
=
isequalwithequalnans
(
A
,
B
);
end
else
if
max
(
abs
(
A
(:)
-
B
(:)))
>
tol
t
=
0
;
end
else
% not yet implemented
t
=
NaN
;
end
elseif
isa
(
cA
,
'cell'
)
rA
=
reshape
(
cA
,
prod
(
sA
),
1
);
rB
=
reshape
(
cB
,
prod
(
sB
),
1
);
for
i
=
1
:
nn
t
=
dassert
(
rA
{
i
},
rB
{
i
},
tol
);
if
~
t
break
end
end
elseif
isa
(
cA
,
'struct'
)
A
=
struct2cell
(
A
);
B
=
struct2cell
(
B
);
t
=
dassert
(
A
,
B
,
tol
);
else
t
=
isequal
(
A
,
B
,
tol
);
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment