#include #include #include "Math.h" #include "MathCommon.ut.h" const float REALY_SMALL_FLOAT = 1.0e-3; //====================================================================================================================== // Alignment = //====================================================================================================================== TEST(MathTests, Alignment) { const int FS = sizeof(float); // float size EXPECT_EQ(sizeof(Vec2), FS * 2); EXPECT_EQ(sizeof(Vec3), FS * 3); EXPECT_EQ(sizeof(Vec4), FS * 4); EXPECT_EQ(sizeof(Quat), FS * 4); EXPECT_EQ(sizeof(Euler), FS * 3); EXPECT_EQ(sizeof(Mat3), FS * 9); EXPECT_EQ(sizeof(Mat4), FS * 16); } TEST(MathTests, VectorConstructors) { testCommonContructors(); testCommonContructors(); testCommonContructors(); } //====================================================================================================================== // Operators = //====================================================================================================================== template void arithmeticOperations() { testOperators(); testOperators(); testOperators(); testOperators(); testOperatorsWithFloat(); testOperatorsWithFloat(); testOperatorsWithFloat(); testOperatorsWithFloat(); testCmpOperators(); } TEST(MathTests, VectorArithmetic) { arithmeticOperations(); arithmeticOperations(); arithmeticOperations(); } //====================================================================================================================== // Misc = //====================================================================================================================== template void testDotProd() { Type a, b; float o = 0.0; for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++) { a[i] = randFloat(); b[i] = randFloat(); o += a[i] * b[i]; } EXPECT_NEAR(a.dot(b), o, M::EPSILON); } TEST(MathTests, DotProducts) { testDotProd(); testDotProd(); testDotProd(); } template void testLengthAndNormalize() { Type a; float o = 0.0; for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++) { a[i] = randFloat(); o += a[i] * a[i]; } o = sqrt(o); EXPECT_NEAR(a.getLength(), o, REALY_SMALL_FLOAT); EXPECT_NEAR(a.getNormalized().getLength(), 1.0, REALY_SMALL_FLOAT); //EXPECT_EQ(a.getNormalized() * a.getLength(), a); } TEST(MathTests, LengthsAndNormals) { testLengthAndNormalize(); testLengthAndNormalize(); testLengthAndNormalize(); }