Changeset 648 for trunk/test
- Timestamp:
- Feb 14, 2011, 2:26:40 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/matrix.cpp
r642 r648 23 23 { 24 24 CPPUNIT_TEST_SUITE(MatrixTest); 25 CPPUNIT_TEST(test_mat_det); 25 26 CPPUNIT_TEST(test_mat_mul); 27 CPPUNIT_TEST(test_mat_inv); 26 28 CPPUNIT_TEST_SUITE_END(); 27 29 … … 29 31 MatrixTest() : CppUnit::TestCase("Matrix Test") {} 30 32 31 void setUp() {} 33 void setUp() 34 { 35 identity = float4x4::identity(); 36 triangular = float4x4(float4(1.0f, 0.0f, 0.0f, 0.0f), 37 float4(7.0f, 2.0f, 0.0f, 0.0f), 38 float4(1.0f, 5.0f, 3.0f, 0.0f), 39 float4(8.0f, 9.0f, 2.0f, 4.0f)); 40 invertible = float4x4(float4( 1.0f, 1.0f, 2.0f, -1.0f), 41 float4(-2.0f, -1.0f, -2.0f, 2.0f), 42 float4( 4.0f, 2.0f, 5.0f, -4.0f), 43 float4( 5.0f, -3.0f, -7.0f, -6.0f)); 44 } 32 45 33 46 void tearDown() {} 34 47 48 void test_mat_det() 49 { 50 float d1 = triangular.det(); 51 CPPUNIT_ASSERT(d1 == 24.0f); 52 float d2 = invertible.det(); 53 CPPUNIT_ASSERT(d2 == -1.0f); 54 } 55 35 56 void test_mat_mul() 36 57 { 37 float4 v0(1.0f, 0.0f, 0.0f, 0.0f); 38 float4 v1(0.0f, 1.0f, 0.0f, 0.0f); 39 float4 v2(0.0f, 0.0f, 1.0f, 0.0f); 40 float4 v3(0.0f, 0.0f, 0.0f, 1.0f); 41 float4x4 m0(v0, v1, v2, v3); 42 float4x4 m1(v0, v1, v2, v3); 58 float4x4 m0 = identity; 59 float4x4 m1 = identity; 43 60 float4x4 m2 = m0 * m1; 44 61 45 62 CPPUNIT_ASSERT(m2[0][0] == 1.0f); 63 CPPUNIT_ASSERT(m2[1][0] == 0.0f); 64 CPPUNIT_ASSERT(m2[2][0] == 0.0f); 65 CPPUNIT_ASSERT(m2[3][0] == 0.0f); 66 67 CPPUNIT_ASSERT(m2[0][1] == 0.0f); 46 68 CPPUNIT_ASSERT(m2[1][1] == 1.0f); 69 CPPUNIT_ASSERT(m2[2][1] == 0.0f); 70 CPPUNIT_ASSERT(m2[3][1] == 0.0f); 71 72 CPPUNIT_ASSERT(m2[0][2] == 0.0f); 73 CPPUNIT_ASSERT(m2[1][2] == 0.0f); 47 74 CPPUNIT_ASSERT(m2[2][2] == 1.0f); 75 CPPUNIT_ASSERT(m2[3][2] == 0.0f); 76 77 CPPUNIT_ASSERT(m2[0][3] == 0.0f); 78 CPPUNIT_ASSERT(m2[1][3] == 0.0f); 79 CPPUNIT_ASSERT(m2[2][3] == 0.0f); 48 80 CPPUNIT_ASSERT(m2[3][3] == 1.0f); 49 81 } 82 83 void test_mat_inv() 84 { 85 float4x4 m0 = invertible; 86 float4x4 m1 = m0.invert(); 87 88 float4x4 m2 = m0 * m1; 89 90 CPPUNIT_ASSERT(m2[0][0] == 1.0f); 91 CPPUNIT_ASSERT(m2[1][0] == 0.0f); 92 CPPUNIT_ASSERT(m2[2][0] == 0.0f); 93 CPPUNIT_ASSERT(m2[3][0] == 0.0f); 94 95 CPPUNIT_ASSERT(m2[0][1] == 0.0f); 96 CPPUNIT_ASSERT(m2[1][1] == 1.0f); 97 CPPUNIT_ASSERT(m2[2][1] == 0.0f); 98 CPPUNIT_ASSERT(m2[3][1] == 0.0f); 99 100 CPPUNIT_ASSERT(m2[0][2] == 0.0f); 101 CPPUNIT_ASSERT(m2[1][2] == 0.0f); 102 CPPUNIT_ASSERT(m2[2][2] == 1.0f); 103 CPPUNIT_ASSERT(m2[3][2] == 0.0f); 104 105 CPPUNIT_ASSERT(m2[0][3] == 0.0f); 106 CPPUNIT_ASSERT(m2[1][3] == 0.0f); 107 CPPUNIT_ASSERT(m2[2][3] == 0.0f); 108 CPPUNIT_ASSERT(m2[3][3] == 1.0f); 109 } 110 111 private: 112 float4x4 triangular, identity, invertible; 50 113 }; 51 114
Note: See TracChangeset
for help on using the changeset viewer.