Skip to content

Commit

Permalink
fix #295 sort did not return correct error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed May 5, 2020
1 parent 3dc0df0 commit 56efb09
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 157 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# 0.4.5 (2020-05-XX)

* test_run: tests are sorted on all platforms.


Bug Fixes:
---------

* [#295](http://github.com/Nelson-numerical-software/nelson/issues/295): sort did not return an wrong error message for struct.


Compilation:
------------

Expand Down
43 changes: 37 additions & 6 deletions modules/elementary_functions/src/cpp/Sort.cpp
Expand Up @@ -42,21 +42,52 @@ Sort(ArrayOf arrayIn, size_t nargin, bool withIndex, indexType dim, bool ascend,
{
ArrayOfVector res;
needToOverload = false;
if (arrayIn.isClassStruct()) {
needToOverload = true;
return res;
}
if (arrayIn.isEmpty()) {
res.push_back(ArrayOf::emptyConstructor(arrayIn.getDimensions()));
if (withIndex) {
switch (arrayIn.getDataClass()) {
case NLS_CELL_ARRAY: {
if (nargin != 1) {
Error(_W("Only one input parameter is supported for cell arrays."));
}
res.push_back(ArrayOf::emptyConstructor(arrayIn.getDimensions()));
}
} else {
if (arrayIn.isClassStruct()) {
} break;
case NLS_STRING_ARRAY:
case NLS_LOGICAL:
case NLS_UINT8:
case NLS_INT8:
case NLS_UINT16:
case NLS_INT16:
case NLS_UINT32:
case NLS_INT32:
case NLS_UINT64:
case NLS_INT64:
case NLS_SINGLE:
case NLS_DOUBLE:
case NLS_SCOMPLEX:
case NLS_DCOMPLEX:
case NLS_CHAR: {
res.push_back(ArrayOf::emptyConstructor(arrayIn.getDimensions()));
if (withIndex) {
res.push_back(ArrayOf::emptyConstructor(arrayIn.getDimensions()));
}
} break;
case NLS_HANDLE:
case NLS_STRUCT_ARRAY:
default: {
needToOverload = true;
return res;
} break;
}
} else {
indexType dimOperate;
Dimensions inDim(arrayIn.getDimensions());
if (dim == 0) {
indexType lenInDim = inDim.getLength();
indexType d = 0;
while (inDim[d] == 1) {
while (d < lenInDim && inDim.getAt(d) == 1) {
d++;
}
dimOperate = d;
Expand Down
37 changes: 37 additions & 0 deletions modules/elementary_functions/tests/bug_github_issue_#295.nls
@@ -0,0 +1,37 @@
//=============================================================================
// Copyright (c) 2017 Allan CORNET (Nelson)
//=============================================================================
// This file is part of the Nelson.
//=============================================================================
// LICENCE_BLOCK_BEGIN
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// Alternatively, 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 2 of
// the License, or (at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see <http://www.gnu.org/licenses/>.
// LICENCE_BLOCK_END
//=============================================================================
// <-- Issue URL -->
// https://github.com/Nelson-numerical-software/nelson/issues/295
// <-- Short Description -->
// sort did not return an wrong error message for struct
//=============================================================================
// <--ENGLISH IMPOSED-->
tests_dir = 'd:\developpements\Github\nelson\modules\mex'
nonreg_tests = dir([tests_dir, 'test_*.nls'])
assert_checkerror('sort(nonreg_tests)', 'function struct_sort undefined.');
//=============================================================================
assert_checkerror('sort(cell(1,1))','function cell_sort undefined.');
//=============================================================================
6 changes: 2 additions & 4 deletions modules/error_manager/src/cpp/Exception.cpp
Expand Up @@ -52,14 +52,12 @@ Exception::Exception()
Exception::Exception(const std::string& msg_in, std::vector<PositionScript> positions,
const std::string& identifier_in)
: backtrace(positions), identifier(utf8_to_wstring(identifier_in)), msg(utf8_to_wstring(msg_in))
{
}
{}
//=============================================================================
Exception::Exception(const std::wstring& msg_in, std::vector<PositionScript> positions,
const std::wstring& identifier_in)
: backtrace(positions), identifier(identifier_in), msg(msg_in)
{
}
{}
//=============================================================================
Exception::Exception(
const std::string& msg_in, const PositionScript& position, const std::string& identifier_in)
Expand Down
4 changes: 1 addition & 3 deletions modules/interpreter/src/cpp/Evaluator.cpp
Expand Up @@ -123,9 +123,7 @@ class endData
ArrayOf endArray;
int index = 0;
size_t count = 0;
endData(ArrayOf p, int ndx, size_t cnt) : endArray(p), index(ndx), count(cnt)
{
}
endData(ArrayOf p, int ndx, size_t cnt) : endArray(p), index(ndx), count(cnt) {}
~endData() = default;
;
};
Expand Down
3 changes: 1 addition & 2 deletions modules/interpreter/src/include/PositionScript.hpp
Expand Up @@ -43,8 +43,7 @@ class PositionScript
PositionScript(
const std::wstring& functionname = L"", const std::wstring& filename = L"", int line = -1)
: filename(filename), functionname(functionname), line(line)
{
}
{}
//=============================================================================
PositionScript(const PositionScript& copy)
{
Expand Down

0 comments on commit 56efb09

Please sign in to comment.