Skip to content

Commit

Permalink
Allow entering values in exponential form for parameters (#12064)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 4, 2024
1 parent c0f2cbf commit 04a453a
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 6 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Util/Utilities.cpp
Expand Up @@ -653,7 +653,7 @@ bool Utilities::isValueLiteralConstant(QString value)
* Issue #11840. Allow setting array of values.
* The following regular expression allows decimal values and array of decimal values. The values can be negative.
*/
QRegExp rx("\\{?\\s*-?\\d+(\\.\\d+)?(?:\\s*,\\s*-?\\d+(\\.\\d+)?)*\\s*\\}?");
QRegExp rx("\\{?\\s*-?\\d+(\\.\\d+)?([eE][-+]?\\d+)?(?:\\s*,\\s*-?\\d+(\\.\\d+)?([eE][-+]?\\d+)?)*\\s*\\}?");
return rx.exactMatch(value);
}

Expand Down
3 changes: 0 additions & 3 deletions OMEdit/Testsuite/ModelInstance/ModelInstanceTest.cpp
Expand Up @@ -82,11 +82,8 @@ void ModelInstanceTest::classConnections()

void ModelInstanceTest::cleanupTestCase()
{
qDebug() << "cleanupTestCase 1";
if (mpModelInstance) {
delete mpModelInstance;
}
qDebug() << "cleanupTestCase 2";
MainWindow::instance()->close();
qDebug() << "cleanupTestCase 3";
}
2 changes: 1 addition & 1 deletion OMEdit/Testsuite/RunOMEditTestsuite.sh
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

testcases=( "BrowseMSL" "Diagram" "Transformation" "Homotopy" "Expression" "ModelInstance" )
testcases=( "BrowseMSL" "Diagram" "Transformation" "Homotopy" "Expression" "ModelInstance" "Utilities" )
OMEditTestResults="$PWD/OMEditTestResult"

for testcase in "${testcases[@]}"
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/Testsuite/Testsuite.pro
Expand Up @@ -36,7 +36,8 @@ SUBDIRS = Util \
Transformation \
Homotopy \
Expression \
ModelInstance
ModelInstance \
Utilities

BrowseMSL.depends = Util
Diagram.depends = Util
Expand Down
38 changes: 38 additions & 0 deletions OMEdit/Testsuite/Utilities/Utilities.pro
@@ -0,0 +1,38 @@
#
# This file is part of OpenModelica.
#
# Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
# c/o Linköpings universitet, Department of Computer and Information Science,
# SE-58183 Linköping, Sweden.
#
# All rights reserved.
#
# THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
# THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
# ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
# OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
#
# The OpenModelica software and the Open Source Modelica
# Consortium (OSMC) Public License (OSMC-PL) are obtained
# from OSMC, either from the above address,
# from the URLs: http://www.ida.liu.se/projects/OpenModelica or
# http://www.openmodelica.org, and in the OpenModelica distribution.
# GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
#
# This program is distributed WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
# IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
#
# See the full OSMC Public License conditions for more details.
#
#/

include(../Common/Testsuite.pri)
include(../Common/Util.pri)

TARGET = Utilities

SOURCES += UtilitiesTest.cpp

HEADERS += UtilitiesTest.h
76 changes: 76 additions & 0 deletions OMEdit/Testsuite/Utilities/UtilitiesTest.cpp
@@ -0,0 +1,76 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#include "UtilitiesTest.h"
#include "Util.h"
#include "OMEditApplication.h"
#include "MainWindow.h"
#include "Util/Utilities.h"

#define GC_THREADS
extern "C" {
#include "meta/meta_modelica.h"
}

OMEDITTEST_MAIN(UtilitiesTest)

void UtilitiesTest::literalConstant()
{
QFETCH(QString, string);

if (!Utilities::isValueLiteralConstant(string)) {
QFAIL(QString("The value %1 is not a literal constant.").arg(string).toStdString().c_str());
}
}

void UtilitiesTest::literalConstant_data()
{
QTest::addColumn<QString>("string");

QTest::newRow("Integer") << "123";
QTest::newRow("Negative integer value") << "-23";
QTest::newRow("Integer array") << "{1,2,3}";
QTest::newRow("Integer array with whitespace") << "{11, 981 ,34}";
QTest::newRow("Decimal") << "56.7";
QTest::newRow("Negative decimal value") << "-10.00";
QTest::newRow("Decimal array") << "{3.11,5.289,3.4798}";
QTest::newRow("Decimal array with whitespace") << "{7.89 , 2.2 , 567.8}";
QTest::newRow("Exponential form") << "1e-09";
QTest::newRow("Exponential form array with whitespace") << "{1e-09 , 2e-3 , 0.456e7}";
}

void UtilitiesTest::cleanupTestCase()
{
MainWindow::instance()->close();
}
53 changes: 53 additions & 0 deletions OMEdit/Testsuite/Utilities/UtilitiesTest.h
@@ -0,0 +1,53 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#ifndef UTILITIESTEST_H
#define UTILITIESTEST_H

#include <QObject>

/*!
* \brief The UtilitiesTest class
*/
class UtilitiesTest: public QObject
{
Q_OBJECT

private slots:
void literalConstant();
void literalConstant_data();
void cleanupTestCase();
};

#endif // UTILITIESTEST_H

0 comments on commit 04a453a

Please sign in to comment.