From 32d01ded03b896ee01caebb698dcee59805deb14 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Fri, 12 Jun 2020 20:20:01 +0200 Subject: [PATCH] Added some tests --- tests/TuningT.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/TuningT.cpp b/tests/TuningT.cpp index 76c94d67..430c031c 100644 --- a/tests/TuningT.cpp +++ b/tests/TuningT.cpp @@ -15,3 +15,109 @@ TEST_CASE("[Tuning] Default tuning") for (int key = 0; key < 128; ++key) REQUIRE(defaultTuning.getFrequencyOfKey(key) == Approx(midiNoteFrequency(key))); } + +TEST_CASE("[Tuning] Railsback disabled") +{ + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.0f); + for (int key = 0; key < 128; ++key) + REQUIRE(tuning.getRatioForIntegralKey(key) == 1.0f); +} + +TEST_CASE("[Tuning] Stretch integral == float") +{ + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.25f); + for (int key = 0; key < 128; ++key) + REQUIRE(tuning.getRatioForIntegralKey(key) == tuning.getRatioForFractionalKey(static_cast(key))); +} + +TEST_CASE("[Tuning] Stretch definition points") +{ + SECTION("For 0.5f") + { + static constexpr float railsback[128] = { + #include "sfizz/railsback/4-1.h" + }; + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.5f); + for (int key = 0; key < 128; ++key) + REQUIRE(tuning.getRatioForIntegralKey(key) == railsback[key]); + } + SECTION("For 1.0f") + { + static constexpr float railsback[128] = { + #include "sfizz/railsback/4-2.h" + }; + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(1.0f); + for (int key = 0; key < 128; ++key) + REQUIRE(tuning.getRatioForIntegralKey(key) == railsback[key]); + } + + SECTION("For 0.25f") + { + static constexpr float railsback[128] = { + #include "sfizz/railsback/2-1.h" + }; + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.25f); + for (int key = 0; key < 128; ++key) + REQUIRE(tuning.getRatioForIntegralKey(key) == railsback[key]); + } +} + +TEST_CASE("[Tuning] Stretch interpolation bounds") +{ + SECTION("Between 0 and 0.25f") + { + static constexpr float bound1[128] = { + #include "sfizz/railsback/2-1.h" + }; + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.1f); + for (int key = 0; key < 128; ++key) { + if (bound1[key] < 1.0f) { + REQUIRE(tuning.getRatioForIntegralKey(key) >= bound1[key]); + REQUIRE(tuning.getRatioForIntegralKey(key) <= 1.0f); + } else { + REQUIRE(tuning.getRatioForIntegralKey(key) <= bound1[key]); + REQUIRE(tuning.getRatioForIntegralKey(key) >= 1.0f); + } + } + } + SECTION("Between 0.25f and 0.5f") + { + static constexpr float bound1[128] = { + #include "sfizz/railsback/2-1.h" + }; + static constexpr float bound2[128] = { + #include "sfizz/railsback/4-1.h" + }; + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.3f); + for (int key = 0; key < 128; ++key) { + if (bound1[key] < bound2[key]) { + REQUIRE(tuning.getRatioForIntegralKey(key) >= bound1[key]); + REQUIRE(tuning.getRatioForIntegralKey(key) <= bound2[key]); + } else { + REQUIRE(tuning.getRatioForIntegralKey(key) <= bound1[key]); + REQUIRE(tuning.getRatioForIntegralKey(key) >= bound2[key]); + } + } + } + SECTION("Between 0.5f and 1.0f") + { + static constexpr float bound1[128] = { + #include "sfizz/railsback/4-1.h" + }; + static constexpr float bound2[128] = { + #include "sfizz/railsback/4-2.h" + }; + auto tuning = sfz::StretchTuning::createRailsbackFromRatio(0.7f); + for (int key = 0; key < 128; ++key) { + if (bound1[key] < bound2[key]) { + REQUIRE(tuning.getRatioForIntegralKey(key) >= bound1[key]); + REQUIRE(tuning.getRatioForIntegralKey(key) <= bound2[key]); + } else { + REQUIRE(tuning.getRatioForIntegralKey(key) <= bound1[key]); + REQUIRE(tuning.getRatioForIntegralKey(key) >= bound2[key]); + } + } + } +} + +