de Rigo, D. (2012). Applying semantic constraints to array programming: the module "check_is" of the Mastrave modelling library. Mastrave project technical report. http://mastrave.org/doc/mtv_m/check_is
Applying semantic constraints to array programming: the module "check_is" of the Mastrave modelling library
Copyright and license notice of the function check_is
Copyright © 2005,2006,2007,2008,2009,2010,2011,2012,2013 Daniele de Rigo
The file check_is.m is part of Mastrave.
Mastrave is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Mastrave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Mastrave. If not, see http://www.gnu.org/licenses/.
Function declaration
[answer, msg, must] = check_is( obj , obj_type , msg = '' , ... )
Description
Module for checking whether the variable obj belongs to the category obj_type . obj_type categories implement the concept of semantic array-based constraints on which the paradigm of Semantic Array Programming is based.
The behaviour of the function depends on the number of output arguments.
If nargout==0 , then if the check ends succesfully, the module returns to the caller. Otherwise, an error is thrown displaying a message whose format is msg .
If nargout==1 , then the module returns a boolean value answer which is true if the check ends succesfully, false otherwise.
If nargout==2 , then the module returns the boolean answer as in the previous case, along with an error message whose format is msg (the messege is an empty string if the check ends succesfully).
If nargout==3 , the module returns answer and msg as in the previous case, along with the struct must whose fields contain the constraints to be satisfied.
If other arguments are passed after msg , they are managed like the optional arguments in the function @sprintf (see the help of @sprintf for more details about the format of msg and the optional arguments).
The semantic constraints associated to each input argument and documented within the help of all Mastrave functions are implemented by invoking this function.
Representation of semantic constraints
In order for a function to be compliant with the Mastrave coding standards, it must explicitly express (and document) a set of semantic constraints for each of its input arguments and optionally for its output arguments. Semantic constraints take the form of a sequence of categories between :: . The special token :: is used as "quotation" delimiter of the semantic constraints which are expected to be delimited by :: both as prefix and suffix. The general documentation syntax is:
argument_name ::semantic constraints::
Documentation describing the argument
argument_name and the reason why its
semantic constraints ought to hold.
where ::semantic constraint:: is a generic placeholder which actually
stays for one or more of the categories described in the following
section "Input arguments".
The role of the category obj_type for the variable obj could be
formalized within the deontic logic. In case to obj a single category
is applied, the category can be interpreted as a necessity.
If obj_type value is ::p::, then for obj it must hold the deontic
logic proposition (basic unary modal operators ☐ and ◇ are here used):
☐ p % it ought to be that p
(Beware that the label ::p::, and in the following the label ::q::, are used as generic placeholders, so that neither ::p:: nor ::q:: are valid constraints.) A consequence of ::p:: is that:
not ( ◇ not(p) )
% it is not permissible that not-p
meaning that if the semantic constraint ::p:: - which we suppose to be required e.g. for a given input argument of a certain module - is not satisfied, then it is not permissible that module's execution to be continued.
If obj_type value is ::p,q::, then for obj it must hold the deontic
logic proposition:
( ☐ p ) and ( ☐ q ) % it ought to be both that p and q
a consequence of it is that:
not ( ◇ not(p) ) or not ( ◇ not(q) )
% it is not permissible that either not-p or not-q
If obj_type value is ::p|q::, then for obj it must hold the deontic
logic proposition:
( ☐ p ) or ( ☐ q ) % it ought to be either p or q
whose consequence is that:
( ◇ not(p) ) and ( ◇ not(q) ) and not ( ◇ ( not(p) and not(q) ) )
% not-p and not-q are both permissible,
% however it is not permissible that neither p nor q
An accurate (despite possibly inefficient) implementation of the
previous deontic logic propositions on obj may be obtained by
replacing each atomic proposition:
☐ p
with the call to @check_is:
T = check_is( obj , ::p:: , '' )
so that e.g. the semantic constraint ::p|q:: on obj can be implemented as:
T1 = check_is( obj , ::p:: , '' )
T2 = check_is( obj , ::q:: , '' )
T = check_is( T1 | T2 , ::true:: , '' )
The validity of the aggregated check result T must hold.
Input arguments
obj ::generic:: Object on which to check the obj_type constraint. obj_type ::generic|row_string:: Constraint to be checked. Follows here a list of the implemented categories for obj_type : obj_type value │ constraint to verify ──────────────────────────┼──────────────────────────────────────────────── model │ class( obj ) must be the same as │ class( model ) and if model is a cell-array │ or a struct, each element of model must │ recursively have the same class of the │ corresponding element of obj . │ model cannot be a string: if you need to │ check if obj is a string, use instead │ something like: │ check_is( obj , 'string' , ... │ 'must be a string!' ) │ Only the classes of the (element composing the) │ object are compared. As a consequence, the │ numeric or string values and also the size of │ a given array element of obj may not imply │ a matching failure, provided that the class of │ the corresponding element of model is the │ same. However, in case the class of that │ element is a container of heterogeneous items │ (e.g. a cell-array of a struct), then the size │ of the element is considered. This is because │ the i-th item of the obj element has to be │ checked for ensuring its class is the same of │ the one of the i-th item of the corresponding │ element of model . As a general rule, │ heterogeneous containers are checked item by │ item, while homogeneous containters (e.g. │ ordinary arrays) are not. ──────────────────────────┼──────────────────────────────────────────────── 'generic', │ Synonym of: logical( 1 ) 'anything' │ Rationale: to provide an always-passing test. ──────────────────────────┼──────────────────────────────────────────────── 'nothing' │ Synonym of: logical( 0 ) │ Rationale: to provide an always-failing test. ──────────────────────────┼──────────────────────────────────────────────── 'true' │ Synonym of: logical( obj ) │ Rationale: to enable generic logical test in │ case no one of the supported specific tests │ applies. ──────────────────────────┼──────────────────────────────────────────────── 'false' │ Synonym of: ~logical( obj ) │ Rationale: to enable generic logical test in │ case no one of the supported specific tests │ applies. ──────────────────────────┼──────────────────────────────────────────────── 'any' │ Synonym of: isnumeric( obj ) & ... │ any( obj (:) ) ──────────────────────────┼──────────────────────────────────────────────── 'all' │ Synonym of: isnumeric( obj ) & ... │ all( obj (:) ) ──────────────────────────┼──────────────────────────────────────────────── 'logical' │ Synonym of: islogical( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'binary' │ Synonym of: islogical( obj ) | ( ... │ isnumeric( obj ) & ... │ all( obj (:) == ... │ logical( obj (:)) ) ) ──────────────────────────┼──────────────────────────────────────────────── 'numeric' │ Synonym of: isnumeric( obj ) | ... │ islogical( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'real' │ Synonym of: isnumeric( obj ) | ... │ islogical( obj ) & ... │ ~any(imag( obj (:)) ) ──────────────────────────┼──────────────────────────────────────────────── 'finite' │ obj must be ::numeric:: and its elements │ must have finite values so that no infinite │ nor NaN elements are allowed. ──────────────────────────┼──────────────────────────────────────────────── 'nanless' │ obj must be ::numeric:: and its elements' │ value cannot be NaN. │ Example of usage: to provide algorithms relaing │ on operators whose use may be problematic when │ dealing with NaN values (e.g. statistics such │ as @var, scan operators such as @cumsum, ... ) │ with a default check for ensuring input data │ have been properly pre-processed. ──────────────────────────┼──────────────────────────────────────────────── 'nonzero' │ obj must be ::numeric:: and its elements' │ value cannot be zero. ──────────────────────────┼──────────────────────────────────────────────── 'numstring' │ Synonym of: ischar( obj ) | ... │ isnumeric( obj ) | ... │ islogical( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'realstring' │ Synonym of: ischar( obj ) | (... │ isnumeric( obj ) | ... │ islogical( obj ) & ... │ ~any(imag( obj (:)) ) ) ──────────────────────────┼──────────────────────────────────────────────── 'char' , │ Synonym of: ischar( obj ) 'string' │ ──────────────────────────┼──────────────────────────────────────────────── 'row_string' │ obj must be a one-row string. ──────────────────────────┼──────────────────────────────────────────────── 'varname' │ Synonym of: ischar( obj ) & ... │ isvarname( obj ) & ... │ obj (1) ~= '_' │ Rationale: to ensure obj is a portable │ variable name. ──────────────────────────┼──────────────────────────────────────────────── 'format_string' │ obj must be a valid format string for the │ *printf family of functions. ──────────────────────────┼──────────────────────────────────────────────── 'regexp' │ obj must be a valid regular expression for │ the regex* family of functions. ──────────────────────────┼──────────────────────────────────────────────── 'cell' │ Synonym of: iscell( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'struct' │ Synonym of: isstruct( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'sparse' │ Synonym of: issparse( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'full' │ Synonym of: ~issparse( obj ) 'nonsparse' │ ──────────────────────────┼──────────────────────────────────────────────── 'function_handle' │ Synonym of: isa( obj , 'function_handle' ) 'funhandle' │ 'func' │ ──────────────────────────┼──────────────────────────────────────────────── 'strfunhandle' │ Synonym of: ischar( obj ) | ... 'strfunc' │ isa( obj , 'function_handle' ) ──────────────────────────┼──────────────────────────────────────────────── 'numfunhandle' │ Synonym of: isnumeric( obj ) | ... 'numfunc' │ islogical( obj ) | ... │ isa( obj , 'function_handle' ) ──────────────────────────┼──────────────────────────────────────────────── 'numstrfunhandle' │ Synonym of: isnumeric( obj ) | ... 'numstrfunc' │ islogical( obj ) | ... │ ischar( obj ) | ... │ isa( obj , 'function_handle' ) ──────────────────────────┼──────────────────────────────────────────────── 'int8' │ Synonym of: isa( obj , 'int8' ) ──────────────────────────┼──────────────────────────────────────────────── 'uint8' │ Synonym of: isa( obj , 'uint8' ) ──────────────────────────┼──────────────────────────────────────────────── 'int16' │ Synonym of: isa( obj , 'int16' ) ──────────────────────────┼──────────────────────────────────────────────── 'uint16' │ Synonym of: isa( obj , 'uint16' ) ──────────────────────────┼──────────────────────────────────────────────── 'int32' │ Synonym of: isa( obj , 'int32' ) ──────────────────────────┼──────────────────────────────────────────────── 'uint32' │ Synonym of: isa( obj , 'uint32' ) ──────────────────────────┼──────────────────────────────────────────────── 'tileable' │ obj must be ::numeric:: or a ::char:: or a cell │ array or a struct. │ Rationale: to ensure obj can be tiled, e.g. │ using repmat( obj , .. ). ──────────────────────────┼──────────────────────────────────────────────── 'numcellstring' │ obj must be ::numeric:: or a ::char:: or a cell 'sortable' │ array whose elements obj_type must be │ ::char:: . │ Rationale: to ensure obj can be sorted, e.g. │ using sort( obj , .. ). ──────────────────────────┼──────────────────────────────────────────────── 'realcellstring' │ obj must be ::real:: or a ::char:: or a cell 'tsortable' │ array whose elements obj_type must be │ ::char:: . │ Rationale: to ensure obj can be sorted, e.g. │ using sort( obj , .. ), with the guarantee │ of total-order. This excludes complex numbers │ with nonzero imaginary part. ──────────────────────────┼──────────────────────────────────────────────── 'sorted' │ obj must be sorted in either ascending or │ descending order. ──────────────────────────┼──────────────────────────────────────────────── 'sorted-ascend' │ obj must be sorted in ascending order. ──────────────────────────┼──────────────────────────────────────────────── 'sorted-descend' │ obj must be sorted in descending order. ──────────────────────────┼──────────────────────────────────────────────── 'row_elems' │ obj must be a row-vector or a cell array │ whose elements must be row-vectors. ──────────────────────────┼──────────────────────────────────────────────── 'cellstring' │ obj must be a ::char:: or a cell array whose │ elements obj_type must be ::char:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellstring-r' │ obj must be a ::char:: or a cell array whose │ elements obj_type must be ::cellstring-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellstring-1' │ obj must be a cell array of ::char:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellstring-2' │ obj must be a cell array of cell arrays of │ ::char:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumeric' │ obj must be ::numeric:: or a cell array whose │ elements obj_type must be ::numeric:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumeric-r' │ obj must be ::numeric:: or a cell array whose │ elements obj_type must be │ ::cellnumeric-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumeric-1' │ obj must be a cell array of ::numeric:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumeric-2' │ obj must be a cell array of cell arrays of │ ::numeric:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellfinite' │ obj must be ::finite:: or a cell array whose │ elements obj_type must be ::finite:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellfinite-r' │ obj must be ::finite:: or a cell array whose │ elements obj_type must be │ ::cellfinite-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellfinite-1' │ obj must be a cell array of ::finite:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellfinite-2' │ obj must be a cell array of cell arrays of │ ::finite:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnanless' │ obj must be ::nanless:: or a cell array whose │ elements obj_type must be ::nanless:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnanless-r' │ obj must be ::nanless:: or a cell array whose │ elements obj_type must be │ ::cellnanless-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnanless-1' │ obj must be a cell array of ::nanless:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnanless-2' │ obj must be a cell array of cell arrays of │ ::nanless:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnonzero' │ obj must be ::nonzero:: or a cell array whose │ elements obj_type must be ::nonzero:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnonzero-r' │ obj must be ::nonzero:: or a cell array whose │ elements obj_type must be │ ::cellnonzero-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnonzero-1' │ obj must be a cell array of ::nonzero:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnonzero-2' │ obj must be a cell array of cell arrays of │ ::nonzero:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellint' │ obj must be integer or a cell array whose │ elements obj_type must be integers. ──────────────────────────┼──────────────────────────────────────────────── 'cellint-r' │ obj must be integers or a cell array whose │ elements obj_type must be ::cellint-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellint-1' │ obj must be a cell array of integers. ──────────────────────────┼──────────────────────────────────────────────── 'cellint-2' │ obj must be a cell array of cell arrays of │ integers. ──────────────────────────┼──────────────────────────────────────────────── 'cellscalar' │ obj must be a scalar or a cell array whose │ elements obj_type must be scalars. ──────────────────────────┼──────────────────────────────────────────────── 'cellscalar-r' │ obj must be a scalar or a cell array whose │ elements obj_type must be ::cellscalar-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellscalar-1' │ obj must be a cell array of scalars. ──────────────────────────┼──────────────────────────────────────────────── 'cellscalar-2' │ obj must be a cell array of cell arrays of │ scalars. ──────────────────────────┼──────────────────────────────────────────────── 'cellvector' │ obj must be a vector or a cell array whose │ elements obj_type must be vectors. ──────────────────────────┼──────────────────────────────────────────────── 'cellvector-r' │ obj must be a vector or a cell array whose │ elements obj_type must be ::cellvector-r::. ──────────────────────────┼──────────────────────────────────────────────── 'cellvector-1' │ obj must be a cell array of vectors. ──────────────────────────┼──────────────────────────────────────────────── 'cellvector-2' │ obj must be a cell array of cell arrays of │ vectors. ──────────────────────────┼──────────────────────────────────────────────── 'cellmatrix' │ obj must be a matrix or a cell array whose │ elements obj_type must be matrices. ──────────────────────────┼──────────────────────────────────────────────── 'cellmatrix-r' │ obj must be a matrix or a cell array whose │ elements obj_type must be ::cellmatrix-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellmatrix-1' │ obj must be a cell array of matrices. ──────────────────────────┼──────────────────────────────────────────────── 'cellmatrix-2' │ obj must be a cell array of cell arrays of │ matrices. ──────────────────────────┼──────────────────────────────────────────────── 'cell3-array' │ obj must be a ::3-array:: or a cell array │ whose elements obj_type must be 3-arrays. ──────────────────────────┼──────────────────────────────────────────────── 'cell3-array-r' │ obj must be a ::3-array:: or a cell array │ whose elements obj_type must be │ ::cell3-array-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cell3-array-1' │ obj must be a cell array of ::3-arrays:: . ──────────────────────────┼──────────────────────────────────────────────── 'cell3-array-2' │ obj must be a cell array of cell arrays of │ ::3-array:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellreal' │ obj must be ::real:: or a cell array whose │ elements obj_type must be ::real:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellreal-r' │ obj must be ::real:: or a cell array whose │ elements obj_type must be ::cellreal-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellreal-1' │ obj must be a cell array of ::real:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellreal-2' │ obj must be a cell array of cell arrays of │ ::real:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumstring' │ obj must be ::numstring:: or a cell array │ whose elements obj_type must be │ ::numstring:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumstring-r' │ obj must be ::numstring:: or a cell array │ whose elements obj_type must be │ ::cellnumstring-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumstring-1' │ obj must be a cell array of ::numstring::. ──────────────────────────┼──────────────────────────────────────────────── 'cellnumstring-2' │ obj must be a cell array of cell arrays of │ ::numstring::. ──────────────────────────┼──────────────────────────────────────────────── 'cellrealstring' │ obj must be ::realstring:: or a cell array │ whose elements obj_type must be │ ::realstring:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellrealstring-r' │ obj must be ::realstring:: or a cell array │ whose elements obj_type must be │ ::cellrealstring-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellrealstring-1' │ obj must be a cell array of ::realstring:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellrealstring-2' │ obj must be a cell array of cell arrays of │ ::realstring:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellfunhandle' │ obj must be a function handle or a cell │ array whose elements obj_type must be │ function handles. ──────────────────────────┼──────────────────────────────────────────────── 'cellfunhandle-r' │ obj must be a function handle or a cell │ array whose elements obj_type must be │ ::cellfunhandle-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellfunhandle-1' │ obj must be a cell array of function │ handles. ──────────────────────────┼──────────────────────────────────────────────── 'cellfunhandle-2' │ obj must be a cell array of cell arrays of │ function handles. ──────────────────────────┼──────────────────────────────────────────────── 'cellindex' │ obj must be ::index:: or a cell array whose │ elements obj_type must be ::index:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellindex-r' │ obj must be ::index:: or a cell array whose │ elements obj_type must be ::cellindex-r::. ──────────────────────────┼──────────────────────────────────────────────── 'cellindex-1' │ obj must be a cell array of ::index:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellindex-2' │ obj must be a cell array of cell arrays of │ ::index:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumel' │ obj must be ::numel:: or a cell array whose │ elements obj_type must be ::numel:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumel-r' │ obj must be ::numel:: or a cell array whose │ elements obj_type must be ::cellnumel-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumel-1' │ obj must be a cell array of ::numel:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnumel-2' │ obj must be a cell array of cell arrays of │ ::numel:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellprob' │ obj must be of ::probability:: or a cell │ array whose elements obj_type must be │ ::probability:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellprob-r' │ obj must be of ::probability:: or a cell │ array whose elements obj_type must be │ ::cellprob-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellprob-1' │ obj must be a cell array of ::probability:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellprob-2' │ obj must be a cell array of cell arrays of │ ::probability:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellempty' │ obj must be empty or a cell array whose │ elements must be empty. ──────────────────────────┼──────────────────────────────────────────────── 'cellempty-c' │ obj must be empty or a cell array whose │ elements must be empty. │ If obj is a cell array, it is not checked │ if it is empty but only if its elements are │ empty. Status: sperimental. ──────────────────────────┼──────────────────────────────────────────────── 'cellempty-r' │ obj must be empty or a cell array whose │ elements obj_type must be ::cellempty-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellempty-1' │ obj must be a cell array of empty elements. ──────────────────────────┼──────────────────────────────────────────────── 'cellempty-2' │ obj must be a cell array of cell arrays of │ empty elements. ──────────────────────────┼──────────────────────────────────────────────── 'cellnonempty' │ obj must be empty or a cell array whose │ elements cannot be empty. ──────────────────────────┼──────────────────────────────────────────────── 'cellnonempty-c' │ obj must be empty or a cell array whose │ elements cannot be empty. │ If obj is a cell array, it is not checked │ if it is non-empty but only if its elements │ are non-empty. Status: sperimental. ──────────────────────────┼──────────────────────────────────────────────── 'cellnonempty-r' │ obj must be ::nonempty:: or a cell array │ whose elements obj_type must be │ ::cellnonempty-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellnonempty-1' │ obj must be a cell array of ::nonempty:: │ elements. ──────────────────────────┼──────────────────────────────────────────────── 'cellnonempty-2' │ obj must be a cell array of cell arrays of │ ::nonempty:: elements. ──────────────────────────┼──────────────────────────────────────────────── 'cellscalempty' │ obj must be ::scalempty:: or a cell array │ whose elements obj_type must be │ ::scalempty:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellscalempty-c' │ obj must be ::scalempty:: or a cell array │ whose elements obj_type must be │ ::scalempty:: . │ If obj is a cell array, it is not checked │ if it is ::scalempty:: but only if its │ elements are scalempty. Status: sperimental. ──────────────────────────┼──────────────────────────────────────────────── 'cellscalempty-r' │ obj must be ::scalempty:: or a cell array │ whose elements obj_type must be │ ::cellscalempty-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellscalempty-1' │ obj must be a cell array of ::scalempty:: │ elements. ──────────────────────────┼──────────────────────────────────────────────── 'cellscalempty-2' │ obj must be a cell array of cell arrays of │ ::scalempty:: elements. ──────────────────────────┼──────────────────────────────────────────────── 'cellxorempty' │ obj must be a non-cell-array or a cell array │ whose elements obj_type must be all empty or │ all ::nonempty:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellxorempty-c' │ obj must be a non-cell-array or a cell array │ whose elements obj_type must be ::xorempty:: │ which means all empty or all ::nonempty:: . │ If obj is a cell array, it is not checked │ if it is ::xorempty:: but only if its │ elements are ::xorempty:: . │ Status: sperimental. ──────────────────────────┼──────────────────────────────────────────────── 'cellxorempty-r' │ obj must be a non-cell-array or a cell array │ whose elements obj_type must be all empty │ or all ::cellnonempty-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellxorempty-1' │ obj must be a cell array whose elements must │ be all empty or all ::nonempty:: . ──────────────────────────┼──────────────────────────────────────────────── 'cellxorempty-2' │ obj must be a cell array of cell arrays │ whose elements must be all empty or all │ ::nonempty:: . ──────────────────────────┼──────────────────────────────────────────────── 'celltileable' │ obj must be ::tileable:: or a cell array │ whose elements obj_type must be │ ::tileable:: . ──────────────────────────┼──────────────────────────────────────────────── 'celltileable-c' │ obj must be ::tileable:: or a cell array │ whose elements obj_type must be │ ::tileable:: . │ If obj is a cell array, it is not checked │ if it is ::tileable:: but only if its │ elements are ::tileable:: . ──────────────────────────┼──────────────────────────────────────────────── 'celltileable-r' │ obj must be ::tileable:: or a cell array │ whose elements obj_type must be │ ::celltileable-r:: . ──────────────────────────┼──────────────────────────────────────────────── 'celltileable-1' │ obj must be a cell array of ::tileable:: . ──────────────────────────┼──────────────────────────────────────────────── 'celltileable-2' │ obj must be a cell array of cell arrays of │ ::tileable:: . ──────────────────────────┼──────────────────────────────────────────────── 'same_rows' │ obj must be a cell array of objects, each of │ them having the same number of rows. ──────────────────────────┼──────────────────────────────────────────────── 'same_columns' │ obj must be a cell array of objects, each of │ them having the same number of columns. ──────────────────────────┼──────────────────────────────────────────────── 'same_length' │ obj must be a cell array of objects, each of │ them having the same length. ──────────────────────────┼──────────────────────────────────────────────── 'same_size' │ obj must be a cell array of objects, each of │ them having the same size. ──────────────────────────┼──────────────────────────────────────────────── 'same_ndims' │ obj must be a cell array of objects, each of │ them having the same number of dimensions. ──────────────────────────┼──────────────────────────────────────────────── 'same_numel' │ obj must be a cell array of objects, each of │ them having the same number of elements. ──────────────────────────┼──────────────────────────────────────────────── 'same_vals' │ obj must be a cell array of objects, each of │ them equal to all other ones. Not-a-number │ values (nan) are never equal each others. ──────────────────────────┼──────────────────────────────────────────────── 'same_valnans' │ obj must be a cell array of objects, each of │ them equal to all other ones. Not-a-number │ values (nan) are always equal each others. ──────────────────────────┼──────────────────────────────────────────────── 'comparable' │ obj must be a cell array of objects, each of │ them must be comparable with the other using │ the operator == . ──────────────────────────┼──────────────────────────────────────────────── 'multipliable' │ obj must be a cell array of objects, each of │ them must be multipliable with the next one │ using the usual matrix product. ──────────────────────────┼──────────────────────────────────────────────── 'positive' │ obj must be numeric and each of its elements │ must be greater than zero. ──────────────────────────┼──────────────────────────────────────────────── 'nonpositive' │ obj must be numeric and each of its elements │ must be less or equal to zero. ──────────────────────────┼──────────────────────────────────────────────── 'negative' │ obj must be numeric and each of its elements │ must be less than zero. ──────────────────────────┼──────────────────────────────────────────────── 'nonnegative' │ obj must be numeric and each of its elements │ must be greater or equal to zero. ──────────────────────────┼──────────────────────────────────────────────── 'probability' │ obj must be of real values each of them 'possibility' │ being greater or equal to zero and less or 'proportion' │ equal to one. │ Rationale: to ensure all obj elements lie │ in the interval [0 1] and therefore are │ suitable to be interpreted as probabilities, │ fuzzy possibilities. ──────────────────────────┼──────────────────────────────────────────────── 'versor_coord-L1' │ obj must be a matrix of real values each │ such that: │ sum( abs( obj ) , 2 ) == 1. │ Rationale: to ensure obj is suitable to be │ interpreted as a versor in L-1 space (L-1 │ norm is also known as Manhattan distance). ──────────────────────────┼──────────────────────────────────────────────── 'versor_coord-L2' │ obj must be a matrix of real values each │ such that: │ sum( obj .^2 , 2 ) == 1. │ Rationale: to ensure obj is suitable to be │ interpreted as a versor in L-2 space (L-2 │ norm is also known as Euclidean distance). ──────────────────────────┼──────────────────────────────────────────────── 'versor_coord-Linf' │ obj must be a matrix of real values each │ such that: │ max( obj , [] , 2 ) == 1. │ Rationale: to ensure obj is suitable to be │ interpreted as a versor in L-infinite space │ (L-infinite norm is also known as Maximum │ distance). ──────────────────────────┼──────────────────────────────────────────────── 'integer' │ obj must be numeric and each of its elements │ must be convertible to an integer without loss │ of information. ──────────────────────────┼──────────────────────────────────────────────── 'natural' │ obj must be numeric and each of its elements 'numel' │ must be convertible to a non-negative integer │ without loss of information. │ Rationale: to ensure obj can represent the │ result of a (set of) count(s). ──────────────────────────┼──────────────────────────────────────────────── 'natural_nonzero' │ obj must be numeric and each of its elements 'index' │ must be convertible to a positive integer │ without loss of information. │ Rationale: to ensure obj can represent a │ valid (set of) index(indices). ──────────────────────────┼──────────────────────────────────────────────── 'empty' │ Synonim of: numel( obj )==0 ──────────────────────────┼──────────────────────────────────────────────── 'nonempty' │ Synonim of: numel( obj )~=0 ──────────────────────────┼──────────────────────────────────────────────── 'scalempty' │ Synonym of: numel( obj )<=1 ──────────────────────────┼──────────────────────────────────────────────── 'scalar' │ Synonym of: numel( obj )==1 '1-vector' │ ──────────────────────────┼──────────────────────────────────────────────── '2-vector' │ Synonym of: numel( obj )==2 ──────────────────────────┼──────────────────────────────────────────────── '3-vector' │ Synonym of: numel( obj )==3 ──────────────────────────┼──────────────────────────────────────────────── 'n-vectors' │ obj must be a cell-array whose first element '[n]-vectors' │ n = obj {1} │ is a scalar or an array with the same number │ of elements of numel( obj )-1 . │ The number of elements of each object passed │ as cell-element of obj (2:end) must be │ exactly equal to the (corresponding) value(s) │ of n . │ Synonym of: │ cellfun( @numel, obj (2:end) ) == n ──────────────────────────┼──────────────────────────────────────────────── 'n]-vectors' │ obj must be a cell-array whose first element │ n = obj {1} │ is a scalar or an array with the same number │ of elements of numel( obj )-1 . │ The number of elements of each object passed │ as cell-element of obj (2:end) must be │ less or equal to the (corresponding) value(s) │ of n . │ Synonym of: │ cellfun( @numel, obj (2:end) ) <= n ──────────────────────────┼──────────────────────────────────────────────── '[n-vectors' │ obj must be a cell-array whose first element │ n = obj {1} │ is a scalar or an array with the same number │ of elements of numel( obj )-1 . │ The number of elements of each object passed │ as cell-element of obj (2:end) must be │ greater or equal to the (corresponding) │ value(s) of n . │ Synonym of: │ cellfun( @numel, obj (2:end) ) >= n ──────────────────────────┼──────────────────────────────────────────────── 'n[-vectors' │ obj must be a cell-array whose first element │ n = obj {1} │ is a scalar or an array with the same number │ of elements of numel( obj )-1 . │ The number of elements of each object passed │ as cell-element of obj (2:end) must be │ strictly less than the (corresponding) │ value(s) of n . │ Synonym of: │ cellfun( @numel, obj (2:end) ) < n ──────────────────────────┼──────────────────────────────────────────────── ']n-vectors' │ obj must be a cell-array whose first element │ n = obj {1} │ is a scalar or an array with the same number │ of elements of numel( obj )-1 . │ The number of elements of each object passed │ as cell-element of obj (2:end) must be │ strictly greater than the (corresponding) │ value(s) of n . │ Synonym of: │ cellfun( @numel, obj (2:end) ) > n ──────────────────────────┼──────────────────────────────────────────────── '{}-numeric' │ obj must be a cell-array whose first element │ valid = obj {1} │ is an array of admissible numbers and the │ following elements obj (2:end) are numeric │ arrays composed only by admissible numbers. ──────────────────────────┼──────────────────────────────────────────────── '{}-numstring' │ obj must be a cell-array whose first element │ valid = obj {1} │ is an array of admissible numbers or a │ cell-array of ::numstring:: (numeric arrays or │ strings) and the following elements │ obj (2:end) │ are ::numstring:: composed only by admissible │ numbers or strings. ──────────────────────────┼──────────────────────────────────────────────── '{}-function_handle' │ '{}-funhandle' │ '{}-func' │ ──────────────────────────┼──────────────────────────────────────────────── '{}-strfunhandle' │ '{}-strfunc' │ ──────────────────────────┼──────────────────────────────────────────────── '{}-numfunhandle' │ '{}-numfunc' │ ──────────────────────────┼──────────────────────────────────────────────── '{}-numstrfunhandle' │ '{}-numstrfunc' │ ──────────────────────────┼──────────────────────────────────────────────── 'scalar_numeric' │ Synonym of: numel( obj )==1 && ... │ isnumeric( obj ) || ... │ islogical( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'scalar_real' │ Synonym of: numel( obj )==1 && ... │ isnumeric( obj ) || ... │ islogical( obj ) && ... │ ~any(imag( obj (:)) ) ──────────────────────────┼──────────────────────────────────────────────── 'scalar_numstring' │ Synonym of: numel( obj )==1 && ... │ ischar( obj ) || ... │ isnumeric( obj ) || ... │ islogical( obj ) ──────────────────────────┼──────────────────────────────────────────────── 'scalar_realstring' │ Synonym of: numel( obj )==1 && ... │ ischar( obj ) || (... │ isnumeric( obj ) || ... │ islogical( obj ) && ... │ ~any(imag( obj (:)) ) ) ──────────────────────────┼──────────────────────────────────────────────── 'scalar_positive' │ obj must be scalar, numeric, greater than │ zero. ──────────────────────────┼──────────────────────────────────────────────── 'scalar_nonpositive' │ obj must be scalar, numeric, less or equal to │ zero. ──────────────────────────┼──────────────────────────────────────────────── 'scalar_negative' │ obj must be scalar, numeric, less than zero. ──────────────────────────┼──────────────────────────────────────────────── 'scalar_nonnegative' │ obj must be scalar, numeric, greater or │ equal to zero. ──────────────────────────┼──────────────────────────────────────────────── 'scalar_integer' │ obj must be scalar, numeric and convertible │ to an integer without loss of information. ──────────────────────────┼──────────────────────────────────────────────── 'scalar_natural' │ obj must be scalar, numeric and convertible 'scalar_numel' │ to a non-negative integer without loss of │ information. ──────────────────────────┼──────────────────────────────────────────────── 'scalar_natural_nonzero' │ obj must be scalar, numeric and convertible 'scalar_index' │ to a positive integer without loss of │ information. ──────────────────────────┼──────────────────────────────────────────────── 'vector' │ obj must be a row or column vector. ──────────────────────────┼──────────────────────────────────────────────── 'row_vector' │ obj must be a row vector. ──────────────────────────┼──────────────────────────────────────────────── 'col_vector' │ obj must be a column vector. ──────────────────────────┼──────────────────────────────────────────────── 'matrix' │ Synonym of: ndims( obj ) <= 2 ──────────────────────────┼──────────────────────────────────────────────── '3-array' │ Synonym of: ndims( obj ) == 3 ──────────────────────────┼──────────────────────────────────────────────── 'interval' │ Synonym of: ::real:: && ... │ size( obj , 2 ) == 2 && ... │ all( diff( obj ') >= 0 ) │ Rationale: to ensure obj represents an │ interval or a set of intervals. An interval │ is represented by its lower and upper │ endpoints whose values are expressed as a │ couple of real numbers (a row vector). │ Intervals cannot have negative lenght. ──────────────────────────┼──────────────────────────────────────────────── 'sortable_interval' │ Synonym of: ::interval:: && ... │ all(diff(reshape( ... │ sortrows( obj ).',[],1 ... │ ))>=0) │ Rationale: to ensure a set of intervals can │ be sorted. A total-order criterion is adopted │ to ensure a sufficient condition in many cases │ of interest. The total-order criterion asks │ all intervals to be disjoint, i.e. to have │ zero-length intersections. ──────────────────────────┼──────────────────────────────────────────────── 'o-sortable_interval' │ Synonym of: ::interval:: && ... │ all(reshape(diff( ... │ sortrows( obj ),[],1 ... │ ))>=0) │ Rationale: to ensure a set of intervals can │ be partially sorted by checking they either │ are disjoint or overlap, without any of them │ being strictly included by others (overlap │ partial sortability). A partial ordering │ criterion is adopted: two intervals are in │ ascending order if their lower endpoins are │ in ascending order (i.e. their values are │ non-decreasing) and their upper endpoints │ are in ascending order. Strict sub-intervals │ (intervals whose endpoins lie strictly inside │ a previous interval) do not pass the test. │ Non-strict sub-intervals could pass the test: │ e.g intervals having equal upper endpoins and │ non-decreasing lower endpoints pass the test. ──────────────────────────┼──────────────────────────────────────────────── 'sorted_interval' │ Synonym of: ::interval:: && ... │ all(diff(reshape( ... │ obj .' ... │ ),[],1)>=0) │ Rationale: to ensure a set of intervals to be │ ascending ordered. A total-order criterion │ is adopted to ensure a sufficient condition │ in many cases of interest. │ The total-order criterion asks all intervals │ to be disjoint, i.e. to have zero-length │ intersections. ──────────────────────────┼──────────────────────────────────────────────── 'o-sorted_interval' │ Synonym of: ::interval:: && ... │ all(reshape(diff( obj ),[],1)>=0) │ Rationale: to ensure a set of intervals to be │ ascending partially-ordered. They can either │ be disjoint or overlap, without any of them │ being strictly included by others (overlap │ partial sortability). A partial ordering │ criterion is adopted: two intervals are in │ ascending order if their lower endpoins are │ in ascending order (i.e. their values are │ non-decreasing) and their upper endpoints │ are in ascending order. Strict sub-intervals │ (intervals whose endpoins lie strictly inside │ a previous interval) do not pass the test. │ Non-strict sub-intervals could pass the test: │ e.g intervals having equal upper endpoins and │ non-decreasing lower endpoints pass the test. ──────────────────────────┼──────────────────────────────────────────────── 'disjoint_interval' │ Synonym of: ::sorted_interval:: && ... │ all(diff(reshape( obj ',[],1))>=0) │ Rationale: to ensure a set of sorted intervals │ to have zero-length intersections. ──────────────────────────┼──────────────────────────────────────────────── 'contiguous_interval' │ Synonym of: ::disjoint_interval:: && ... │ all( obj (2:end,1) == ... │ obj (1:end-1) ) │ Rationale: to ensure a set of disjoint │ intervals to be contiguous (i.e. each interval │ upper endpoint must coincide with the lower │ endpoint of the subsequent interval of obj ). msg ::string:: String that contains the message to emit in case of check-failure. It can optionally contain C-language format tags that are replaced by the values specified in subsequent additional arguments. See fprintf help for more details.
Example of usage
s={ 'cell' , 'string' , 'cellstring' , ...
'cellstring-r' , 'cellstring-1' , 'cellstring-2' };
obj1 = {}, obj2 = { 'a' 'bc' }, obj3 = 'a' ,
obj4 = { 'a' {} }, obj5 = { { 'a' 'bc' } {} }, obj6 = {{{ 'a' }}},
objlist = { obj1 , obj2 , obj3 , obj4 , obj5 , obj6 };
for i=1:numel(s)
for j=1:numel(objlist)
obj = objlist{j};
[answer, msg] = check_is( obj , s{i}, 'oops..');
fprintf('is obj%d a %s ?: %d (%s)\n', j, s{i}, answer, msg );
end
end
s={ 'same_rows' , 'same_columns' , 'same_numel' , ...
'same_length' , 'same_size' , 'same_ndims' , 'comparable' };
obj1 = rand(4,4), obj2 = rand(4,4), obj3 = rand(4,2,2),
obj4 = rand(3,4), obj5 = rand(5,4),
for i=1:numel(s)
[answer, msg] = check_is( { obj1, obj2, obj3, obj4, obj5 }, ...
s{i}, 'oops..' );
fprintf('%s : %d (%s)\n', s{i}, answer, msg );
end
% ::multipliable::
% [OK]:
check_is( { ones(3,2) ones(2,5) ones(5,4) } , 'multipliable' , 'err' )
% [FAIL]: incompatible size
check_is( { ones(3,2) ones(7,5) ones(5,4) } , 'multipliable' , 'err' )
% [FAIL]: multi-array not supported by matrix product
check_is( { ones(3,2) ones(2,5,3) ones(5,4) } , 'multipliable' , 'err' )
% ::same_vals:: , ::same_valnans::
obj1 = randn( 4 , 3 );
obj2 = obj1;
obj2([3 5]) = [nan -inf];
% [OK]:
check_is( { obj1 obj1 obj1 } , 'same_vals' , 'err' )
check_is( { obj1 obj1 obj1 } , 'same_valnans' , 'err' )
check_is( { obj2 obj2 obj2 } , 'same_valnans' , 'err' )
% [FAIL]: different objects
check_is( { obj2 obj2 'foo' } , 'same_valnans' , 'err' )
% [FAIL]: assert( nan ~= nan )
check_is( { obj2 obj2 obj2 } , 'same_vals' , 'err' )
% ::sorted*:: objects
a3 = rand( 3 , 2 , 4 )
cc = cell( 3 , 2 , 4 );
c = 'abcdefghijklmnopqrstuvwxyz';
for i=1:numel(cc) cc{i}=c(ceil(rand(1,ceil(rand*10))*numel(c))); end
sa3 = sort( a3 , 1 )
scc = sort( cc , 1 )
sa3_ = sort( a3 , 1 , 'descend' )
scc_ = sort( cc , 1 , 'descend' )
% [FAIL]: unsorted objects
check_is( a3 , 'sorted' , 'err' )
check_is( cc , 'sorted' , 'err' )
check_is( a3 , 'sorted-ascend' , 'err' )
check_is( cc , 'sorted-ascend' , 'err' )
check_is( a3 , 'sorted-descend' , 'err' )
check_is( cc , 'sorted-descend' , 'err' )
% [OK]:
check_is( sa3 , 'sorted' , 'err' )
check_is( scc , 'sorted' , 'err' )
check_is( sa3 , 'sorted-ascend' , 'err' )
check_is( scc , 'sorted-ascend' , 'err' )
check_is( sa3_ , 'sorted-descend' , 'err' )
check_is( scc_ , 'sorted-descend' , 'err' )
% [FAIL]: objects sorted in ascending order
check_is( sa3 , 'sorted-descend' , 'err' )
check_is( scc , 'sorted-descend' , 'err' )
% [FAIL]: objects sorted in descending order
check_is( sa3_ , 'sorted-ascend' , 'err' )
check_is( scc_ , 'sorted-ascend' , 'err' )
% ::finite:: objects
% [FAIL]: non numeric object
check_is( { 'a' { 1:3 } } , 'finite' , 'err' )
% [FAIL]: non numeric object
check_is( 'finite string' , 'finite' , 'err' )
% [FAIL]: object containing Inf values
check_is( [-1 0 1 Inf 3] , 'finite' , 'err' )
% [FAIL]: object containing NaN values
check_is( [-1 0 1 NaN 3] , 'finite' , 'err' )
% [OK]: numeric object containing only finite values
check_is( [-1 0 1 2 3] , 'finite' , 'err' )
% [OK]: numeric object containing only finite values
check_is( [] , 'finite' , 'err' )
% Versors in L-1 norm: ::versor_coord-L1::
% [FAIL]:non numeric object
check_is( { 'a' { 1:3 } }, 'versor_coord-L1' , 'err' )
% [FAIL]:it is not an L-1 versor
check_is( [1 3] , 'versor_coord-L1' , 'err' )
% [OK]
check_is( [ pi/4 1-pi/4 ] , 'versor_coord-L1' , 'err' )
check_is( [1] , 'versor_coord-L1' , 'err' )
check_is( [ ] , 'versor_coord-L1' , 'err' )
% Versors in L-2 norm: ::versor_coord-L2::
% [FAIL]:non numeric object
check_is( { 'a' { 1:3 } }, 'versor_coord-L2' , 'err' )
% [FAIL]:it is not an L-2 versor
check_is( [1 3] , 'versor_coord-L2' , 'err' )
% [OK]
check_is( [2 2].^-0.5 , 'versor_coord-L2' , 'err' )
check_is( [1] , 'versor_coord-L2' , 'err' )
check_is( [ ] , 'versor_coord-L2' , 'err' )
% Versors in L-infinite norm: ::versor_coord-Linf::
% [FAIL]:non numeric object
check_is( { 'a' { 1:3 } }, 'versor_coord-Linf' , 'err' )
% [FAIL]:it is not an L-2 versor
check_is( [1 3] , 'versor_coord-Linf' , 'err' )
% [OK]
check_is( [1 0 .1;0 .2 1] , 'versor_coord-Linf' , 'err' )
check_is( [1] , 'versor_coord-Linf' , 'err' )
check_is( [ ] , 'versor_coord-Linf' , 'err' )
% ::format_string::
format = '%g, %d.\n'
% [OK]
check_is( format, 'format_string' , 'err' )
fprintf( 1 , format, pi, -1 )
format = '%&$'
% [FAIL]:invalid format string
check_is( format, 'format_string' , 'err' )
format = 123
% [FAIL]:it is not a string
check_is( format, 'format_string' , 'err' )
% ::regexp::, regular expressions
regexp = '.*'
% [OK]
check_is( pattern, 'regexp' , 'err' )
pattern = '.*['
% [FAIL]:invalid regular expression string
check_is( pattern, 'regexp' , 'err' )
pattern = 123
% [FAIL]:it is not a string
check_is( pattern, 'regexp' , 'err' )
% ::*funhandle::
% ::cellfunhandle::
f = @max
% [OK]
check_is( f , 'funhandle' , 'err' )
check_is( 'max' , 'strfunhandle' , 'err' )
check_is( f , 'cellfunhandle' , 'err' )
f = @(x)quantile( x, 0.2 )
% [OK]
check_is( f , 'funhandle' , 'err' )
check_is( 0.2 , 'numfunhandle' , 'err' )
check_is( f , 'cellfunhandle' , 'err' )
f = { @max , @median , @min }
% [FAIL]: expected a single funtion handle
check_is( f , 'funhandle' , 'err' )
% [OK]
check_is( f , 'cellfunhandle' , 'err' )
f = { @max , { @median , @min } }
% [FAIL]: invalid cell-array of cell-arrays
check_is( f , 'cellfunhandle' , 'err' )
f = 'max'
% [FAIL]: it is not a function handle
check_is( f , 'cellfunhandle' , 'err' )
% ::*-vector::, ::*n-vectors::
% [OK]
check_is( pi , 'scalar' , 'err' )
check_is( pi , '1-vector', 'err' )
% [OK]
check_is( { 'foo', 'bar' }, '2-vector', 'err' )
% [OK]
check_is( [2 3 5] , '3-vector', 'err' )
% [FAIL]
check_is( [2 3 5] , '2-vector', 'err' )
% [OK]
check_is( { 3, [2 3 5] } , 'n-vectors', 'err' )
% [OK]
check_is( { [1 3], pi, [2 3 5] }, 'n-vectors', 'err' )
% [FAIL]: [2 3 5] has not 2 elements
check_is( { [1 2], pi, [2 3 5] }, 'n-vectors', 'err' )
% [FAIL]: the first element of the cell-array
% must be an array
check_is( { 'foo', pi, [2 3 5] }, 'n-vectors', 'err' )
% [FAIL]: the first element of the cell-array
% must be scalar of have exactly
% numel( obj )-1
% elements
check_is( { 1:3 , pi, [2 3 5] }, 'n-vectors', 'err' )
% [OK]: numel( [2 3 5] ) <= 3
check_is( { 3, [2 3 5] } , '[n-vectors', 'err' )
% [OK]
check_is( { [1 3], pi, [2 3 5] }, '[n-vectors', 'err' )
% [OK]
check_is( { [1 2], pi, [2 3 5] }, '[n-vectors', 'err' )
% [FAIL]: [2 3 5] has less than 4 elements
check_is( { [1 4], pi, [2 3 5] }, '[n-vectors', 'err' )
% [OK]
check_is( { [1 4], pi, [2 3 5] }, 'n]-vectors', 'err' )
% [FAIL]: pi has not more than 1 element
check_is( { [1 4], pi, [2 3 5] }, ']n-vectors', 'err' )
% [FAIL]: pi has not less than 1 element
check_is( { [1 4], pi, [2 3 5] }, 'n[-vectors', 'err' )
% [OK]
check_is( { [2 4], pi, [2 3 5] }, 'n[-vectors', 'err' )
See also: gettext Keywords: constraints, pre-conditions, post-conditions, checks Version: 0.13.14
Support
The Mastrave modelling library is committed to provide reusable and general - but also robust and scalable - modules for research modellers dealing with computational science. You can help the Mastrave project by providing feedbacks on unexpected behaviours of this module. Despite all efforts, all of us - either developers or users - (should) know that errors are unavoidable. However, the free software paradigm successfully highlights that scientific knowledge freedom also implies an impressive opportunity for collectively evolve the tools and ideas upon which our daily work is based. Reporting a problem that you found using Mastrave may help the developer team to find a possible bug. Please, be aware that Mastrave is entirely based on voluntary efforts: in order for your help to be as effective as possible, please read carefully the section on reporting problems. Thank you for your collaboration.
Semantic array programming: abstract, portable and scalable data-transformation modelling for the community of computational scientists.