Skip to content

Commit

Permalink
Merge pull request #17 from agateau/port-to-catch3
Browse files Browse the repository at this point in the history
Port to catch3
  • Loading branch information
agateau authored Aug 1, 2023
2 parents f642abd + 374fbff commit 2799823
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/catch2
Submodule catch2 updated 743 files
32 changes: 22 additions & 10 deletions tests/SoundTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
#include <QTemporaryDir>
#include <QUrl>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>

using Catch::Matchers::Equals;
using Catch::Matchers::WithinAbs;

static constexpr double PRECISION = 0.00001;

static auto Within(float value) {
return WithinAbs(value, PRECISION);
}

static bool fuzzyEq(const Sound& s1, const Sound& s2) {
QMetaObject mo = BaseSound::staticMetaObject;
Expand All @@ -19,7 +29,7 @@ static bool fuzzyEq(const Sound& s1, const Sound& s2) {
QVariant v2 = property.read(&s2);

if (property.type() == QVariant::Double) {
if (v1.toDouble() != Approx(v2.toDouble())) {
if (qAbs(v1.toDouble() - v2.toDouble()) > PRECISION) {
return false;
}
} else {
Expand All @@ -37,21 +47,23 @@ TEST_CASE("Sound") {
Sound sound;
auto path = QUrl::fromLocalFile(QString(TEST_FIXTURES_DIR) + "/pickup.sfxr");
REQUIRE(sound.load(path));
CHECK(sound.waveForm() == 0);
CHECK(sound.sustainTime() == Approx(0.05916));
CHECK(sound.baseFrequency() == Approx(0.5019));
CHECK(sound.changeSpeed() == Approx(0.54938));
CHECK(sound.waveForm() == WaveForm::Enum::Square);
CHECK_THAT(sound.sustainTime(), Within(0.05916));
CHECK_THAT(sound.sustainTime(), Within(0.05916));
CHECK_THAT(sound.sustainTime(), Within(0.05916));
CHECK_THAT(sound.baseFrequency(), Within(0.5019));
CHECK_THAT(sound.changeSpeed(), Within(0.54938));
CHECK(sound.phaserOffset() == 0);
}

SECTION("load sfxj") {
Sound sound;
auto path = QUrl::fromLocalFile(QString(TEST_FIXTURES_DIR) + "/pickup.sfxj");
REQUIRE(sound.load(path));
CHECK(sound.waveForm() == 0);
CHECK(sound.sustainTime() == Approx(0.05916));
CHECK(sound.baseFrequency() == Approx(0.5019));
CHECK(sound.changeSpeed() == Approx(0.54938));
CHECK(sound.waveForm() == WaveForm::Enum::Square);
CHECK_THAT(sound.sustainTime(), Within(0.05916));
CHECK_THAT(sound.baseFrequency(), Within(0.5019));
CHECK_THAT(sound.changeSpeed(), Within(0.54938));
CHECK(sound.phaserOffset() == 0);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/SynthesizerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QDir>
#include <QTemporaryDir>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

static constexpr char FIXTURES_DIR[] = TEST_FIXTURES_DIR "/synthesizer";

Expand Down
4 changes: 2 additions & 2 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#define CATCH_CONFIG_RUNNER
#include "SynthesizerTest.h"

#include <QCoreApplication>
#include <QtTest>

#include <catch2/catch.hpp>
#include <catch2/catch_session.hpp>
#include <catch2/catch_test_macros.hpp>

int main(int argc, char* argv[]) {
QCoreApplication app(argc, argv);
Expand Down

0 comments on commit 2799823

Please sign in to comment.