summaryrefslogtreecommitdiff
path: root/src/tests/test_maths.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_maths.cc')
-rw-r--r--src/tests/test_maths.cc19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/tests/test_maths.cc b/src/tests/test_maths.cc
index e7a686c..d9bc4d1 100644
--- a/src/tests/test_maths.cc
+++ b/src/tests/test_maths.cc
@@ -9,7 +9,9 @@
#include <vector>
// Checks if two floats are approximately equal
-bool near(float a, float b, float e = 0.001f) { return std::abs(a - b) < e; }
+bool near(float a, float b, float e = 0.001f) {
+ return std::abs(a - b) < e;
+}
// Generic test runner for any vector type (vec2, vec3, vec4)
template <typename T> void test_vector_ops(int n) {
@@ -22,16 +24,19 @@ template <typename T> void test_vector_ops(int n) {
// Add
T c = a + b;
- for (int i = 0; i < n; ++i) assert(near(c[i], (float)(i + 1) + 10.0f));
+ for (int i = 0; i < n; ++i)
+ assert(near(c[i], (float)(i + 1) + 10.0f));
// Scale
T s = a * 2.0f;
- for (int i = 0; i < n; ++i) assert(near(s[i], (float)(i + 1) * 2.0f));
+ for (int i = 0; i < n; ++i)
+ assert(near(s[i], (float)(i + 1) * 2.0f));
// Dot Product
// vec3(1,2,3) . vec3(1,2,3) = 1+4+9 = 14
float expected_dot = 0;
- for (int i = 0; i < n; ++i) expected_dot += a[i] * a[i];
+ for (int i = 0; i < n; ++i)
+ expected_dot += a[i] * a[i];
assert(near(T::dot(a, a), expected_dot));
// Norm (Length)
@@ -43,7 +48,8 @@ template <typename T> void test_vector_ops(int n) {
// Lerp
T l = lerp(a, b, 0.3f);
- for (int i = 0; i < n; ++i) assert(near(l[i], .7 * (i + 1) + .3 * 10.0f));
+ for (int i = 0; i < n; ++i)
+ assert(near(l[i], .7 * (i + 1) + .3 * 10.0f));
}
// Specific test for padding alignment in vec3
@@ -127,7 +133,8 @@ void test_spring() {
std::cout << "Testing Spring..." << std::endl;
float p = 0, v = 0;
// Simulate approx 1 sec with 0.5s smooth time
- for (int i = 0; i < 60; ++i) spring::solve(p, v, 10.0f, 0.5f, 0.016f);
+ for (int i = 0; i < 60; ++i)
+ spring::solve(p, v, 10.0f, 0.5f, 0.016f);
assert(p > 8.5f);
// Test vector spring