From 2fd8c892cf4cd5a3ad219d77bfda45ba5817bf2b Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Thu, 4 Feb 2021 11:02:09 +0100 Subject: [PATCH] Last test errors --- tests/FilesT.cpp | 23 ++++++++++++----------- tests/TestHelpers.h | 9 +++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/FilesT.cpp b/tests/FilesT.cpp index 0c25cfc9..07d12c03 100644 --- a/tests/FilesT.cpp +++ b/tests/FilesT.cpp @@ -147,11 +147,12 @@ TEST_CASE("[Files] Group from AVL") REQUIRE(synth.getRegionView(i)->volume == 6.0f); REQUIRE(synth.getRegionView(i)->keyRange == Range(36, 36)); } - REQUIRE(synth.getRegionView(0)->velocityRange == Range(1_norm, 26_norm)); - REQUIRE(synth.getRegionView(1)->velocityRange == Range(27_norm, 52_norm)); - REQUIRE(synth.getRegionView(2)->velocityRange == Range(53_norm, 77_norm)); - REQUIRE(synth.getRegionView(3)->velocityRange == Range(78_norm, 102_norm)); - REQUIRE(synth.getRegionView(4)->velocityRange == Range(103_norm, 127_norm)); + + almostEqualRanges(synth.getRegionView(0)->velocityRange, { 1_norm, 26_norm }); + almostEqualRanges(synth.getRegionView(1)->velocityRange, { 27_norm, 52_norm }); + almostEqualRanges(synth.getRegionView(2)->velocityRange, { 53_norm, 77_norm }); + almostEqualRanges(synth.getRegionView(3)->velocityRange, { 78_norm, 102_norm }); + almostEqualRanges(synth.getRegionView(4)->velocityRange, { 103_norm, 127_norm }); } TEST_CASE("[Files] Full hierarchy") @@ -242,14 +243,14 @@ TEST_CASE("[Files] Pizz basic") REQUIRE(synth.getNumRegions() == 4); for (int i = 0; i < synth.getNumRegions(); ++i) { REQUIRE(synth.getRegionView(i)->keyRange == Range(12, 22)); - REQUIRE(synth.getRegionView(i)->velocityRange == Range(97_norm, 127_norm)); + almostEqualRanges(synth.getRegionView(i)->velocityRange, { 97_norm, 127_norm }); REQUIRE(synth.getRegionView(i)->pitchKeycenter == 21); - REQUIRE(synth.getRegionView(i)->ccConditions.getWithDefault(107) == Range(0_norm, 13_norm)); + almostEqualRanges(synth.getRegionView(i)->ccConditions.getWithDefault(107), { 0_norm, 13_norm }); } - REQUIRE(synth.getRegionView(0)->randRange == Range(0, 0.25)); - REQUIRE(synth.getRegionView(1)->randRange == Range(0.25, 0.5)); - REQUIRE(synth.getRegionView(2)->randRange == Range(0.5, 0.75)); - REQUIRE(synth.getRegionView(3)->randRange == Range(0.75, 1.0)); + almostEqualRanges(synth.getRegionView(0)->randRange, { 0, 0.25 }); + almostEqualRanges(synth.getRegionView(1)->randRange, { 0.25, 0.5 }); + almostEqualRanges(synth.getRegionView(2)->randRange, { 0.5, 0.75 }); + almostEqualRanges(synth.getRegionView(3)->randRange, { 0.75, 1.0 }); REQUIRE(synth.getRegionView(0)->sampleId->filename() == R"(../Samples/pizz/a0_vl4_rr1.wav)"); REQUIRE(synth.getRegionView(1)->sampleId->filename() == R"(../Samples/pizz/a0_vl4_rr2.wav)"); REQUIRE(synth.getRegionView(2)->sampleId->filename() == R"(../Samples/pizz/a0_vl4_rr3.wav)"); diff --git a/tests/TestHelpers.h b/tests/TestHelpers.h index 31c5feb5..6a5fda7e 100644 --- a/tests/TestHelpers.h +++ b/tests/TestHelpers.h @@ -5,9 +5,11 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #pragma once +#include "catch2/catch.hpp" #include "sfizz/Synth.h" #include "sfizz/Region.h" #include "sfizz/Voice.h" +#include "sfizz/Range.h" #include "sfizz/modulations/ModKey.h" class RegionCCView { @@ -30,6 +32,13 @@ private: sfz::ModKey target_; }; +template +void almostEqualRanges(const sfz::Range& lhs, const sfz::Range& rhs) +{ + REQUIRE(lhs.getStart() == Approx(rhs.getStart())); + REQUIRE(lhs.getEnd() == Approx(rhs.getEnd())); +} + template void sortAll(C& container) {