<commit_before>/*-----------------------------------------------------------------------------
 This source file is a part of Hopsan

 Copyright (c) 2009 to present year, Hopsan Group

    This program 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.

    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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 For license details and information about the Hopsan Group see the files
 GPLv3 and HOPSANGROUP in the Hopsan source code root directory

 For author and contributor information see the AUTHORS file
-----------------------------------------------------------------------------*/

#include <QString>
#include <QtTest>

#include "ComponentUtilities.h"

using namespace hopsan;

Q_DECLARE_METATYPE(QVector<double>)

class ComponentUtilitiesTestTest : public QObject
{
    Q_OBJECT

public:
    ComponentUtilitiesTestTest()
    {

    }

private Q_SLOTS:
    void Limit_Value()
    {
        QFETCH(double, x);
        QFETCH(double, min);
        QFETCH(double, max);
        QFETCH(double, x_limited);

        limitValue(x, min, max);
        QVERIFY2(x == x_limited, "limitValue() returned wrong value!");
    }

    void Limit_Value_data()
    {
        QTest::addColumn<double>("x");
        QTest::addColumn<double>("min");
        QTest::addColumn<double>("max");
        QTest::addColumn<double>("x_limited");

        QTest::newRow("0") << 5.0 << 1.7 << 4.0 << 4.0;
        QTest::newRow("1") << 3.0 << 1.7 << 4.0 << 3.0;
        QTest::newRow("2") << 1.0 << 1.7 << 4.0 << 1.7;
        QTest::newRow("3") << 5.0 << -1.7 << 4.0 << 4.0;
        QTest::newRow("4") << -1.0 << -1.7 << 4.0 << -1.0;
        QTest::newRow("5") << -10.0 << -1.7 << 4.0 << -1.7;
        QTest::newRow("6") << -5.0 << -10.0 << -6.0 << -6.0;
    }

    void Fuzzy_Equal()
    {
        QFETCH(double, x);
        QFETCH(double, y);
        QFETCH(bool, equal);

        QVERIFY2(fuzzyEqual(x,y) == equal, "fuzzyEqual() returned wrong value!");
    }

    void Fuzzy_Equal_data()
    {
        QTest::addColumn<double>("x");
        QTest::addColumn<double>("y");
        QTest::addColumn<bool>("equal");

        QTest::newRow("0") << 12.345 << 12.345 << true;
        QTest::newRow("1") << 12.345 << 12.346 << false;
        QTest::newRow("2") << -12.345 << -12.345 << true;
        QTest::newRow("3") << -12.345 << -12.346 << false;
    }

    void Signed_Square_L()
    {
        QFETCH(double, x);
        QFETCH(double, x0);

        QVERIFY2(fuzzyEqual(fabs(x)*pow(1.0/(pow(x0,4.0) + pow(fabs(x),2.0)),0.25)*sign(x), signedSquareL(x,x0)), "signedSquareL() returned wrong value!");
    }

    void Signed_Square_L_data()
    {
        QTest::addColumn<double>("x");
        QTest::addColumn<double>("x0");

        QTest::newRow("0") << 0.0 << 1.0;
        for(int i=1; i<100; ++i)
        {
            QTest::newRow("i") << (double)rand() - (double)RAND_MAX*0.5 << (double)rand()- (double)RAND_MAX*0.5;
        }
    }

    void Dx_Signed_Square_L()
    {
        QFETCH(double, x);
        QFETCH(double, x0);

        QVERIFY2(fuzzyEqual((pow(1.0/(pow(x0,4.0) + pow(fabs(x),2.0)),1.25)*(2.0*pow(x0,4.0) + pow(fabs(x),2.0))*
                  dxAbs(x)*sign(x))/2.0, dxSignedSquareL(x,x0)), "dxSignedSquareL() returned wrong value!");
    }
<commit_msg>Updated unit tests for new versions of signedSquareL and dxSignedSquareL<commit_after>/*-----------------------------------------------------------------------------
 This source file is a part of Hopsan

 Copyright (c) 2009 to present year, Hopsan Group

    This program 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.

    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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 For license details and information about the Hopsan Group see the files
 GPLv3 and HOPSANGROUP in the Hopsan source code root directory

 For author and contributor information see the AUTHORS file
-----------------------------------------------------------------------------*/

#include <QString>
#include <QtTest>

#include "ComponentUtilities.h"

using namespace hopsan;

Q_DECLARE_METATYPE(QVector<double>)

class ComponentUtilitiesTestTest : public QObject
{
    Q_OBJECT

public:
    ComponentUtilitiesTestTest()
    {

    }

private Q_SLOTS:
    void Limit_Value()
    {
        QFETCH(double, x);
        QFETCH(double, min);
        QFETCH(double, max);
        QFETCH(double, x_limited);

        limitValue(x, min, max);
        QVERIFY2(x == x_limited, "limitValue() returned wrong value!");
    }

    void Limit_Value_data()
    {
        QTest::addColumn<double>("x");
        QTest::addColumn<double>("min");
        QTest::addColumn<double>("max");
        QTest::addColumn<double>("x_limited");

        QTest::newRow("0") << 5.0 << 1.7 << 4.0 << 4.0;
        QTest::newRow("1") << 3.0 << 1.7 << 4.0 << 3.0;
        QTest::newRow("2") << 1.0 << 1.7 << 4.0 << 1.7;
        QTest::newRow("3") << 5.0 << -1.7 << 4.0 << 4.0;
        QTest::newRow("4") << -1.0 << -1.7 << 4.0 << -1.0;
        QTest::newRow("5") << -10.0 << -1.7 << 4.0 << -1.7;
        QTest::newRow("6") << -5.0 << -10.0 << -6.0 << -6.0;
    }

    void Fuzzy_Equal()
    {
        QFETCH(double, x);
        QFETCH(double, y);
        QFETCH(bool, equal);

        QVERIFY2(fuzzyEqual(x,y) == equal, "fuzzyEqual() returned wrong value!");
    }

    void Fuzzy_Equal_data()
    {
        QTest::addColumn<double>("x");
        QTest::addColumn<double>("y");
        QTest::addColumn<bool>("equal");

        QTest::newRow("0") << 12.345 << 12.345 << true;
        QTest::newRow("1") << 12.345 << 12.346 << false;
        QTest::newRow("2") << -12.345 << -12.345 << true;
        QTest::newRow("3") << -12.345 << -12.346 << false;
    }

    void Signed_Square_L()
    {
        QFETCH(double, x);
        QFETCH(double, x0);

        QVERIFY2(fuzzyEqual(fabs(x)*pow(1.0/(pow(x0,2.0) + pow(fabs(x),2.0)),0.25)*sign(x), signedSquareL(x,x0)), "signedSquareL() returned wrong value!");
    }

    void Signed_Square_L_data()
    {
        QTest::addColumn<double>("x");
        QTest::addColumn<double>("x0");

        QTest::newRow("0") << 0.0 << 1.0;
        for(int i=1; i<100; ++i)
        {
            QTest::newRow("i") << (double)rand() - (double)RAND_MAX*0.5 << (double)rand()- (double)RAND_MAX*0.5;
        }
    }

    void Dx_Signed_Square_L()
    {
        QFETCH(double, x);
        QFETCH(double, x0);

        QVERIFY2(fuzzyEqual((pow(1.0/(pow(x0,2.0) + pow(fabs(x),2.0)),1.25)*(2.0*pow(x0,2.0) + pow(fabs(x),2.0))*
                  dxAbs(x)*sign(x))/2.0, dxSignedSquareL(x,x0)), "dxSignedSquareL() returned wrong value!");
    }

{'fraction_non_alphanumeric': 0.19776756401838477, 'fraction_numerical': 0.04359816152330926, 'mean_word_length': 2.3228621291448515, 'pattern_counts': {'":': 0, '<': 207, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5047468', 'n_tokens_mistral': 2772, 'n_tokens_neox': 2583, 'n_words': 619}