AnimTestbed/tests/SyncTrackTests.cc

81 lines
2.7 KiB
C++
Raw Normal View History

//
// Created by martin on 16.11.21.
//
#include "catch.hpp"
2021-11-16 18:23:04 +01:00
#include "SkinnedMesh.h"
TEST_CASE("SyncTrackBlendSimple", "[SyncTrackBlend]") {
SyncTrack track_A;
track_A.m_num_intervals = 2;
track_A.m_duration = 2.0;
track_A.m_interval_durations[0] = 0.7;
track_A.m_interval_durations[1] = 0.3;
2021-11-16 18:23:04 +01:00
SyncTrack track_B;
track_B.m_num_intervals = 2;
track_B.m_duration = 1.5;
track_B.m_interval_durations[0] = 0.6;
track_B.m_interval_durations[1] = 0.4;
WHEN ("Calculating sync time of track_B at 0.5 duration") {
float sync_time_at_0_75 = track_B.CalcSyncFromAbsTime(0.5 * track_B.m_duration);
REQUIRE(sync_time_at_0_75 == Catch::Detail::Approx(0.83333));
}
WHEN ("Calculating sync time of track_B at 0.6 duration") {
float sync_time_at_0_6 = track_B.CalcSyncFromAbsTime(0.6 * track_B.m_duration);
REQUIRE(sync_time_at_0_6 == Catch::Detail::Approx(1.0));
}
WHEN ("Calculating sync time of track_B at 0.7 duration") {
float sync_time_at_0_7 = track_B.CalcSyncFromAbsTime(0.7 * track_B.m_duration);
REQUIRE(sync_time_at_0_7 == Catch::Detail::Approx(1.25));
}
WHEN ("Calculating sync time of track_B at 0.0 duration") {
float sync_time_at_1_0 = track_B.CalcSyncFromAbsTime(0.0 * track_B.m_duration);
REQUIRE(sync_time_at_1_0 == Catch::Detail::Approx(0.0));
}
WHEN ("Calculating sync time of track_B at 1.0 duration") {
float sync_time_at_1_0 = track_B.CalcSyncFromAbsTime(0.9999 * track_B.m_duration);
REQUIRE(sync_time_at_1_0 == Catch::Detail::Approx(2.0).epsilon(0.001f));
}
WHEN ("Calculating ratio from sync time on track_A at 0.83333") {
float ratio = track_A.CalcRatioFromSyncTime(0.83333333);
REQUIRE (ratio == Catch::Detail::Approx(0.5833333));
}
WHEN ("Calculating ratio from sync time on track_A at 0.83333") {
float ratio = track_A.CalcRatioFromSyncTime(1.25);
REQUIRE (ratio == Catch::Detail::Approx(0.775));
}
2021-11-16 18:23:04 +01:00
WHEN("Blending two synctracks with weight 0.") {
SyncTrack blended = SyncTrack::Blend(0.f, track_A, track_B);
THEN ("Result must equal track_A") {
REQUIRE(blended.m_duration == track_A.m_duration);
REQUIRE(
blended.m_interval_durations[0] == track_A.m_interval_durations[0]);
REQUIRE(
blended.m_interval_durations[1] == track_A.m_interval_durations[1]);
}
}
WHEN("Blending two synctracks with weight 1.") {
SyncTrack blended = SyncTrack::Blend(1.f, track_A, track_B);
THEN ("Result must equal track_B") {
REQUIRE(blended.m_duration == track_B.m_duration);
REQUIRE(
blended.m_interval_durations[0] == track_B.m_interval_durations[0]);
REQUIRE(
blended.m_interval_durations[1] == track_B.m_interval_durations[1]);
}
}
}