11namespace tracktion {
inline namespace engine
14#if TRACKTION_UNIT_TESTS && ENGINE_UNIT_TESTS_CONSTRAINED_CACHED_VALUE
19 ConstrainedCachedValueTests()
20 :
juce::UnitTest (
"ConstrainedCachedValue ",
"Tracktion") {}
23 void runTest()
override
25 beginTest (
"Odd/even tests");
28 ConstrainedCachedValue<int> value;
29 value.setConstrainer ([] (
int v) {
return v % 2 == 0 ? v : v + 1; });
30 value.referTo (state,
"value",
nullptr);
32 expectEquals (value.get(), 0);
34 expectEquals (value.get(), 2);
36 expectEquals (value.get(), 2);
38 expectEquals (value.get(), 18);
41 beginTest (
"ceil/floor tests");
44 ConstrainedCachedValue<float> value;
46 value.setConstrainer ([&useCeil] (
float v) {
return useCeil ?
std::ceil (v) :
std::
floor (v); });
47 value.referTo (state,
"value",
nullptr);
49 expectWithinAbsoluteError (value.getDefault(), 0.0f, 0.00000000000001f);
50 expectWithinAbsoluteError (value.get(), 0.0f, 0.00000000000001f);
52 expectWithinAbsoluteError (value.get(), 2.0f, 0.00000000000001f);
54 expectWithinAbsoluteError (value.get(), 3.0f, 0.00000000000001f);
58 expectWithinAbsoluteError (value.get(), 2.0f, 0.00000000000001f);
60 expectWithinAbsoluteError (value.get(), 1.0f, 0.00000000000001f);
62 expectWithinAbsoluteError (value.get(), -3.0f, 0.00000000000001f);
64 value.referTo (state,
"value",
nullptr, 1.2f);
65 expectWithinAbsoluteError (value.getDefault(), 1.0f, 0.00000000000001f);
66 expectWithinAbsoluteError (value.get(), -3.0f, 0.00000000000001f);
71static ConstrainedCachedValueTests constrainedCachedValueTests;