Changeset 1318 for trunk/test/unit/quat.cpp
 Timestamp:
 Apr 30, 2012, 3:40:54 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/unit/quat.cpp
r1305 r1318 27 27 LOLUNIT_TEST(Equality) 28 28 { 29 quat a4(1. 0f, 2.0f, 3.0f, 4.0f);30 quat b4(0. 0f, 2.0f, 3.0f, 4.0f);31 quat c4(1. 0f, 0.0f, 3.0f, 4.0f);32 quat d4(1. 0f, 2.0f, 0.0f, 4.0f);33 quat e4(1. 0f, 2.0f, 3.0f, 0.0f);29 quat a4(1.f, 2.f, 3.f, 4.f); 30 quat b4(0.f, 2.f, 3.f, 4.f); 31 quat c4(1.f, 0.f, 3.f, 4.f); 32 quat d4(1.f, 2.f, 0.f, 4.f); 33 quat e4(1.f, 2.f, 3.f, 0.f); 34 34 35 35 LOLUNIT_ASSERT_EQUAL(a4, a4); … … 48 48 LOLUNIT_TEST(UnaryMinus) 49 49 { 50 quat a(1. 0f, 3.0f, 2.0f, 4.0f);51 quat b(1. 0f, 3.0f, 2.0f, 4.0f);50 quat a(1.f, 3.f, 2.f, 4.f); 51 quat b(1.f, 3.f, 2.f, 4.f); 52 52 53 53 LOLUNIT_ASSERT_EQUAL(a, b); … … 57 57 LOLUNIT_TEST(Conjugate) 58 58 { 59 quat a(1. 0f, 3.0f, 2.0f, 4.0f);60 quat b(1. 0f, 3.0f, 2.0f, 4.0f);59 quat a(1.f, 3.f, 2.f, 4.f); 60 quat b(1.f, 3.f, 2.f, 4.f); 61 61 62 62 LOLUNIT_ASSERT_EQUAL(a, ~b); … … 66 66 LOLUNIT_TEST(Norm) 67 67 { 68 quat a(2. 0f, 2.0f, 8.0f, 3.0f);68 quat a(2.f, 2.f, 8.f, 3.f); 69 69 70 LOLUNIT_ASSERT_EQUAL(norm(a), 81. 0f);70 LOLUNIT_ASSERT_EQUAL(norm(a), 81.f); 71 71 72 72 quat b = a * ~a; 73 quat c(norm(a), 0. 0f, 0.0f, 0.0f);73 quat c(norm(a), 0.f, 0.f, 0.f); 74 74 75 75 LOLUNIT_ASSERT_EQUAL(b, c); 76 76 77 quat d(2. 0f, 3.0f, 4.0f, 1.0f);77 quat d(2.f, 3.f, 4.f, 1.f); 78 78 79 79 LOLUNIT_ASSERT_EQUAL(norm(a * d), norm(a) * norm(d)); … … 82 82 LOLUNIT_TEST(Base) 83 83 { 84 quat i(0.0f, 1.0f, 0.0f, 0.0f);85 quat j(0.0f, 0.0f, 1.0f, 0.0f);86 quat k(0.0f, 0.0f, 0.0f, 1.0f);87 quat one(1.0f, 0.0f, 0.0f, 0.0f);84 quat one(1.f, 0.f, 0.f, 0.f); 85 quat i(0.f, 1.f, 0.f, 0.f); 86 quat j(0.f, 0.f, 1.f, 0.f); 87 quat k(0.f, 0.f, 0.f, 1.f); 88 88 89 LOLUNIT_ASSERT_EQUAL(norm( i), 1.0f);90 LOLUNIT_ASSERT_EQUAL(norm( j), 1.0f);91 LOLUNIT_ASSERT_EQUAL(norm( k), 1.0f);92 LOLUNIT_ASSERT_EQUAL(norm( one), 1.0f);89 LOLUNIT_ASSERT_EQUAL(norm(one), 1.f); 90 LOLUNIT_ASSERT_EQUAL(norm(i), 1.f); 91 LOLUNIT_ASSERT_EQUAL(norm(j), 1.f); 92 LOLUNIT_ASSERT_EQUAL(norm(k), 1.f); 93 93 94 94 LOLUNIT_ASSERT_EQUAL(i * i, one); … … 107 107 LOLUNIT_TEST(Normalize) 108 108 { 109 quat a(2. 0f, 2.0f, 8.0f, 3.0f);109 quat a(2.f, 2.f, 8.f, 3.f); 110 110 quat b = normalize(a); 111 111 112 LOLUNIT_ASSERT_DOUBLES_EQUAL(norm(b), 1.0, 1e 8);112 LOLUNIT_ASSERT_DOUBLES_EQUAL(norm(b), 1.0, 1e5); 113 113 } 114 114 115 115 LOLUNIT_TEST(Reciprocal) 116 116 { 117 quat a(2. 0f, 2.0f, 8.0f, 3.0f);117 quat a(2.f, 2.f, 8.f, 3.f); 118 118 quat b = re(a); 119 119 120 120 quat m1 = a * b; 121 121 quat m2 = b * a; 122 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. x, m2.x, 1e8);123 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. y, m2.y, 1e8);124 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. z, m2.z, 1e8);125 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. w, m2.w, 1e8);122 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, m2.w, 1e5); 123 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.x, m2.x, 1e5); 124 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.y, m2.y, 1e5); 125 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.z, m2.z, 1e5); 126 126 127 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. x, 0.0, 1e8);128 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. y, 0.0, 1e8);129 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. z, 0.0, 1e8);130 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1. w, 1.0, 1e8);127 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, 1.0, 1e5); 128 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.x, 0.0, 1e5); 129 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.y, 0.0, 1e5); 130 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.z, 0.0, 1e5); 131 131 } 132 132 133 133 LOLUNIT_TEST(Rotation) 134 134 { 135 quat a = quat::rotate(10.0f, vec3(1, 0, 0)); 136 quat b = quat::rotate(20.0f, vec3(1, 0, 0)); 135 /* Check that rotating 10 degrees twice means rotating 20 degrees */ 136 quat a = quat::rotate(10.f, vec3(1, 0, 0)); 137 quat b = quat::rotate(20.f, vec3(1, 0, 0)); 137 138 quat c = a * a; 138 139 139 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.w, a.w, 1e8); 140 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.x, a.x, 1e8); 141 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.y, a.y, 1e8); 142 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.z, a.z, 1e8); 140 LOLUNIT_ASSERT_DOUBLES_EQUAL(c.w, b.w, 1e5); 141 LOLUNIT_ASSERT_DOUBLES_EQUAL(c.x, b.x, 1e5); 142 LOLUNIT_ASSERT_DOUBLES_EQUAL(c.y, b.y, 1e5); 143 LOLUNIT_ASSERT_DOUBLES_EQUAL(c.z, b.z, 1e5); 144 145 /* Check that rotating 10 degrees then 20 is the same as 20 then 10 */ 146 quat d = a * b; 147 quat e = b * a; 148 149 LOLUNIT_ASSERT_DOUBLES_EQUAL(e.w, d.w, 1e5); 150 LOLUNIT_ASSERT_DOUBLES_EQUAL(e.x, d.x, 1e5); 151 LOLUNIT_ASSERT_DOUBLES_EQUAL(e.y, d.y, 1e5); 152 LOLUNIT_ASSERT_DOUBLES_EQUAL(e.z, d.z, 1e5); 143 153 } 144 154 };
Note: See TracChangeset
for help on using the changeset viewer.