1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "../Tests.hpp"
- #include "core/math/BufferedValue.hpp"
- #include "core/math/Vector.hpp"
- template class Core::BufferedValue<Core::Vector2>;
- using BufferedFloat = Core::BufferedValue<float>;
- const float eps = 0.0001f;
- static void testInit() {
- BufferedFloat b = 5.0f;
- CORE_TEST_FLOAT(5.0f, b.get(0.0f), eps);
- CORE_TEST_FLOAT(5.0f, b.get(0.5f), eps);
- CORE_TEST_FLOAT(5.0f, b.get(1.0f), eps);
- CORE_TEST_FLOAT(5.0f, b, eps);
- CORE_TEST_FLOAT(5.0f, static_cast<const BufferedFloat&>(b), eps);
- }
- static void testInterpolate() {
- BufferedFloat b = 5.0f;
- b = 7.0f;
- CORE_TEST_FLOAT(5.0f, b.get(0.0f), eps);
- CORE_TEST_FLOAT(6.0f, b.get(0.5f), eps);
- CORE_TEST_FLOAT(7.0f, b.get(1.0f), eps);
- CORE_TEST_FLOAT(7.0f, b, eps);
- }
- static void testUpdate() {
- BufferedFloat b = 5.0f;
- b = 7.0f;
- b.update();
- CORE_TEST_FLOAT(7.0f, b.get(0.0f), eps);
- CORE_TEST_FLOAT(7.0f, b.get(0.5f), eps);
- CORE_TEST_FLOAT(7.0f, b.get(1.0f), eps);
- CORE_TEST_FLOAT(7.0f, b, eps);
- }
- static void testCalculate() {
- BufferedFloat b = 5.0f;
- b = 7.0f;
- b += 3.0f;
- CORE_TEST_FLOAT(5.0f, b.get(0.0f), eps);
- CORE_TEST_FLOAT(7.5f, b.get(0.5f), eps);
- CORE_TEST_FLOAT(10.0f, b.get(1.0f), eps);
- CORE_TEST_FLOAT(10.0f, b, eps);
- CORE_TEST_FLOAT(12.0f, b + 2.0f, eps);
- }
- static void testVector2() {
- Core::Vector2 base(5.0f, 6.0f);
- using BufferedVector2 = Core::BufferedValue<Core::Vector2>;
- BufferedVector2 b = base;
- CORE_TEST_VECTOR(base, b.get(1.0f));
- b = Core::Vector2(7.0f, 5.0);
- CORE_TEST_VECTOR(Core::Vector2(7.0f, 5.0f), b.get(1.0f));
- b += Core::Vector2(1.0f, 1.0f);
- CORE_TEST_VECTOR(Core::Vector2(8.0f, 6.0f), b.get(1.0f));
- b -= Core::Vector2(1.0f, 1.0f);
- CORE_TEST_VECTOR(Core::Vector2(7.0f, 5.0f), b.get(1.0f));
- b *= Core::Vector2(2.0f, 2.0f);
- CORE_TEST_VECTOR(Core::Vector2(14.0f, 10.0f), b.get(1.0f));
- b /= Core::Vector2(0.5f, 0.5f);
- CORE_TEST_VECTOR(Core::Vector2(28.0f, 20.0f), b.get(1.0f));
- b = b + Core::Vector2(1.0f, 1.0f);
- CORE_TEST_VECTOR(Core::Vector2(29.0f, 21.0f), b.get(1.0f));
- b = b - Core::Vector2(1.0f, 1.0f);
- CORE_TEST_VECTOR(Core::Vector2(28.0f, 20.0f), b.get(1.0f));
- b = b * Core::Vector2(2.0f, 2.0f);
- CORE_TEST_VECTOR(Core::Vector2(56.0f, 40.0f), b.get(1.0f));
- b = b / Core::Vector2(0.5f, 0.5f);
- CORE_TEST_VECTOR(Core::Vector2(112.0f, 80.0f), b.get(1.0f));
- b = Core::Vector2(1.0f, 1.0f) + b;
- CORE_TEST_VECTOR(Core::Vector2(113.0f, 81.0f), b.get(1.0f));
- b = Core::Vector2(1.0f, 1.0f) - b;
- CORE_TEST_VECTOR(Core::Vector2(-112.0f, -80.0f), b.get(1.0f));
- b = Core::Vector2(2.0f, 2.0f) * b;
- CORE_TEST_VECTOR(Core::Vector2(-224.0f, -160.0f), b.get(1.0f));
- b = Core::Vector2(224.0f, 160.0f) / b;
- CORE_TEST_VECTOR(Core::Vector2(-1.0f, -1.0f), b.get(1.0f));
- b = -b;
- CORE_TEST_VECTOR(Core::Vector2(1.0f, 1.0f), b.get(1.0f));
- b[0] += 3;
- CORE_TEST_VECTOR(Core::Vector2(4.0f, 1.0f), b.get(1.0f));
- CORE_TEST_FLOAT(4.0f, static_cast<const BufferedVector2&>(b)[0], eps);
- }
- void Core::testBufferedValue() {
- testInit();
- testInterpolate();
- testUpdate();
- testCalculate();
- testVector2();
- }
|