diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 3568fb1a9a..0eda8b53d6 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -21,7 +21,6 @@ jobs: brew install icu4c brew info open-mpi brew install openmpi - brew unlink pkg-config@0.29.2 brew install pkgconf brew install gettext brew link gettext --force @@ -103,7 +102,6 @@ jobs: brew install icu4c brew info open-mpi brew install openmpi - brew unlink pkg-config@0.29.2 brew install pkgconf brew install gettext brew link gettext --force diff --git a/CHANGELOG.md b/CHANGELOG.md index d41a9772db..9fde50fe3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,9 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `csvwrite`: Write comma-separated value (CSV) file. - `dlmread`: Read ASCII-delimited file of numeric data into matrix. - `realmin`: Smallest normalized floating-point number. +- [#1288](http://github.com/nelson-lang/nelson/issues/1288) `mustBeMatrix`, `mustBeRow`, `mustBeColumn` validator functions. ### Changed +- `narginchk`, `nargoutchk` support for check only minimun arguments `narginchk(3, Inf)`. - Fedora 41 CI - `title`: `Visible` property is inherited from the parent if not explicitly defined. - i18n: migration PO files to JSON. diff --git a/modules/core/builtin/cpp/narginchkBuiltin.cpp b/modules/core/builtin/cpp/narginchkBuiltin.cpp index 0913c8c3cd..2afdacece8 100644 --- a/modules/core/builtin/cpp/narginchkBuiltin.cpp +++ b/modules/core/builtin/cpp/narginchkBuiltin.cpp @@ -31,14 +31,21 @@ Nelson::CoreGateway::narginchkBuiltin(Evaluator* eval, int nLhs, const ArrayOfVe Error(_("Scalar integer value required for #2 argument.")); } int minArgs = argIn[0].getContentAsInteger32Scalar(false, true); - int maxArgs = argIn[1].getContentAsInteger32Scalar(false, true); - + bool maxArgsIsInf = false; + if (argIn[1].isDoubleType(true)) { + double maxValue = argIn[1].getContentAsDoubleScalar(); + maxArgsIsInf = std::isinf(maxValue); + } int nargin = context->getCurrentScope()->getNargIn(); if (nargin < minArgs) { Error(ERROR_WRONG_NUMBERS_INPUT_ARGS, L"Nelson:narginchk:notEnoughInputs", true); } - if (nargin > maxArgs) { - Error(ERROR_WRONG_NUMBERS_INPUT_ARGS, L"Nelson:narginchk:tooManyInputs", true); + if (!maxArgsIsInf) { + int maxArgs = argIn[1].getContentAsInteger32Scalar(false, true); + + if (nargin > maxArgs) { + Error(ERROR_WRONG_NUMBERS_INPUT_ARGS, L"Nelson:narginchk:tooManyInputs", true); + } } return retval; } diff --git a/modules/core/builtin/cpp/nargoutchkBuiltin.cpp b/modules/core/builtin/cpp/nargoutchkBuiltin.cpp index 0c19a4f826..737ba9a890 100644 --- a/modules/core/builtin/cpp/nargoutchkBuiltin.cpp +++ b/modules/core/builtin/cpp/nargoutchkBuiltin.cpp @@ -69,7 +69,12 @@ Nelson::CoreGateway::nargoutchkBuiltin(Evaluator* eval, int nLhs, const ArrayOfV } int minArgs = argIn[0].getContentAsInteger32Scalar(false, true); - int maxArgs = argIn[1].getContentAsInteger32Scalar(false, true); + + bool maxArgsIsInf = false; + if (argIn[1].isDoubleType(true)) { + double maxValue = argIn[1].getContentAsDoubleScalar(); + maxArgsIsInf = std::isinf(maxValue); + } int numArgs = argIn[2].getContentAsInteger32Scalar(false, true); std::wstring msg = L""; @@ -78,7 +83,9 @@ Nelson::CoreGateway::nargoutchkBuiltin(Evaluator* eval, int nLhs, const ArrayOfV msg = _W("Not enough output arguments."); id = L"Nelson:nargoutchk:notEnoughOutputs"; } - if (numArgs > maxArgs) { + + int maxArgs = argIn[1].getContentAsInteger32Scalar(false, true); + if (!maxArgsIsInf && numArgs > maxArgs) { msg = _W("Too many output arguments."); id = L"Nelson:nargoutchk:tooManyOutputs"; } diff --git a/modules/core/help/en_US/xml/narginchk.xml b/modules/core/help/en_US/xml/narginchk.xml index d93babb814..fae11e13a2 100644 --- a/modules/core/help/en_US/xml/narginchk.xml +++ b/modules/core/help/en_US/xml/narginchk.xml @@ -26,6 +26,10 @@

narginchk checks the number of input arguments of an function.

+

To ensure that a minimum number of arguments is provided, while allowing an unlimited maximum number by setting maxArgs to inf. For instance, use narginchk(2, inf) to throw an error if fewer than two inputs are supplied.

@@ -59,6 +63,10 @@ 1.0.0 initial version + + 1.10.0 + narginchk(3, Inf) managed + diff --git a/modules/core/help/en_US/xml/nargoutchk.xml b/modules/core/help/en_US/xml/nargoutchk.xml index 248f41c783..74eb46cabd 100644 --- a/modules/core/help/en_US/xml/nargoutchk.xml +++ b/modules/core/help/en_US/xml/nargoutchk.xml @@ -44,6 +44,9 @@

nargoutchk checks the number of output arguments of an function.

+

To ensure a minimum number of outputs while imposing no maximum limit, set maxArgs to inf. For example, nargoutchk(2, inf) generates an error if fewer than two outputs are specified.

@@ -68,7 +71,7 @@ nargoutchk(1, 2, 3, 'struct')]]> nargout - narginchk + narginchk @@ -78,6 +81,10 @@ nargoutchk(1, 2, 3, 'struct')]]> 1.0.0 initial version + + 1.10.0 + nargoutchk(3, Inf) managed + diff --git a/modules/validators/builtin/c/nlsValidators_builtin.vcxproj b/modules/validators/builtin/c/nlsValidators_builtin.vcxproj index 97e241fc93..2032b9486e 100644 --- a/modules/validators/builtin/c/nlsValidators_builtin.vcxproj +++ b/modules/validators/builtin/c/nlsValidators_builtin.vcxproj @@ -182,6 +182,7 @@ + @@ -194,6 +195,7 @@ + @@ -208,6 +210,7 @@ + @@ -237,6 +240,7 @@ + @@ -249,6 +253,7 @@ + @@ -263,6 +268,7 @@ + diff --git a/modules/validators/builtin/c/nlsValidators_builtin.vcxproj.filters b/modules/validators/builtin/c/nlsValidators_builtin.vcxproj.filters index 1bcb5e2180..7e456b6ea4 100644 --- a/modules/validators/builtin/c/nlsValidators_builtin.vcxproj.filters +++ b/modules/validators/builtin/c/nlsValidators_builtin.vcxproj.filters @@ -21,9 +21,6 @@ Source Files - - Source Files - Source Files @@ -117,6 +114,18 @@ Source Files + + Source Files + + + Header Files + + + Source Files + + + Source Files + @@ -221,6 +230,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files + diff --git a/modules/validators/builtin/cpp/Gateway.cpp b/modules/validators/builtin/cpp/Gateway.cpp index a059610608..5f09c16daf 100644 --- a/modules/validators/builtin/cpp/Gateway.cpp +++ b/modules/validators/builtin/cpp/Gateway.cpp @@ -45,6 +45,9 @@ #include "mustBeNonzeroLengthTextBuiltin.hpp" #include "mustBeMemberBuiltin.hpp" #include "mustBeInRangeBuiltin.hpp" +#include "mustBeMatrixBuiltin.hpp" +#include "mustBeRowBuiltin.hpp" +#include "mustBeColumnBuiltin.hpp" //============================================================================= using namespace Nelson; //============================================================================= @@ -91,6 +94,10 @@ static const nlsGateway gateway[] = { 0, -2 }, { "mustBeMember", (ptrBuiltin)Nelson::ValidatorsGateway::mustBeMemberBuiltin, 0, -2 }, { "mustBeInRange", (ptrBuiltin)Nelson::ValidatorsGateway::mustBeInRangeBuiltin, 0, -3 }, + { "mustBeMatrix", (ptrBuiltin)Nelson::ValidatorsGateway::mustBeMatrixBuiltin, 0, -1 }, + { "mustBeRow", (ptrBuiltin)Nelson::ValidatorsGateway::mustBeRowBuiltin, 0, -1 }, + { "mustBeColumn", (ptrBuiltin)Nelson::ValidatorsGateway::mustBeColumnBuiltin, 0, -1 }, + }; //============================================================================= static bool diff --git a/modules/validators/builtin/cpp/mustBeColumnBuiltin.cpp b/modules/validators/builtin/cpp/mustBeColumnBuiltin.cpp new file mode 100644 index 0000000000..cddaca92c5 --- /dev/null +++ b/modules/validators/builtin/cpp/mustBeColumnBuiltin.cpp @@ -0,0 +1,35 @@ +//============================================================================= +// Copyright (c) 2016-present Allan CORNET (Nelson) +//============================================================================= +// This file is part of the Nelson. +//============================================================================= +// LICENCE_BLOCK_BEGIN +// SPDX-License-Identifier: LGPL-3.0-or-later +// LICENCE_BLOCK_END +//============================================================================= +#include "mustBeColumnBuiltin.hpp" +#include "ValidatorsInternal.hpp" +#include "Error.hpp" +#include "i18n.hpp" +#include "InputOutputArgumentsCheckers.hpp" +//============================================================================= +using namespace Nelson; +//============================================================================= +ArrayOfVector +Nelson::ValidatorsGateway::mustBeColumnBuiltin(int nLhs, const ArrayOfVector& argIn) +{ + ArrayOfVector retval; + nargoutcheck(nLhs, 0, 0); + nargincheck(argIn, 1, 2); + int argPos = -1; + if (argIn.size() == 2) { + ArrayOf param2 = argIn[1]; + argPos = param2.getContentAsInteger32Scalar(); + if (argPos < 1) { + Error(_W("The last argument must be a positive integer.")); + } + } + mustBeColumn(argIn[0], argPos, true); + return retval; +} +//============================================================================= diff --git a/modules/validators/builtin/cpp/mustBeMatrixBuiltin.cpp b/modules/validators/builtin/cpp/mustBeMatrixBuiltin.cpp new file mode 100644 index 0000000000..b833ba361a --- /dev/null +++ b/modules/validators/builtin/cpp/mustBeMatrixBuiltin.cpp @@ -0,0 +1,35 @@ +//============================================================================= +// Copyright (c) 2016-present Allan CORNET (Nelson) +//============================================================================= +// This file is part of the Nelson. +//============================================================================= +// LICENCE_BLOCK_BEGIN +// SPDX-License-Identifier: LGPL-3.0-or-later +// LICENCE_BLOCK_END +//============================================================================= +#include "mustBeMatrixBuiltin.hpp" +#include "ValidatorsInternal.hpp" +#include "Error.hpp" +#include "i18n.hpp" +#include "InputOutputArgumentsCheckers.hpp" +//============================================================================= +using namespace Nelson; +//============================================================================= +ArrayOfVector +Nelson::ValidatorsGateway::mustBeMatrixBuiltin(int nLhs, const ArrayOfVector& argIn) +{ + ArrayOfVector retval; + nargoutcheck(nLhs, 0, 0); + nargincheck(argIn, 1, 2); + int argPos = -1; + if (argIn.size() == 2) { + ArrayOf param2 = argIn[1]; + argPos = param2.getContentAsInteger32Scalar(); + if (argPos < 1) { + Error(_W("The last argument must be a positive integer.")); + } + } + mustBeMatrix(argIn[0], argPos, true); + return retval; +} +//============================================================================= diff --git a/modules/validators/builtin/cpp/mustBeRowBuiltin.cpp b/modules/validators/builtin/cpp/mustBeRowBuiltin.cpp new file mode 100644 index 0000000000..fc12a4e14c --- /dev/null +++ b/modules/validators/builtin/cpp/mustBeRowBuiltin.cpp @@ -0,0 +1,35 @@ +//============================================================================= +// Copyright (c) 2016-present Allan CORNET (Nelson) +//============================================================================= +// This file is part of the Nelson. +//============================================================================= +// LICENCE_BLOCK_BEGIN +// SPDX-License-Identifier: LGPL-3.0-or-later +// LICENCE_BLOCK_END +//============================================================================= +#include "mustBeRowBuiltin.hpp" +#include "ValidatorsInternal.hpp" +#include "Error.hpp" +#include "i18n.hpp" +#include "InputOutputArgumentsCheckers.hpp" +//============================================================================= +using namespace Nelson; +//============================================================================= +ArrayOfVector +Nelson::ValidatorsGateway::mustBeRowBuiltin(int nLhs, const ArrayOfVector& argIn) +{ + ArrayOfVector retval; + nargoutcheck(nLhs, 0, 0); + nargincheck(argIn, 1, 2); + int argPos = -1; + if (argIn.size() == 2) { + ArrayOf param2 = argIn[1]; + argPos = param2.getContentAsInteger32Scalar(); + if (argPos < 1) { + Error(_W("The last argument must be a positive integer.")); + } + } + mustBeRow(argIn[0], argPos, true); + return retval; +} +//============================================================================= diff --git a/modules/validators/builtin/include/mustBeColumnBuiltin.hpp b/modules/validators/builtin/include/mustBeColumnBuiltin.hpp new file mode 100644 index 0000000000..202f296e46 --- /dev/null +++ b/modules/validators/builtin/include/mustBeColumnBuiltin.hpp @@ -0,0 +1,20 @@ +//============================================================================= +// Copyright (c) 2016-present Allan CORNET (Nelson) +//============================================================================= +// This file is part of the Nelson. +//============================================================================= +// LICENCE_BLOCK_BEGIN +// SPDX-License-Identifier: LGPL-3.0-or-later +// LICENCE_BLOCK_END +//============================================================================= +#pragma once +//============================================================================= +#include "ArrayOf.hpp" +//============================================================================= +namespace Nelson::ValidatorsGateway { +//============================================================================= +ArrayOfVector +mustBeColumnBuiltin(int nLhs, const ArrayOfVector& argIn); +//============================================================================= +} // namespace Nelson +//============================================================================= diff --git a/modules/validators/builtin/include/mustBeMatrixBuiltin.hpp b/modules/validators/builtin/include/mustBeMatrixBuiltin.hpp new file mode 100644 index 0000000000..4f0e7982a8 --- /dev/null +++ b/modules/validators/builtin/include/mustBeMatrixBuiltin.hpp @@ -0,0 +1,20 @@ +//============================================================================= +// Copyright (c) 2016-present Allan CORNET (Nelson) +//============================================================================= +// This file is part of the Nelson. +//============================================================================= +// LICENCE_BLOCK_BEGIN +// SPDX-License-Identifier: LGPL-3.0-or-later +// LICENCE_BLOCK_END +//============================================================================= +#pragma once +//============================================================================= +#include "ArrayOf.hpp" +//============================================================================= +namespace Nelson::ValidatorsGateway { +//============================================================================= +ArrayOfVector +mustBeMatrixBuiltin(int nLhs, const ArrayOfVector& argIn); +//============================================================================= +} // namespace Nelson +//============================================================================= diff --git a/modules/validators/builtin/include/mustBeRowBuiltin.hpp b/modules/validators/builtin/include/mustBeRowBuiltin.hpp new file mode 100644 index 0000000000..d8d726224e --- /dev/null +++ b/modules/validators/builtin/include/mustBeRowBuiltin.hpp @@ -0,0 +1,20 @@ +//============================================================================= +// Copyright (c) 2016-present Allan CORNET (Nelson) +//============================================================================= +// This file is part of the Nelson. +//============================================================================= +// LICENCE_BLOCK_BEGIN +// SPDX-License-Identifier: LGPL-3.0-or-later +// LICENCE_BLOCK_END +//============================================================================= +#pragma once +//============================================================================= +#include "ArrayOf.hpp" +//============================================================================= +namespace Nelson::ValidatorsGateway { +//============================================================================= +ArrayOfVector +mustBeRowBuiltin(int nLhs, const ArrayOfVector& argIn); +//============================================================================= +} // namespace Nelson +//============================================================================= diff --git a/modules/validators/help/en_US/xml/mustBeColumn.xml b/modules/validators/help/en_US/xml/mustBeColumn.xml new file mode 100644 index 0000000000..6a18e80576 --- /dev/null +++ b/modules/validators/help/en_US/xml/mustBeColumn.xml @@ -0,0 +1,67 @@ + + + SAME AS NELSON SOFTWARE + + en_US + mustBeColumn + Checks that value is a column vector or raise an error. + + + mustBeColumn(var) + mustBeColumn(var, argPosition) + C++: void mustBeColumn(const ArrayOfVector& args, int argPosition) + + + + + var + a variable: all supported types and classes that implement iscolumn method. + + + argPosition + a positive integer value: Position of input argument. + + + + + +

mustBeColumn checks that value is a column vector or raise an error.

+
+ + + + + + + nelson + + + + + + + + + iscolumn + + + + + + 1.10.0 + initial version + + + + + Allan CORNET + +
diff --git a/modules/validators/help/en_US/xml/mustBeMatrix.xml b/modules/validators/help/en_US/xml/mustBeMatrix.xml new file mode 100644 index 0000000000..d44ff2f0be --- /dev/null +++ b/modules/validators/help/en_US/xml/mustBeMatrix.xml @@ -0,0 +1,66 @@ + + + SAME AS NELSON SOFTWARE + + en_US + mustBeMatrix + Checks that value is a matrix or raise an error. + + + mustBeMatrix(var) + mustBeMatrix(var, argPosition) + C++: void mustBeMatrix(const ArrayOfVector& args, int argPosition) + + + + + var + a variable: all supported types and classes that implement ismatrix method. + + + argPosition + a positive integer value: Position of input argument. + + + + + +

mustBeMatrix checks that value is a matrix or raise an error.

+
+ + + + + + + nelson + + + + + + + + + ismatrix + + + + + + 1.10.0 + initial version + + + + + Allan CORNET + +
diff --git a/modules/validators/help/en_US/xml/mustBeRow.xml b/modules/validators/help/en_US/xml/mustBeRow.xml new file mode 100644 index 0000000000..b064c0b9b9 --- /dev/null +++ b/modules/validators/help/en_US/xml/mustBeRow.xml @@ -0,0 +1,66 @@ + + + SAME AS NELSON SOFTWARE + + en_US + mustBeRow + Checks that value is a row vector or raise an error. + + + mustBeRow(var) + mustBeRow(var, argPosition) + C++: void mustBeRow(const ArrayOfVector& args, int argPosition) + + + + + var + a variable: all supported types and classes that implement isrow method. + + + argPosition + a positive integer value: Position of input argument. + + + + + +

mustBeRow checks that value is a row vector or raise an error.

+
+ + + + + + + nelson + + + + + + + + + isrow + + + + + + 1.10.0 + initial version + + + + + Allan CORNET + +
diff --git a/modules/validators/src/cpp/ValidatorsInternal.cpp b/modules/validators/src/cpp/ValidatorsInternal.cpp index 663b7c2a35..568807639d 100644 --- a/modules/validators/src/cpp/ValidatorsInternal.cpp +++ b/modules/validators/src/cpp/ValidatorsInternal.cpp @@ -224,6 +224,43 @@ mustBeFloat(const ArrayOf& arg, int argPosition, bool asCaller) } //============================================================================= void +mustBeMatrix(const ArrayOf& arg, int argPosition, bool asCaller) +{ + ArrayOfVector argIn(arg); + ArrayOfVector argOut = evaluateFunction(argIn, 1, "ismatrix"); + if (!argOut[0].getContentAsLogicalScalar()) { + std::wstring msg = invalidPositionMessage(argPosition) + _W("Value must be a matrix."); + std::wstring id = L"Nelson:validators:mustBeMatrix"; + Error(msg, id, asCaller); + } +} +//============================================================================= +void +mustBeRow(const ArrayOf& arg, int argPosition, bool asCaller) +{ + ArrayOfVector argIn(arg); + ArrayOfVector argOut = evaluateFunction(argIn, 1, "isrow"); + if (!argOut[0].getContentAsLogicalScalar()) { + std::wstring msg = invalidPositionMessage(argPosition) + _W("Value must be a row vector."); + std::wstring id = L"Nelson:validators:mustBeRow"; + Error(msg, id, asCaller); + } +} +//============================================================================= +void +mustBeColumn(const ArrayOf& arg, int argPosition, bool asCaller) +{ + ArrayOfVector argIn(arg); + ArrayOfVector argOut = evaluateFunction(argIn, 1, "iscolumn"); + if (!argOut[0].getContentAsLogicalScalar()) { + std::wstring msg + = invalidPositionMessage(argPosition) + _W("Value must be a column vector."); + std::wstring id = L"Nelson:validators:mustBeColumn"; + Error(msg, id, asCaller); + } +} +//============================================================================= +void mustBeNumeric(const ArrayOf& arg, int argPosition, bool asCaller) { ArrayOfVector argIn(arg); diff --git a/modules/validators/src/cpp/ValidatorsInternal.hpp b/modules/validators/src/cpp/ValidatorsInternal.hpp index 8a7fe04d01..2add4c160e 100644 --- a/modules/validators/src/cpp/ValidatorsInternal.hpp +++ b/modules/validators/src/cpp/ValidatorsInternal.hpp @@ -51,6 +51,9 @@ NLSVALIDATORS_IMPEXP void mustBeFloat(const ArrayOf& arg, int argPosition, bool asCaller = false); //============================================================================= NLSVALIDATORS_IMPEXP void +mustBeMatrix(const ArrayOf& arg, int argPosition, bool asCaller = false); +//============================================================================= +NLSVALIDATORS_IMPEXP void mustBeNumeric(const ArrayOf& arg, int argPosition, bool asCaller = false); //============================================================================= NLSVALIDATORS_IMPEXP void @@ -114,5 +117,11 @@ mustBeInRange(const ArrayOf& value, const ArrayOf& lower, const ArrayOf& upper, const std::wstring& boundflag1, const std::wstring& boundflag2, int argPosition, bool asCaller = false); //============================================================================= +NLSVALIDATORS_IMPEXP void +mustBeRow(const ArrayOf& arg, int argPosition, bool asCaller = false); +//============================================================================= +NLSVALIDATORS_IMPEXP void +mustBeColumn(const ArrayOf& arg, int argPosition, bool asCaller = false); +//============================================================================= } //============================================================================= diff --git a/modules/validators/src/include/Validators.hpp b/modules/validators/src/include/Validators.hpp index 165fc18c2b..0461771378 100644 --- a/modules/validators/src/include/Validators.hpp +++ b/modules/validators/src/include/Validators.hpp @@ -110,5 +110,7 @@ mustBeMember(const ArrayOfVector& args, const ArrayOf& S, int argPosition); NLSVALIDATORS_IMPEXP void mustBeInRange(const ArrayOfVector& args, const ArrayOf& upper, const ArrayOf& lower, const std::wstring& boundflag1, const std::wstring& boundflag2, int argPosition); +//============================================================================= + } //============================================================================= diff --git a/modules/validators/tests/test_mustBeColumn.m b/modules/validators/tests/test_mustBeColumn.m new file mode 100644 index 0000000000..b6c521dc30 --- /dev/null +++ b/modules/validators/tests/test_mustBeColumn.m @@ -0,0 +1,21 @@ +%============================================================================= +% Copyright (c) 2016-present Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +assert_isequal(nargin('mustBeColumn'), -1); +assert_isequal(nargout('mustBeColumn'), 0); +%============================================================================= +mustBeColumn(['N';'e';'l';'s';'o';'n']); +mustBeColumn([1; 2; 3]); +%============================================================================= +assert_checkerror('mustBeColumn([])', _('Value must be a column vector.')); +%============================================================================= +msg = [sprintf(_('Invalid input argument at position %d.'), 3), char(10), _('Value must be a column vector.')]; +assert_checkerror('mustBeColumn([], 3)', msg); +%============================================================================= + diff --git a/modules/validators/tests/test_mustBeMatrix.m b/modules/validators/tests/test_mustBeMatrix.m new file mode 100644 index 0000000000..e3f86c9956 --- /dev/null +++ b/modules/validators/tests/test_mustBeMatrix.m @@ -0,0 +1,21 @@ +%============================================================================= +% Copyright (c) 2016-present Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +assert_isequal(nargin('mustBeMatrix'), -1); +assert_isequal(nargout('mustBeMatrix'), 0); +%============================================================================= +mustBeMatrix([]); +mustBeMatrix(single(3)); +%============================================================================= +assert_checkerror('mustBeMatrix(ones(2, 3, 2))', _('Value must be a matrix.')); +%============================================================================= +msg = [sprintf(_('Invalid input argument at position %d.'), 3), char(10), _('Value must be a matrix.')]; +assert_checkerror('mustBeMatrix(ones(2, 3, 2), 3)', msg); +%============================================================================= + diff --git a/modules/validators/tests/test_mustBeRow.m b/modules/validators/tests/test_mustBeRow.m new file mode 100644 index 0000000000..5b9c286944 --- /dev/null +++ b/modules/validators/tests/test_mustBeRow.m @@ -0,0 +1,21 @@ +%============================================================================= +% Copyright (c) 2016-present Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +assert_isequal(nargin('mustBeRow'), -1); +assert_isequal(nargout('mustBeRow'), 0); +%============================================================================= +mustBeRow('Nelson'); +mustBeRow([1, 2, 3]); +%============================================================================= +assert_checkerror('mustBeRow([])', _('Value must be a row vector.')); +%============================================================================= +msg = [sprintf(_('Invalid input argument at position %d.'), 3), char(10), _('Value must be a row vector.')]; +assert_checkerror('mustBeRow([], 3)', msg); +%============================================================================= +