First few test cases

This commit is contained in:
Tobias Berger 2021-09-17 12:32:14 +02:00
parent 9ce7e4ed96
commit 1b7b25e09e
6 changed files with 95 additions and 51 deletions

View file

@ -6,8 +6,9 @@ CONFIG -= app_bundle
TEMPLATE = app TEMPLATE = app
SOURCES += tst_testcasename.cpp \ SOURCES += \
fraction.cpp fraction.cpp \
tst_fractiontest.cpp
HEADERS += \ HEADERS += \
fraction.hpp fraction.hpp

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.12.3, 2021-09-17T11:54:22. --> <!-- Written by QtCreator 4.12.3, 2021-09-17T12:29:53. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -54,7 +54,24 @@
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.PluginSettings</variable> <variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/> <valuemap type="QVariantMap">
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
<value type="QString">-fno-delayed-template-parsing</value>
</valuelist>
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
<value type="QString" key="ClangCodeModel.WarningConfigId">Builtin.Questionable</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">2</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs">
<value type="QString">C:/Users/$5NP000-N4QVBFC8R26B/Documents/FractionTask/FractionTask.pro</value>
</valuelist>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.Target.0</variable> <variable>ProjectExplorer.Project.Target.0</variable>
@ -293,19 +310,19 @@
</valuelist> </valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/$5NP000-N4QVBFC8R26B/Documents/FractionTask/FractionTask.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value> <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/$5NP000-N4QVBFC8R26B/Documents/FractionTask/FractionTask.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="QString" key="RunConfiguration.Arguments"></value> <value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value> <value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value> <value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value> <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value> <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value> <value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/$5NP000-N4QVBFC8R26B/Documents/build-FractionTask-Desktop_Qt_5_15_0_MinGW_64_bit-Debug</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>

View file

@ -1,6 +1,5 @@
#include "fraction.h" #include "fraction.hpp"
Fraction::Fraction() Fraction::Fraction()
{ {
} }

View file

@ -1,11 +1,7 @@
#ifndef FRACTION_H #pragma once
#define FRACTION_H
class Fraction class Fraction
{ {
public: public:
Fraction(); Fraction(int, int);
}; };
#endif // FRACTION_H

66
tst_fractiontest.cpp Normal file
View file

@ -0,0 +1,66 @@
#include <QtTest>
#include "fraction.hpp"
class FractionTest : public QObject
{
Q_OBJECT
public:
FractionTest();
~FractionTest();
private slots:
void test_constructor();
void test_equivalence();
};
FractionTest::FractionTest()
{
}
FractionTest::~FractionTest()
{
}
void FractionTest::test_constructor()
{
Fraction f1 = Fraction(1, 2);
QVERIFY(f1 == 0.5f);
QVERIFY(f1 == 0.5);
QVERIFY(f1.numerator() == 1);
QVERIFY(f1.denominator() == 2);
Fraction f2 = Fraction(2,4);
QVERIFY(f1 == f2);
QVERIFY(f2 == 0.5f);
QVERIFY(f2 == 0.5);
QVERIFY(f2.numerator() == 1);
QVERIFY(f2.denominator() == 2);
}
void FractionTest::test_equivalence()
{
Fraction f1 = Fraction(1, 1);
Fraction f2 = Fraction(1, 1);
QVERIFY(f1 == f2);
QVERIFY(f1 == 1);
QVERIFY(f1 == 1.0);
QVERIFY(f1 == 1.0f);
QVERIFY(f2 == 1);
QVERIFY(f2 == 1.0);
QVERIFY(f2 == 1.0f);
Fraction f3 = Fraction(2, 3);
QVERIFY(f3 != 1);
QVERIFY(f3 != 1.0);
QVERIFY(f3 != 1.0f);
}
QTEST_APPLESS_MAIN(FractionTest)
#include "tst_fractiontest.moc"

View file

@ -1,35 +0,0 @@
#include <QtTest>
// add necessary includes here
class TestCaseName : public QObject
{
Q_OBJECT
public:
TestCaseName();
~TestCaseName();
private slots:
void test_case1();
};
TestCaseName::TestCaseName()
{
}
TestCaseName::~TestCaseName()
{
}
void TestCaseName::test_case1()
{
}
QTEST_APPLESS_MAIN(TestCaseName)
#include "tst_testcasename.moc"