28 static CommonSmoothedValueTests <SmoothedValue<float, ValueSmoothingTypes::Linear>> commonLinearSmoothedValueTests;
29 static CommonSmoothedValueTests <SmoothedValue<float, ValueSmoothingTypes::Multiplicative>> commonMultiplicativeSmoothedValueTests;
31 class SmoothedValueTests :
public UnitTest
35 : UnitTest (
"SmoothedValueTests", UnitTestCategories::smoothedValues)
38 void runTest()
override 40 beginTest (
"Linear moving target");
42 SmoothedValue<float, ValueSmoothingTypes::Linear> sv;
45 float initialValue = 0.0f;
46 sv.setCurrentAndTargetValue (initialValue);
47 sv.setTargetValue (1.0f);
49 auto delta = sv.getNextValue() - initialValue;
53 auto newInitialValue = sv.getCurrentValue();
54 sv.setTargetValue (newInitialValue + 2.0f);
55 auto doubleDelta = sv.getNextValue() - newInitialValue;
57 expectWithinAbsoluteError (doubleDelta, delta * 2.0f, 1.0e-7f);
60 beginTest (
"Multiplicative curve");
62 SmoothedValue<double, ValueSmoothingTypes::Multiplicative> sv;
65 AudioBuffer<double> values (2, numSamples + 1);
67 sv.reset (numSamples);
68 sv.setCurrentAndTargetValue (1.0);
69 sv.setTargetValue (2.0f);
71 values.setSample (0, 0, sv.getCurrentValue());
73 for (
int i = 1; i < values.getNumSamples(); ++i)
74 values.setSample (0, i, sv.getNextValue());
76 sv.setTargetValue (1.0f);
77 values.setSample (1, values.getNumSamples() - 1, sv.getCurrentValue());
79 for (
int i = values.getNumSamples() - 2; i >= 0 ; --i)
80 values.setSample (1, i, sv.getNextValue());
82 for (
int i = 0; i < values.getNumSamples(); ++i)
83 expectWithinAbsoluteError (values.getSample (0, i), values.getSample (1, i), 1.0e-9);
88 static SmoothedValueTests smoothedValueTests;