|
@@ -1,9 +1,20 @@
|
|
|
#include "tests/BufferedValueTests.h"
|
|
|
#include "math/BufferedValue.h"
|
|
|
+#include "math/Vector.h"
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
const float eps = 0.0001f;
|
|
|
|
|
|
+template<int N, typename T>
|
|
|
+static void compareVectors(Test& test, const Vector<N, T>& wanted,
|
|
|
+ const Vector<N, T>& actual, const char* text) {
|
|
|
+ for(int i = 0; i < N; i++) {
|
|
|
+ test.checkFloat(
|
|
|
+ wanted[i], actual[i], eps,
|
|
|
+ StringBuffer<100>(text).append(" (").append(i).append(")"));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void testInit(Test& test) {
|
|
|
BufferedValue<float> b = 5.0f;
|
|
|
test.checkFloat(5.0f, b.get(0.0f), eps, "init 1");
|
|
@@ -35,10 +46,48 @@ 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");
|
|
|
+ test.checkFloat(5.0f, b.get(0.0f), eps, "calculate 1");
|
|
|
+ test.checkFloat(7.5f, b.get(0.5f), eps, "calculate 2");
|
|
|
+ test.checkFloat(10.0f, b.get(1.0f), eps, "calculate 3");
|
|
|
+ test.checkFloat(10.0f, b, eps, "calculate 4");
|
|
|
+ test.checkFloat(12.0f, b + 2.0f, eps, "calculate 5");
|
|
|
+}
|
|
|
+
|
|
|
+static void testVector(Test& test) {
|
|
|
+ Vector2 base(5.0f, 6.0f);
|
|
|
+ BufferedValue<Vector2> b = base;
|
|
|
+
|
|
|
+ compareVectors(test, base, b.get(1.0f), "vector 1");
|
|
|
+ b = Vector2(7.0f, 5.0);
|
|
|
+ compareVectors(test, Vector2(7.0f, 5.0f), b.get(1.0f), "vector 2");
|
|
|
+ b += Vector2(1.0f, 1.0f);
|
|
|
+ compareVectors(test, Vector2(8.0f, 6.0f), b.get(1.0f), "vector 3");
|
|
|
+ b -= Vector2(1.0f, 1.0f);
|
|
|
+ compareVectors(test, Vector2(7.0f, 5.0f), b.get(1.0f), "vector 4");
|
|
|
+ b *= Vector2(2.0f, 2.0f);
|
|
|
+ compareVectors(test, Vector2(14.0f, 10.0f), b.get(1.0f), "vector 5");
|
|
|
+ b /= Vector2(0.5f, 0.5f);
|
|
|
+ compareVectors(test, Vector2(28.0f, 20.0f), b.get(1.0f), "vector 6");
|
|
|
+ b = b + Vector2(1.0f, 1.0f);
|
|
|
+ compareVectors(test, Vector2(29.0f, 21.0f), b.get(1.0f), "vector 7");
|
|
|
+ b = b - Vector2(1.0f, 1.0f);
|
|
|
+ compareVectors(test, Vector2(28.0f, 20.0f), b.get(1.0f), "vector 8");
|
|
|
+ b = b * Vector2(2.0f, 2.0f);
|
|
|
+ compareVectors(test, Vector2(56.0f, 40.0f), b.get(1.0f), "vector 9");
|
|
|
+ b = b / Vector2(0.5f, 0.5f);
|
|
|
+ compareVectors(test, Vector2(112.0f, 80.0f), b.get(1.0f), "vector 10");
|
|
|
+ b = Vector2(1.0f, 1.0f) + b;
|
|
|
+ compareVectors(test, Vector2(113.0f, 81.0f), b.get(1.0f), "vector 11");
|
|
|
+ b = Vector2(1.0f, 1.0f) - b;
|
|
|
+ compareVectors(test, Vector2(-112.0f, -80.0f), b.get(1.0f), "vector 12");
|
|
|
+ b = Vector2(2.0f, 2.0f) * b;
|
|
|
+ compareVectors(test, Vector2(-224.0f, -160.0f), b.get(1.0f), "vector 13");
|
|
|
+ b = Vector2(224.0f, 160.0f) / b;
|
|
|
+ compareVectors(test, Vector2(-1.0f, -1.0f), b.get(1.0f), "vector 14");
|
|
|
+ b = -b;
|
|
|
+ compareVectors(test, Vector2(1.0f, 1.0f), b.get(1.0f), "vector 15");
|
|
|
+ b[0] += 3;
|
|
|
+ compareVectors(test, Vector2(4.0f, 1.0f), b.get(1.0f), "vector 16");
|
|
|
}
|
|
|
|
|
|
void BufferedValueTests::test() {
|
|
@@ -47,5 +96,6 @@ void BufferedValueTests::test() {
|
|
|
testInterpolate(test);
|
|
|
testUpdate(test);
|
|
|
testCalculate(test);
|
|
|
+ testVector(test);
|
|
|
test.finalize();
|
|
|
}
|