Cours:ClasseTestCorrecteurKp : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
(Annulation des modifications 20150 de Bjacquot (discussion))
 
Ligne 1 : Ligne 1 :
 
{|style="vertical-align:middle; width:100%; text-align:left; "
 
{|style="vertical-align:middle; width:100%; text-align:left; "
 
|-
 
|-
| {{boîte déroulante/début|titre=[[Media:.h|.h]]}}
+
| {{boîte déroulante/début|titre=[[Media:testcorrecteurkp.h|testcorrecteurkp.h]]}}
 
<source lang=cpp>
 
<source lang=cpp>
 +
#ifndef TESTCORRECTEURKP_H
 +
#define TESTCORRECTEURKP_H
  
 +
#include <QtTest/QTest>
 +
#include <QObject>
 +
 +
class TestCorrecteurKp : public QObject
 +
{
 +
    Q_OBJECT
 +
public:
 +
    explicit TestCorrecteurKp(QObject *parent = nullptr);
 +
private slots:
 +
    void process_data();
 +
    void process();
 +
 +
signals:
 +
};
 +
 +
#endif // TESTCORRECTEURKP_H
 
</source>
 
</source>
 
{{boîte déroulante/fin}}
 
{{boîte déroulante/fin}}
||{{boîte déroulante/début|titre=[[Media:.cpp|.cpp]]}}
+
||{{boîte déroulante/début|titre=[[Media:testcorrecteurkp.cpp|testcorrecteurkp.cpp]]}}
 
<source lang=cpp>
 
<source lang=cpp>
 +
#include "testcorrecteurkp.h"
 +
#include "correcteurkp.h"
 +
 +
TestCorrecteurKp::TestCorrecteurKp(QObject *parent)
 +
    : QObject{parent}
 +
{
 +
 +
}
 +
 +
void TestCorrecteurKp::process_data()
 +
{
 +
    QTest::addColumn<double>("consigne");
 +
    QTest::addColumn<double>("Kp");
 +
    QTest::addColumn<double>("input");
 +
    QTest::addColumn<double>("output");
 +
 +
    QTest::newRow("") << 100.0 << 1.0 << 100.0 << 0.0 ;
 +
    QTest::newRow("") << 100.0 << 1.0 << 80.0 << 20.0 ;
 +
    QTest::newRow("") << 100.0 << 1.0 << 120.0 << -20.0 ;
 +
    QTest::newRow("") << 80.0 << 1.0 << 80.0 << 0.0 ;
 +
    QTest::newRow("") << 80.0 << 1.0 << 70.0 << 10.0 ;
 +
    QTest::newRow("") << 80.0 << 1.0 << 90.0 << -10.0 ;
 +
 +
}
 +
 +
void TestCorrecteurKp::process()
 +
{
 +
 +
    QFETCH(double, consigne);
 +
    QFETCH(double, Kp);
 +
    QFETCH(double, input);
 +
    QFETCH(double, output);
 +
 +
    QCOMPARE(CorrecteurKp(consigne,Kp).process(input), output);
  
 +
}
 
</source>
 
</source>
 
{{boîte déroulante/fin}}
 
{{boîte déroulante/fin}}
Ligne 15 : Ligne 68 :
 
<source lang=cpp>
 
<source lang=cpp>
 
//main.cpp
 
//main.cpp
 +
#include "testcorrecteurkp.h"
  
 +
QTEST_MAIN(TestCorrecteurKp)
 
</source>
 
</source>

Version actuelle datée du 17 octobre 2025 à 16:42

testcorrecteurkp.h

#ifndef TESTCORRECTEURKP_H
#define TESTCORRECTEURKP_H

#include <QtTest/QTest>
#include <QObject>

class TestCorrecteurKp : public QObject
{
    Q_OBJECT
public:
    explicit TestCorrecteurKp(QObject *parent = nullptr);
private slots:
    void process_data();
    void process();

signals:
};

#endif // TESTCORRECTEURKP_H

testcorrecteurkp.cpp

#include "testcorrecteurkp.h"
#include "correcteurkp.h"

TestCorrecteurKp::TestCorrecteurKp(QObject *parent)
    : QObject{parent}
{

}

void TestCorrecteurKp::process_data()
{
    QTest::addColumn<double>("consigne");
    QTest::addColumn<double>("Kp");
    QTest::addColumn<double>("input");
    QTest::addColumn<double>("output");

    QTest::newRow("") << 100.0 << 1.0 << 100.0 << 0.0 ;
    QTest::newRow("") << 100.0 << 1.0 << 80.0 << 20.0 ;
    QTest::newRow("") << 100.0 << 1.0 << 120.0 << -20.0 ;
    QTest::newRow("") << 80.0 << 1.0 << 80.0 << 0.0 ;
    QTest::newRow("") << 80.0 << 1.0 << 70.0 << 10.0 ;
    QTest::newRow("") << 80.0 << 1.0 << 90.0 << -10.0 ;

}

void TestCorrecteurKp::process()
{

    QFETCH(double, consigne);
    QFETCH(double, Kp);
    QFETCH(double, input);
    QFETCH(double, output);

    QCOMPARE(CorrecteurKp(consigne,Kp).process(input), output);

}
//main.cpp
#include "testcorrecteurkp.h"

QTEST_MAIN(TestCorrecteurKp)