Fix unit tests

This commit is contained in:
Pascal Serrarens 2024-08-02 11:27:16 +02:00
parent b81b77b1c9
commit a4b0491c2f
3 changed files with 18 additions and 12 deletions

View File

@ -25,6 +25,8 @@ else()
add_library(LinearAlgebra STATIC
"FloatSingle.cpp"
"Angle.cpp"
"Angle8.cpp"
"Angle16.cpp"
"Vector2.cpp"
"Vector3.cpp"
"Quaternion.cpp"

View File

@ -150,8 +150,12 @@ struct Vector2 : Vec2 {
/// @param f The scaling factor
/// @return The scaled vector
/// @remark Each componet of the vector will be divided by the same factor.
friend Vector2 operator/(const Vector2& v, float f);
friend Vector2 operator/(float f, const Vector2& v);
friend Vector2 operator/(const Vector2& v, float f) {
return Vector2(v.x / f, v.y / f);
}
friend Vector2 operator/(float f, const Vector2& v) {
return Vector2(f / v.x, f / v.y);
}
Vector2 operator/=(float f);
/// @brief The dot product of two vectors

View File

@ -1,8 +1,8 @@
#if GTEST
#include <gtest/gtest.h>
#include <limits>
#include <math.h>
#include <limits>
#include "Angle16.h"
#include "Angle8.h"
@ -12,12 +12,12 @@
TEST(Angle8, Construct) {
float angle = 0.0F;
Angle8 a = Angle8(angle);
float f = a.ToFloat();
float f = (float)a;
EXPECT_FLOAT_EQ(f, angle);
angle = -180.0F;
a = Angle8(angle);
f = a.ToFloat();
f = (float)a;
EXPECT_FLOAT_EQ(f, angle);
}
@ -25,26 +25,26 @@ TEST(Angle8, Negate) {
float angle = 0;
Angle8 a = Angle8(angle);
a = -a;
float f = a.ToFloat();
float f = (float)a;
EXPECT_FLOAT_EQ(f, angle);
angle = 90.0F;
a = Angle8(angle);
a = -a;
f = a.ToFloat();
f = (float)a;
EXPECT_FLOAT_EQ(f, -angle);
}
TEST(Angle8, Add) {
Angle8 a = Angle8(0.0F);
Angle8 a = Angle8::Degrees(0.0F);
Angle8 b = Angle8(0.0F);
Angle8 r = a + b;
EXPECT_FLOAT_EQ(r.ToFloat(), 0);
EXPECT_FLOAT_EQ((float)r, 0);
}
TEST(Angle16, Construct) {
Angle16 a = Angle16(0.0F);
float f = a.ToFloat();
float f = (float)a;
EXPECT_FLOAT_EQ(f, 0);
}
@ -52,13 +52,13 @@ TEST(Angle16, Negate) {
float angle = 0;
Angle16 a = Angle16(angle);
a = -a;
float f = a.ToFloat();
float f = (float)a;
EXPECT_FLOAT_EQ(f, angle);
angle = 90.0F;
a = Angle16(angle);
a = -a;
f = a.ToFloat();
f = (float)a;
EXPECT_FLOAT_EQ(f, -angle);
}
#endif