Add some more tests

This commit is contained in:
Dorian Zedler 2021-05-11 20:08:36 +02:00
parent d5d8f5cffc
commit b25a70a96c
Signed by: dorian
GPG key ID: 989DE36109AFA354
5 changed files with 161 additions and 30 deletions

View file

@ -0,0 +1,10 @@
#include "scstwtestingtimer.h"
ScStwTestingTimer::ScStwTestingTimer()
{
}
void ScStwTestingTimer::handleClimberStart(double timeOfStart) {
ScStwTimer::handleClimberStart(timeOfStart);
}

View file

@ -0,0 +1,14 @@
#ifndef SCSTWTESTINGTIMER_H
#define SCSTWTESTINGTIMER_H
#include <scstwtimer.h>
#include <QObject>
class ScStwTestingTimer : public ScStwTimer
{
public:
ScStwTestingTimer();
void handleClimberStart(double timeOfStart);
};
#endif // SCSTWTESTINGTIMER_H

View file

@ -7,8 +7,13 @@ CONFIG -= app_bundle
TEMPLATE = app
SOURCES += \
scstwtestingtimer.cpp \
tst_scstwrace.cpp \
tst_scstwtimertests.cpp
# include submodules
CONFIG += ScStwLibraries_QML ScStwLibraries_Styling ScStwLibraries_ClientLibs
include($$PWD/../ScStwLibraries.pri)
HEADERS += \
scstwtestingtimer.h

View file

@ -0,0 +1,49 @@
#include <QtTest>
#include <QDateTime>
#include "scstwrace.h"
// add necessary includes here
class ScStwRaceTests : public QObject
{
Q_OBJECT
public:
ScStwRaceTests();
~ScStwRaceTests();
private slots:
void initTestCase();
void cleanupTestCase();
void basic_cycle();
};
ScStwRaceTests::ScStwRaceTests()
{
}
ScStwRaceTests::~ScStwRaceTests()
{
}
void ScStwRaceTests::initTestCase()
{
}
void ScStwRaceTests::cleanupTestCase()
{
}
void ScStwRaceTests::basic_cycle()
{
}
#include "tst_scstwrace.moc"

View file

@ -1,5 +1,8 @@
#include <QtTest>
#include "scstwlibraries.h"
#include <QDateTime>
#include "scstwtimer.h"
#include "scstwtestingtimer.h"
// add necessary includes here
@ -15,9 +18,12 @@ private slots:
void initTestCase();
void cleanupTestCase();
void basic_cycle_cancelled();
void basic_cycle_won();
void basic_cycle_lost();
void basic_cycle_failed();
void basic_cycle_wildcard();
};
@ -41,46 +47,93 @@ void ScStwTimerTests::cleanupTestCase()
}
void ScStwTimerTests::basic_cycle_cancelled()
{
ScStwTimer timer;
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
timer.start();
QCOMPARE(timer.getState(), ScStwTimer::RUNNING);
QCOMPARE(timer.isRunning(), true);
timer.cancel();
QCOMPARE(timer.getState(), ScStwTimer::CANCELLED);
timer.reset();
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
}
void ScStwTimerTests::basic_cycle_won()
{
ScStwTimer * timer = new ScStwTimer();
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
timer->start();
QCOMPARE(timer->getState(), ScStwTimer::RUNNING);
timer->stop();
QCOMPARE(timer->getState(), ScStwTimer::WAITING);
timer->setResult(ScStwTimer::WON);
QCOMPARE(timer->getState(), ScStwTimer::WON);
timer->reset();
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
ScStwTimer timer;
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
timer.start();
QCOMPARE(timer.getState(), ScStwTimer::RUNNING);
QCOMPARE(timer.isRunning(), true);
timer.stop();
QCOMPARE(timer.getState(), ScStwTimer::WAITING);
timer.setResult(ScStwTimer::WON);
QCOMPARE(timer.getState(), ScStwTimer::WON);
timer.reset();
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
}
void ScStwTimerTests::basic_cycle_lost()
{
ScStwTimer * timer = new ScStwTimer();
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
timer->start();
QCOMPARE(timer->getState(), ScStwTimer::RUNNING);
timer->stop();
QCOMPARE(timer->getState(), ScStwTimer::WAITING);
timer->setResult(ScStwTimer::LOST);
QCOMPARE(timer->getState(), ScStwTimer::LOST);
timer->reset();
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
ScStwTimer timer;
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
timer.start();
QCOMPARE(timer.getState(), ScStwTimer::RUNNING);
QCOMPARE(timer.isRunning(), true);
timer.stop();
QCOMPARE(timer.getState(), ScStwTimer::WAITING);
timer.setResult(ScStwTimer::LOST);
QCOMPARE(timer.getState(), ScStwTimer::LOST);
timer.reset();
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
}
void ScStwTimerTests::basic_cycle_failed()
{
ScStwTimer * timer = new ScStwTimer();
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
timer->start();
QCOMPARE(timer->getState(), ScStwTimer::RUNNING);
double startTime = QDateTime::currentMSecsSinceEpoch() + 1000;
ScStwTestingTimer timer;
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
timer.start(startTime);
QCOMPARE(timer.getState(), ScStwTimer::STARTING);
timer.handleClimberStart(startTime - 1000);
QCOMPARE(timer.getState(), ScStwTimer::FAILING);
QCOMPARE(timer->getState(), ScStwTimer::WAITING);
timer->setResult(ScStwTimer::WON);
QCOMPARE(timer->getState(), ScStwTimer::WON);
timer->reset();
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
timer.setResult(ScStwTimer::FAILED);
QCOMPARE(timer.getState(), ScStwTimer::FAILED);
QCOMPARE(timer.getReactionTime(), -1000);
timer.reset();
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
}
void ScStwTimerTests::basic_cycle_wildcard()
{
double startTime = QDateTime::currentMSecsSinceEpoch() + 1000;
ScStwTestingTimer timer;
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
timer.start(startTime);
QCOMPARE(timer.getState(), ScStwTimer::STARTING);
timer.handleClimberStart(startTime - 1000);
QCOMPARE(timer.getState(), ScStwTimer::FAILING);
timer.setResult(ScStwTimer::WILDCARD);
QCOMPARE(timer.getState(), ScStwTimer::WILDCARD);
QCOMPARE(timer.getReactionTime(), -1000);
timer.reset();
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
}
QTEST_APPLESS_MAIN(ScStwTimerTests)