TEST(Subtraction, Vec3) { hmm_vec3 v3_1 = HMM_Vec3(1.0f, 2.0f, 3.0f); hmm_vec3 v3_2 = HMM_Vec3(4.0f, 5.0f, 6.0f); { hmm_vec3 result = HMM_SubtractVec3(v3_1, v3_2); EXPECT_FLOAT_EQ(result.X, -3.0f); EXPECT_FLOAT_EQ(result.Y, -3.0f); EXPECT_FLOAT_EQ(result.Z, -3.0f); } { hmm_vec3 result = HMM_Subtract(v3_1, v3_2); EXPECT_FLOAT_EQ(result.X, -3.0f); EXPECT_FLOAT_EQ(result.Y, -3.0f); EXPECT_FLOAT_EQ(result.Z, -3.0f); } { hmm_vec3 result = v3_1 - v3_2; EXPECT_FLOAT_EQ(result.X, -3.0f); EXPECT_FLOAT_EQ(result.Y, -3.0f); EXPECT_FLOAT_EQ(result.Z, -3.0f); } v3_1 -= v3_2; EXPECT_FLOAT_EQ(v3_1.X, -3.0f); EXPECT_FLOAT_EQ(v3_1.Y, -3.0f); EXPECT_FLOAT_EQ(v3_1.Z, -3.0f); }

TEST_F(TestEMConverter, TestDPIScale2) { float scale = 2.0f; em_converter.SetDPI(DPI * scale); EXPECT_FLOAT_EQ(em_converter.DPIScale(), 2.0); }

TEST(divf, div3) { tvec3f a = {5.f, -6.f, 9.4f}; tvec3f b = {-3.f, 4.f, 23.5f}; EXPECT_FLOAT_EQ(div(a, 2.f).x, 5.f / 2.f); EXPECT_FLOAT_EQ(div(2.f, a).x, 2.f / 5.f); EXPECT_FLOAT_EQ(div(a, -2.f).y, -6.f / -2.f); EXPECT_FLOAT_EQ(div(-2.f, a).y, -2.f / -6.f); EXPECT_FLOAT_EQ(div(a, -2.f).z, 9.4f / -2.f); EXPECT_FLOAT_EQ(div(-2.f, a).z, -2.f / 9.4f); a = {5.f, -6.f, 9.4f}; b = {-3.f, 4.f, 23.5f}; EXPECT_FLOAT_EQ(div(a, b).x, 5.f / -3.f); EXPECT_FLOAT_EQ(div(b, a).x, -3.f / 5.f); EXPECT_FLOAT_EQ(div(a, b).y, -6.f / 4.f); EXPECT_FLOAT_EQ(div(b, a).y, 4.f / -6.f); EXPECT_FLOAT_EQ(div(a, b).z, 9.4f / 23.5f); EXPECT_FLOAT_EQ(div(b, a).z, 23.5f / 9.4f); }

/** * Test the encoder by reseting it to 0 and reading the value. */ TEST_F(FakeEncoderTest, TestDefaultState) { EXPECT_FLOAT_EQ(0.0f, m_encoder->Get()) << "The encoder did not start at 0."; }

TEST(ShaderLib,testSetUniform) { auto shader = ngl::ShaderLib::instance(); auto *shaderName="TestUniform"; EXPECT_TRUE(shader->loadShader(shaderName,"files/testUniformVertex.glsl","files/testUniformFragment.glsl",ngl::ErrorExit::OFF))<<"shader loaded?"; shader->use(shaderName); { shader->setUniform("testFloat",2.25f); float result; shader->getUniform("testFloat",result); EXPECT_FLOAT_EQ(result,2.25f)<<"Testing setting a single float"; } { shader->setUniform("testVec2",0.5f,2.0f); float resultF1,resultF2; shader->getUniform("testVec2",resultF1,resultF2); EXPECT_FLOAT_EQ(resultF1,0.5f)<<"Test setting two floats x"; EXPECT_FLOAT_EQ(resultF2,2.0f)<<"Test setting two floats y"; ngl::Vec2 resultVec2; shader->getUniform("testVec2",resultVec2); EXPECT_FLOAT_EQ(resultVec2.m_x,0.5f)<<"Test getting from ngl::Vec2 m_x"; EXPECT_FLOAT_EQ(resultVec2.m_y,2.0f)<<"Test getting from ngl::Vec2 m_y";; } { shader->setUniform("testVec3",0.5f,2.0f,-22.2f); ngl::Real resultF1,resultF2,resultF3; shader->getUniform("testVec3",resultF1,resultF2,resultF3); EXPECT_FLOAT_EQ(resultF1,0.5f)<<"test setting 3 floats x"; EXPECT_FLOAT_EQ(resultF2,2.0f)<<"test setting 3 floats x"; EXPECT_FLOAT_EQ(resultF3,-22.2f)<<"test setting 3 floats x"; ngl::Vec3 resultVec3; shader->getUniform("testVec3",resultVec3); EXPECT_FLOAT_EQ(resultVec3.m_x,0.5f)<<"test getting ngl::Vec3 m_x"; EXPECT_FLOAT_EQ(resultVec3.m_y,2.0f)<<"test getting ngl::Vec3 m_y"; EXPECT_FLOAT_EQ(resultVec3.m_z,-22.2f)<<"test getting ngl::Vec3 m_z"; } { shader->setUniform("testVec4",0.5f,2.0f,-22.2f,1230.4f); ngl::Real resultF1,resultF2,resultF3,resultF4; shader->getUniform("testVec4",resultF1,resultF2,resultF3,resultF4); EXPECT_FLOAT_EQ(resultF1,0.5f); EXPECT_FLOAT_EQ(resultF2,2.0f); EXPECT_FLOAT_EQ(resultF3,-22.2f); EXPECT_FLOAT_EQ(resultF4,1230.4f); ngl::Vec4 resultVec4; shader->getUniform("testVec4",resultVec4); EXPECT_FLOAT_EQ(resultVec4.m_x,0.5f); EXPECT_FLOAT_EQ(resultVec4.m_y,2.0f); EXPECT_FLOAT_EQ(resultVec4.m_z,-22.2f); EXPECT_FLOAT_EQ(resultVec4.m_w,1230.4f); } { shader->setUniform("testMat2",ngl::Mat2()); ngl::Mat2 result; shader->getUniform("testMat2",result); EXPECT_TRUE(result==ngl::Mat2()); } { shader->setUniform("testMat3",ngl::Mat3()); ngl::Mat3 result; shader->getUniform("testMat3",result); EXPECT_TRUE(result==ngl::Mat3()); } { shader->setUniform("testMat4",ngl::Mat4()); ngl::Mat4 result; shader->getUniform("testMat4",result); EXPECT_TRUE(result==ngl::Mat4()); } }

TEST(Vector2DTest, angle) { EXPECT_FLOAT_EQ(0.0f, Vector2D(1, 0).angle()); EXPECT_FLOAT_EQ(M_PI * 2 / 8, Vector2D(1, 1).angle()); EXPECT_FLOAT_EQ(M_PI * 2 / 4, Vector2D(0, 1).angle()); }

TEST(mylibrary, radiansToDegs) { float radianConv = GetDegrees(9); EXPECT_FLOAT_EQ(515.662016, radianConv); }

TEST(Multiplication, Vec3Vec3) { hmm_vec3 v3_1 = HMM_Vec3(1.0f, 2.0f, 3.0f); hmm_vec3 v3_2 = HMM_Vec3(4.0f, 5.0f, 6.0f); { hmm_vec3 result = HMM_MultiplyVec3(v3_1, v3_2); EXPECT_FLOAT_EQ(result.X, 4.0f); EXPECT_FLOAT_EQ(result.Y, 10.0f); EXPECT_FLOAT_EQ(result.Z, 18.0f); } { hmm_vec3 result = HMM_Multiply(v3_1, v3_2); EXPECT_FLOAT_EQ(result.X, 4.0f); EXPECT_FLOAT_EQ(result.Y, 10.0f); EXPECT_FLOAT_EQ(result.Z, 18.0f); } { hmm_vec3 result = v3_1 * v3_2; EXPECT_FLOAT_EQ(result.X, 4.0f); EXPECT_FLOAT_EQ(result.Y, 10.0f); EXPECT_FLOAT_EQ(result.Z, 18.0f); } v3_1 *= v3_2; EXPECT_FLOAT_EQ(v3_1.X, 4.0f); EXPECT_FLOAT_EQ(v3_1.Y, 10.0f); EXPECT_FLOAT_EQ(v3_1.Z, 18.0f); }

TEST(Multiplication, Vec3Scalar) { hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f); float s = 3.0f; { hmm_vec3 result = HMM_MultiplyVec3f(v3, s); EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); } { hmm_vec3 result = HMM_Multiply(v3, s); EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); } { hmm_vec3 result = v3 * s; EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); } { hmm_vec3 result = s * v3; EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); } v3 *= s; EXPECT_FLOAT_EQ(v3.X, 3.0f); EXPECT_FLOAT_EQ(v3.Y, 6.0f); EXPECT_FLOAT_EQ(v3.Z, 9.0f); }

TEST(ScalarMath, PowerF) { EXPECT_FLOAT_EQ(HMM_PowerF(2.0f, 0), 1.0f); EXPECT_NEAR(HMM_PowerF(2.0f, 4.1), 17.148376f, 0.0001f); EXPECT_NEAR(HMM_PowerF(2.0f, -2.5), 0.176777f, 0.0001f); }

TEST(ScalarMath, Lerp) { EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.0f, 2.0f), -2.0f); EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.5f, 2.0f), 0.0f); EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 1.0f, 2.0f), 2.0f); }

TEST(Subtraction, Mat4) { hmm_mat4 m4_1 = HMM_Mat4(); // will have 1 - 16 hmm_mat4 m4_2 = HMM_Mat4(); // will have 17 - 32 // Fill the matrices int Counter = 1; for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { m4_1.Elements[Column][Row] = Counter; ++Counter; } } for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { m4_2.Elements[Column][Row] = Counter; ++Counter; } } // Test the results { hmm_mat4 result = HMM_SubtractMat4(m4_1, m4_2); for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { EXPECT_FLOAT_EQ(result.Elements[Column][Row], -16.0f) << "At column " << Column << ", row " << Row; } } } { hmm_mat4 result = HMM_Subtract(m4_1, m4_2); for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { EXPECT_FLOAT_EQ(result.Elements[Column][Row], -16.0f) << "At column " << Column << ", row " << Row; } } } { hmm_mat4 result = m4_1 - m4_2; for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { EXPECT_FLOAT_EQ(result.Elements[Column][Row], -16.0f) << "At column " << Column << ", row " << Row; } } } m4_1 -= m4_2; for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { EXPECT_FLOAT_EQ(m4_1.Elements[Column][Row], -16.0f) << "At column " << Column << ", row " << Row; } } }

TEST(Subtraction, Vec4) { hmm_vec4 v4_1 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f); hmm_vec4 v4_2 = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f); { hmm_vec4 result = HMM_SubtractVec4(v4_1, v4_2); EXPECT_FLOAT_EQ(result.X, -4.0f); EXPECT_FLOAT_EQ(result.Y, -4.0f); EXPECT_FLOAT_EQ(result.Z, -4.0f); EXPECT_FLOAT_EQ(result.W, -4.0f); } { hmm_vec4 result = HMM_Subtract(v4_1, v4_2); EXPECT_FLOAT_EQ(result.X, -4.0f); EXPECT_FLOAT_EQ(result.Y, -4.0f); EXPECT_FLOAT_EQ(result.Z, -4.0f); EXPECT_FLOAT_EQ(result.W, -4.0f); } { hmm_vec4 result = v4_1 - v4_2; EXPECT_FLOAT_EQ(result.X, -4.0f); EXPECT_FLOAT_EQ(result.Y, -4.0f); EXPECT_FLOAT_EQ(result.Z, -4.0f); EXPECT_FLOAT_EQ(result.W, -4.0f); } v4_1 -= v4_2; EXPECT_FLOAT_EQ(v4_1.X, -4.0f); EXPECT_FLOAT_EQ(v4_1.Y, -4.0f); EXPECT_FLOAT_EQ(v4_1.Z, -4.0f); EXPECT_FLOAT_EQ(v4_1.W, -4.0f); }

TEST(ScalarMath, Power) { EXPECT_FLOAT_EQ(HMM_Power(2.0f, 0), 1.0f); EXPECT_FLOAT_EQ(HMM_Power(2.0f, 4), 16.0f); EXPECT_FLOAT_EQ(HMM_Power(2.0f, -2), 0.25f); }

TEST(Vector2DTest, cross) { Vector2D v1(1.0f, 1.0f); Vector2D v2(1.0f, -1.0f); EXPECT_FLOAT_EQ(-2.0f, v1.cross(v2)); }

TEST(ScalarMath, Clamp) { EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, 0.0f, 2.0f), 0.0f); EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, -3.0f, 2.0f), -2.0f); EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, 3.0f, 2.0f), 2.0f); }

TEST(Vector2DTest, dot) { Vector2D v1(1.0f, 1.0f); Vector2D v2(1.0f, -1.0f); EXPECT_FLOAT_EQ(0.0f, v1.dot(v2)); }

TEST(Multiplication, Vec4Vec4) { hmm_vec4 v4_1 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f); hmm_vec4 v4_2 = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f); { hmm_vec4 result = HMM_MultiplyVec4(v4_1, v4_2); EXPECT_FLOAT_EQ(result.X, 5.0f); EXPECT_FLOAT_EQ(result.Y, 12.0f); EXPECT_FLOAT_EQ(result.Z, 21.0f); EXPECT_FLOAT_EQ(result.W, 32.0f); } { hmm_vec4 result = HMM_Multiply(v4_1, v4_2); EXPECT_FLOAT_EQ(result.X, 5.0f); EXPECT_FLOAT_EQ(result.Y, 12.0f); EXPECT_FLOAT_EQ(result.Z, 21.0f); EXPECT_FLOAT_EQ(result.W, 32.0f); } { hmm_vec4 result = v4_1 * v4_2; EXPECT_FLOAT_EQ(result.X, 5.0f); EXPECT_FLOAT_EQ(result.Y, 12.0f); EXPECT_FLOAT_EQ(result.Z, 21.0f); EXPECT_FLOAT_EQ(result.W, 32.0f); } v4_1 *= v4_2; EXPECT_FLOAT_EQ(v4_1.X, 5.0f); EXPECT_FLOAT_EQ(v4_1.Y, 12.0f); EXPECT_FLOAT_EQ(v4_1.Z, 21.0f); EXPECT_FLOAT_EQ(v4_1.W, 32.0f); }

TEST(mylibrary, degreesToRads) { float degreeConv = GetRadians(3); EXPECT_FLOAT_EQ(0.0523598776, degreeConv); }

TEST(Multiplication, Vec4Scalar) { hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f); float s = 3.0f; { hmm_vec4 result = HMM_MultiplyVec4f(v4, s); EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); EXPECT_FLOAT_EQ(result.W, 12.0f); } { hmm_vec4 result = HMM_Multiply(v4, s); EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); EXPECT_FLOAT_EQ(result.W, 12.0f); } { hmm_vec4 result = v4 * s; EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); EXPECT_FLOAT_EQ(result.W, 12.0f); } { hmm_vec4 result = s * v4; EXPECT_FLOAT_EQ(result.X, 3.0f); EXPECT_FLOAT_EQ(result.Y, 6.0f); EXPECT_FLOAT_EQ(result.Z, 9.0f); EXPECT_FLOAT_EQ(result.W, 12.0f); } v4 *= s; EXPECT_FLOAT_EQ(v4.X, 3.0f); EXPECT_FLOAT_EQ(v4.Y, 6.0f); EXPECT_FLOAT_EQ(v4.Z, 9.0f); }

//Mylibrary general tests TEST(mylibrary, lerp) { float lerpTest = Lerp(0, 10, .9); EXPECT_FLOAT_EQ(9.f, lerpTest); }

TEST(Initialization, Vectors) { // // Test vec2 // hmm_vec2 v2 = HMM_Vec2(1.0f, 2.0f); hmm_vec2 v2i = HMM_Vec2(1, 2); EXPECT_FLOAT_EQ(v2.X, 1.0f); EXPECT_FLOAT_EQ(v2.Y, 2.0f); EXPECT_FLOAT_EQ(v2i.X, 1.0f); EXPECT_FLOAT_EQ(v2i.Y, 2.0f); // // Test vec3 // hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f); hmm_vec3 v3i = HMM_Vec3i(1, 2, 3); EXPECT_FLOAT_EQ(v3.X, 1.0f); EXPECT_FLOAT_EQ(v3.Y, 2.0f); EXPECT_FLOAT_EQ(v3.Z, 3.0f); EXPECT_FLOAT_EQ(v3i.X, 1.0f); EXPECT_FLOAT_EQ(v3i.Y, 2.0f); EXPECT_FLOAT_EQ(v3i.Z, 3.0f); // // Test vec4 // hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f); hmm_vec4 v4i = HMM_Vec4i(1, 2, 3, 4); hmm_vec4 v4v = HMM_Vec4v(v3, 4.0f); EXPECT_FLOAT_EQ(v4.X, 1.0f); EXPECT_FLOAT_EQ(v4.Y, 2.0f); EXPECT_FLOAT_EQ(v4.Z, 3.0f); EXPECT_FLOAT_EQ(v4.W, 4.0f); EXPECT_FLOAT_EQ(v4i.X, 1.0f); EXPECT_FLOAT_EQ(v4i.Y, 2.0f); EXPECT_FLOAT_EQ(v4i.Z, 3.0f); EXPECT_FLOAT_EQ(v4i.W, 4.0f); EXPECT_FLOAT_EQ(v4v.X, 1.0f); EXPECT_FLOAT_EQ(v4v.Y, 2.0f); EXPECT_FLOAT_EQ(v4v.Z, 3.0f); EXPECT_FLOAT_EQ(v4v.W, 4.0f); }

/** * Test the encoder by setting the digital outputs and reading the value. */ TEST_F(FakeEncoderTest, TestCountUp) { m_encoder->Reset(); Simulate100QuadratureTicks(); EXPECT_FLOAT_EQ(100.0f, m_encoder->Get()) << "Encoder did not count to 100."; }

TEST(Multiplication, Mat4Mat4) { hmm_mat4 m4_1 = HMM_Mat4(); // will have 1 - 16 hmm_mat4 m4_2 = HMM_Mat4(); // will have 17 - 32 // Fill the matrices int Counter = 1; for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { m4_1.Elements[Column][Row] = Counter; ++Counter; } } for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { m4_2.Elements[Column][Row] = Counter; ++Counter; } } // Test the results { hmm_mat4 result = HMM_MultiplyMat4(m4_1, m4_2); EXPECT_FLOAT_EQ(result.Elements[0][0], 538.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 612.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 686.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 760.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 650.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 740.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 830.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 920.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 762.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 868.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 974.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 1080.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 874.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 996.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 1118.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 1240.0f); } { hmm_mat4 result = HMM_Multiply(m4_1, m4_2); EXPECT_FLOAT_EQ(result.Elements[0][0], 538.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 612.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 686.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 760.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 650.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 740.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 830.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 920.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 762.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 868.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 974.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 1080.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 874.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 996.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 1118.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 1240.0f); } { hmm_mat4 result = m4_1 * m4_2; EXPECT_FLOAT_EQ(result.Elements[0][0], 538.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 612.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 686.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 760.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 650.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 740.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 830.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 920.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 762.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 868.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 974.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 1080.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 874.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 996.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 1118.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 1240.0f); } // At the time I wrote this, I intentionally omitted // the *= operator for matrices because matrix // multiplication is not commutative. (bvisness) }

TEST_F(TestEMConverter, TestDPIScale) { EXPECT_FLOAT_EQ(em_converter.DPIScale(), 1.0); }

TEST(Multiplication, Mat4Scalar) { hmm_mat4 m4 = HMM_Mat4(); // will have 1 - 16 float s = 3; // Fill the matrix int Counter = 1; for (int Column = 0; Column < 4; ++Column) { for (int Row = 0; Row < 4; ++Row) { m4.Elements[Column][Row] = Counter; ++Counter; } } // Test the results { hmm_mat4 result = HMM_MultiplyMat4f(m4, s); EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 12.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 15.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 18.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 24.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 27.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 30.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 33.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 36.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 39.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 42.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 45.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 48.0f); } { hmm_mat4 result = HMM_Multiply(m4, s); EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 12.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 15.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 18.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 24.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 27.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 30.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 33.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 36.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 39.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 42.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 45.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 48.0f); } { hmm_mat4 result = m4 * s; EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 12.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 15.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 18.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 24.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 27.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 30.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 33.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 36.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 39.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 42.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 45.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 48.0f); } { hmm_mat4 result = s * m4; EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f); EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f); EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f); EXPECT_FLOAT_EQ(result.Elements[0][3], 12.0f); EXPECT_FLOAT_EQ(result.Elements[1][0], 15.0f); EXPECT_FLOAT_EQ(result.Elements[1][1], 18.0f); EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f); EXPECT_FLOAT_EQ(result.Elements[1][3], 24.0f); EXPECT_FLOAT_EQ(result.Elements[2][0], 27.0f); EXPECT_FLOAT_EQ(result.Elements[2][1], 30.0f); EXPECT_FLOAT_EQ(result.Elements[2][2], 33.0f); EXPECT_FLOAT_EQ(result.Elements[2][3], 36.0f); EXPECT_FLOAT_EQ(result.Elements[3][0], 39.0f); EXPECT_FLOAT_EQ(result.Elements[3][1], 42.0f); EXPECT_FLOAT_EQ(result.Elements[3][2], 45.0f); EXPECT_FLOAT_EQ(result.Elements[3][3], 48.0f); } m4 *= s; EXPECT_FLOAT_EQ(m4.Elements[0][0], 3.0f); EXPECT_FLOAT_EQ(m4.Elements[0][1], 6.0f); EXPECT_FLOAT_EQ(m4.Elements[0][2], 9.0f); EXPECT_FLOAT_EQ(m4.Elements[0][3], 12.0f); EXPECT_FLOAT_EQ(m4.Elements[1][0], 15.0f); EXPECT_FLOAT_EQ(m4.Elements[1][1], 18.0f); EXPECT_FLOAT_EQ(m4.Elements[1][2], 21.0f); EXPECT_FLOAT_EQ(m4.Elements[1][3], 24.0f); EXPECT_FLOAT_EQ(m4.Elements[2][0], 27.0f); EXPECT_FLOAT_EQ(m4.Elements[2][1], 30.0f); EXPECT_FLOAT_EQ(m4.Elements[2][2], 33.0f); EXPECT_FLOAT_EQ(m4.Elements[2][3], 36.0f); EXPECT_FLOAT_EQ(m4.Elements[3][0], 39.0f); EXPECT_FLOAT_EQ(m4.Elements[3][1], 42.0f); EXPECT_FLOAT_EQ(m4.Elements[3][2], 45.0f); EXPECT_FLOAT_EQ(m4.Elements[3][3], 48.0f); }

TEST_F(TestCalibratorPhase, getWetbulbInvalid) { EXPECT_FLOAT_EQ(Util::MV, CalibratorPhase::getWetbulb(Util::MV, 30000, 1)); EXPECT_FLOAT_EQ(Util::MV, CalibratorPhase::getWetbulb(270, Util::MV, 1)); EXPECT_FLOAT_EQ(Util::MV, CalibratorPhase::getWetbulb(270, 30000, Util::MV)); EXPECT_FLOAT_EQ(Util::MV, CalibratorPhase::getWetbulb(270, 100000, 0)); // No humidity }

// ------------------------------------------------------------------------------------------------ TEST_F(ColladaExportLight, testExportLight) { const char* file = "cameraExp.dae"; const aiScene* pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/lights.dae",0); ASSERT_TRUE(pTest!=NULL); ASSERT_TRUE(pTest->HasLights()); EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file)); EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada","lightsExp.dae")); const aiScene* imported = im->ReadFile(file,0); ASSERT_TRUE(imported!=NULL); EXPECT_TRUE(imported->HasLights()); EXPECT_EQ(pTest->mNumLights,imported->mNumLights); for(size_t i=0; i< pTest->mNumLights;i++){ const aiLight *orig = pTest->mLights[i]; const aiLight *read = imported->mLights[i]; EXPECT_TRUE(orig->mName==read->mName); EXPECT_EQ(orig->mType,read->mType); EXPECT_FLOAT_EQ(orig->mAttenuationConstant,read->mAttenuationConstant); EXPECT_FLOAT_EQ(orig->mAttenuationLinear,read->mAttenuationLinear); EXPECT_FLOAT_EQ(orig->mAttenuationQuadratic,read->mAttenuationQuadratic); EXPECT_FLOAT_EQ(orig->mColorAmbient.r,read->mColorAmbient.r); EXPECT_FLOAT_EQ(orig->mColorAmbient.g,read->mColorAmbient.g); EXPECT_FLOAT_EQ(orig->mColorAmbient.b,read->mColorAmbient.b); EXPECT_FLOAT_EQ(orig->mColorDiffuse.r,read->mColorDiffuse.r); EXPECT_FLOAT_EQ(orig->mColorDiffuse.g,read->mColorDiffuse.g); EXPECT_FLOAT_EQ(orig->mColorDiffuse.b,read->mColorDiffuse.b); EXPECT_FLOAT_EQ(orig->mColorSpecular.r,read->mColorSpecular.r); EXPECT_FLOAT_EQ(orig->mColorSpecular.g,read->mColorSpecular.g); EXPECT_FLOAT_EQ(orig->mColorSpecular.b,read->mColorSpecular.b); EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001); EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001); } }

TEST(Vector4, Sub) { MrukEngine::Vector4 v1(3, 4, 5, 6); MrukEngine::Vector4 v2(3, 4, 5, 6); MrukEngine::Vector4 r1 = -v1; MrukEngine::Vector4 r2 = v1 - v2; v1 -= v2; EXPECT_FLOAT_EQ(-3, r1.x); EXPECT_FLOAT_EQ(-4, r1.y); EXPECT_FLOAT_EQ(-5, r1.z); EXPECT_FLOAT_EQ(-6, r1.w); EXPECT_FLOAT_EQ(0, r2.x); EXPECT_FLOAT_EQ(0, r2.y); EXPECT_FLOAT_EQ(0, r2.z); EXPECT_FLOAT_EQ(0, r2.w); EXPECT_FLOAT_EQ(0, v1.x); EXPECT_FLOAT_EQ(0, v1.y); EXPECT_FLOAT_EQ(0, v1.z); EXPECT_FLOAT_EQ(0, v1.w); }

TEST(ScalarMath, RSquareRootF) { EXPECT_FLOAT_EQ(HMM_RSquareRootF(10.0f), 0.31616211f); }