BufferedValueTests.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "tests/BufferedValueTests.h"
  2. #include "math/BufferedValue.h"
  3. #include "tests/Test.h"
  4. const float eps = 0.0001f;
  5. static void testInit(Test& test) {
  6. BufferedValue<float> b = 5.0f;
  7. test.checkFloat(5.0f, b.get(0.0f), eps, "init 1");
  8. test.checkFloat(5.0f, b.get(0.5f), eps, "init 2");
  9. test.checkFloat(5.0f, b.get(1.0f), eps, "init 3");
  10. test.checkFloat(5.0f, b, eps, "init 4");
  11. }
  12. static void testInterpolate(Test& test) {
  13. BufferedValue<float> b = 5.0f;
  14. b = 7.0f;
  15. test.checkFloat(5.0f, b.get(0.0f), eps, "interpolate 1");
  16. test.checkFloat(6.0f, b.get(0.5f), eps, "interpolate 2");
  17. test.checkFloat(7.0f, b.get(1.0f), eps, "interpolate 3");
  18. test.checkFloat(7.0f, b, eps, "interpolate 4");
  19. }
  20. static void testUpdate(Test& test) {
  21. BufferedValue<float> b = 5.0f;
  22. b = 7.0f;
  23. b.update();
  24. test.checkFloat(7.0f, b.get(0.0f), eps, "update 1");
  25. test.checkFloat(7.0f, b.get(0.5f), eps, "update 2");
  26. test.checkFloat(7.0f, b.get(1.0f), eps, "update 3");
  27. test.checkFloat(7.0f, b, eps, "update 4");
  28. }
  29. static void testCalculate(Test& test) {
  30. BufferedValue<float> b = 5.0f;
  31. b = 7.0f;
  32. b += 3.0f;
  33. test.checkFloat(5.0f, b.get(0.0f), eps, "interpolate 1");
  34. test.checkFloat(7.5f, b.get(0.5f), eps, "interpolate 2");
  35. test.checkFloat(10.0f, b.get(1.0f), eps, "interpolate 3");
  36. test.checkFloat(10.0f, b, eps, "interpolate 4");
  37. }
  38. void BufferedValueTests::test() {
  39. Test test("BufferedValue");
  40. testInit(test);
  41. testInterpolate(test);
  42. testUpdate(test);
  43. testCalculate(test);
  44. test.finalize();
  45. }