Vectors.ut.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <gtest/gtest.h>
  2. #include <iostream>
  3. #include "Math.h"
  4. #include "MathCommon.ut.h"
  5. const float REALY_SMALL_FLOAT = 1.0e-3;
  6. //============================================================================== ==//==============================================================================ECT_EQ(sizeof(Vec2), FS * 2);
  7. EXPECT_EQ(sizeof(Vec3), FS * 3);
  8. EXPECT_EQ(sizeof(Vec4), FS * 4);
  9. EXPECT_EQ(sizeof(Quat), FS * 4);
  10. EXPECT_EQ(sizeof(Euler), FS * 3);
  11. EXPECT_EQ(sizeof(Mat3), FS * 9);
  12. EXPECT_EQ(sizeof(Mat4), FS * 16);
  13. }
  14. TEST(MathTests, VectorConstructors)
  15. {
  16. testCommonContructors<Vec2>();
  17. testCommonContructors<Vec3>();
  18. testCommonContructors<Vec4>();
  19. }
  20. //==============================================================================//===============================================================================
  21. //==============================================================================
  22. template<typename Type>
  23. void arithmeti//==============================================================================-, &Type::operator-=, &subf>();
  24. testOperators<Type, &Type::operator*, &Type::operator*=, &mulf>();
  25. testOperators<Type, &Type::operator/, &Type::operator/=, &divf>();
  26. testOperatorsWithFloat<Type, &Type::operator+, &Type::operator+=, &operator+, &addf>();
  27. testOperatorsWithFloat<Type, &Type::operator-, &Type::operator-=, &operator-, &subf>();
  28. testOperatorsWithFloat<Type, &Type::operator*, &Type::operator*=, &operator*, &mulf>();
  29. testOperatorsWithFloat<Type, &Type::operator/, &Type::operator/=, &operator/, &divf>();
  30. testCmpOperators<Type>();
  31. }
  32. TEST(MathTests, VectorArithmetic)
  33. {
  34. arithmeticOperations<Vec2>();
  35. arithmeticOperations<Vec3>();
  36. arithmeticOperations<Vec4>();
  37. }
  38. //==============================================================================
  39. // Misc //================================================================================
  40. template<typename Type>
  41. void testDotProd()
  42. {
  43. Type a, b;
  44. float o = 0.0;
  45. for(uint i = 0; i < (sizeof(Type) / sizeof(//==============================================================================N);
  46. }
  47. TEST(MathTests, DotProducts)
  48. {
  49. testDotProd<Vec2>();
  50. testDotProd<Vec3>();
  51. testDotProd<Vec4>();
  52. }
  53. template<typename Type>
  54. void testLengthAndNormalize()
  55. {
  56. Type a;
  57. float o = 0.0;
  58. for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
  59. {
  60. a[i] = randFloat();
  61. o += a[i] * a[i];
  62. }
  63. o = sqrt(o);
  64. EXPECT_NEAR(a.getLength(), o, REALY_SMALL_FLOAT);
  65. EXPECT_NEAR(a.getNormalized().getLength(), 1.0, REALY_SMALL_FLOAT);
  66. //EXPECT_EQ(a.getNormalized() * a.getLength(), a);
  67. }
  68. TEST(MathTests, LengthsAndNormals)
  69. {
  70. testLengthAndNormalize<Vec2>();
  71. testLengthAndNormalize<Vec3>();
  72. testLengthAndNormalize<Vec4>();
  73. }