|
@@ -0,0 +1,51 @@
|
|
|
+#include "tests/BufferedValueTests.h"
|
|
|
+#include "math/BufferedValue.h"
|
|
|
+#include "tests/Test.h"
|
|
|
+
|
|
|
+const float eps = 0.0001f;
|
|
|
+
|
|
|
+static void testInit(Test& test) {
|
|
|
+ BufferedValue<float> b = 5.0f;
|
|
|
+ test.checkFloat(5.0f, b.get(0.0f), eps, "init 1");
|
|
|
+ test.checkFloat(5.0f, b.get(0.5f), eps, "init 2");
|
|
|
+ test.checkFloat(5.0f, b.get(1.0f), eps, "init 3");
|
|
|
+ test.checkFloat(5.0f, b, eps, "init 4");
|
|
|
+}
|
|
|
+
|
|
|
+static void testInterpolate(Test& test) {
|
|
|
+ BufferedValue<float> b = 5.0f;
|
|
|
+ b = 7.0f;
|
|
|
+ test.checkFloat(5.0f, b.get(0.0f), eps, "interpolate 1");
|
|
|
+ test.checkFloat(6.0f, b.get(0.5f), eps, "interpolate 2");
|
|
|
+ test.checkFloat(7.0f, b.get(1.0f), eps, "interpolate 3");
|
|
|
+ test.checkFloat(7.0f, b, eps, "interpolate 4");
|
|
|
+}
|
|
|
+
|
|
|
+static void testUpdate(Test& test) {
|
|
|
+ BufferedValue<float> b = 5.0f;
|
|
|
+ b = 7.0f;
|
|
|
+ b.update();
|
|
|
+ test.checkFloat(7.0f, b.get(0.0f), eps, "update 1");
|
|
|
+ test.checkFloat(7.0f, b.get(0.5f), eps, "update 2");
|
|
|
+ test.checkFloat(7.0f, b.get(1.0f), eps, "update 3");
|
|
|
+ test.checkFloat(7.0f, b, eps, "update 4");
|
|
|
+}
|
|
|
+
|
|
|
+static void testCalculate(Test& test) {
|
|
|
+ BufferedValue<float> b = 5.0f;
|
|
|
+ b = 7.0f;
|
|
|
+ b += 3.0f;
|
|
|
+ test.checkFloat(5.0f, b.get(0.0f), eps, "interpolate 1");
|
|
|
+ test.checkFloat(7.5f, b.get(0.5f), eps, "interpolate 2");
|
|
|
+ test.checkFloat(10.0f, b.get(1.0f), eps, "interpolate 3");
|
|
|
+ test.checkFloat(10.0f, b, eps, "interpolate 4");
|
|
|
+}
|
|
|
+
|
|
|
+void BufferedValueTests::test() {
|
|
|
+ Test test("BufferedValue");
|
|
|
+ testInit(test);
|
|
|
+ testInterpolate(test);
|
|
|
+ testUpdate(test);
|
|
|
+ testCalculate(test);
|
|
|
+ test.finalize();
|
|
|
+}
|