Mercurial > Math
changeset 21:fbb4ac41da28
Updated tests to run as typed tests over int, float, and double.
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Wed, 17 Sep 2014 23:02:35 -0500 |
parents | b2c15ffdab9d |
children | b3e035767eb0 |
files | test/main.cpp |
diffstat | 1 files changed, 117 insertions(+), 87 deletions(-) [+] |
line diff
1.1 --- a/test/main.cpp Mon Sep 15 01:02:52 2014 -0500 1.2 +++ b/test/main.cpp Wed Sep 17 23:02:35 2014 -0500 1.3 @@ -11,103 +11,133 @@ 1.4 #include "gtest/gtest.h" 1.5 1.6 //////////////////////////////////////////////////////////////////////////////// 1.7 -// Vector2iTest 1.8 +// Vector2 floating point 1.9 1.10 -TEST( Vector2iTest, ConstructFromSingleValue ) { 1.11 - Vector2i v2i_0(0); 1.12 - EXPECT_EQ( 0, v2i_0.x ) << "x component is not 0"; 1.13 - EXPECT_EQ( 0, v2i_0.y ) << "y component is not 0"; 1.14 +typedef ::testing::Types<int, float, double> MyTypes; 1.15 1.16 - Vector2i v2i_1(1); 1.17 - EXPECT_EQ( 1, v2i_1.x ) << "x component is not 1"; 1.18 - EXPECT_EQ( 1, v2i_1.y ) << "y component is not 1"; 1.19 +template <typename T> 1.20 +class VectorTest : public ::testing::Test { 1.21 +public: 1.22 + static T x; 1.23 + static T y; 1.24 + static T z; 1.25 + static T w; 1.26 + 1.27 + virtual void SetUp() { 1.28 + } 1.29 + 1.30 + }; 1.31 + 1.32 +TYPED_TEST_CASE( VectorTest, MyTypes ); 1.33 + 1.34 +TYPED_TEST( VectorTest, ConstructFromSingleValue ) { 1.35 + TypeParam zero = (TypeParam ) 0; 1.36 + TypeParam one = (TypeParam ) 1; 1.37 + 1.38 + Vector2<TypeParam> v2_zero( zero ); 1.39 + EXPECT_FLOAT_EQ( zero, v2_zero.x ) << "x component is not " << zero; 1.40 + EXPECT_FLOAT_EQ( zero, v2_zero.y ) << "y component is not " << zero; 1.41 + 1.42 + Vector2<TypeParam> v2_one( one ); 1.43 + EXPECT_FLOAT_EQ( one, v2_one.x ) << "x component is not " << one; 1.44 + EXPECT_FLOAT_EQ( one, v2_one.y ) << "y component is not " << one; 1.45 + 1.46 + Vector3<TypeParam> v3_zero( zero ); 1.47 + EXPECT_FLOAT_EQ( zero, v3_zero.x ) << "x component is not " << zero; 1.48 + EXPECT_FLOAT_EQ( zero, v3_zero.y ) << "y component is not " << zero; 1.49 + EXPECT_FLOAT_EQ( zero, v3_zero.z ) << "z component is not " << zero; 1.50 + 1.51 + Vector3<TypeParam> v3_one( one ); 1.52 + EXPECT_FLOAT_EQ( one, v3_one.x ) << "x component is not " << one; 1.53 + EXPECT_FLOAT_EQ( one, v3_one.y ) << "y component is not " << one; 1.54 + EXPECT_FLOAT_EQ( one, v3_one.z ) << "z component is not " << one; 1.55 + 1.56 + Vector4<TypeParam> v4_zero( zero ); 1.57 + EXPECT_FLOAT_EQ( zero, v4_zero.x ) << "x component is not " << zero; 1.58 + EXPECT_FLOAT_EQ( zero, v4_zero.y ) << "y component is not " << zero; 1.59 + EXPECT_FLOAT_EQ( zero, v4_zero.z ) << "z component is not " << zero; 1.60 + EXPECT_FLOAT_EQ( zero, v4_zero.w ) << "w component is not " << zero; 1.61 + 1.62 + Vector4<TypeParam> v4_one( one ); 1.63 + EXPECT_FLOAT_EQ( one, v4_one.x ) << "x component is not " << one; 1.64 + EXPECT_FLOAT_EQ( one, v4_one.y ) << "y component is not " << one; 1.65 + EXPECT_FLOAT_EQ( one, v4_one.z ) << "z component is not " << one; 1.66 + EXPECT_FLOAT_EQ( one, v4_one.w ) << "w component is not " << one; 1.67 + 1.68 } 1.69 1.70 -TEST( Vector2iTest, ConstructFromMultipleValue ) { 1.71 - Vector2i v2i(1, 2); 1.72 - EXPECT_EQ( 1, v2i.x ) << "x component is not 1"; 1.73 - EXPECT_EQ( 2, v2i.y ) << "y component is not 2"; 1.74 +TYPED_TEST( VectorTest, ConstructFromMultipleValues ) { 1.75 + TypeParam x = (TypeParam ) 1.1; 1.76 + TypeParam y = (TypeParam ) 2.2; 1.77 + TypeParam z = (TypeParam ) 3.3; 1.78 + TypeParam w = (TypeParam ) 4.4; 1.79 + 1.80 + Vector2<TypeParam> v2( x, y ); 1.81 + EXPECT_FLOAT_EQ( x, v2.x ) << "x component is not " << x; 1.82 + EXPECT_FLOAT_EQ( y, v2.y ) << "y component is not " << y; 1.83 + 1.84 + Vector3<TypeParam> v3( x, y, z ); 1.85 + EXPECT_FLOAT_EQ( x, v3.x ) << "x component is not " << x; 1.86 + EXPECT_FLOAT_EQ( y, v3.y ) << "y component is not " << y; 1.87 + EXPECT_FLOAT_EQ( z, v3.z ) << "z component is not " << z; 1.88 + 1.89 + Vector4<TypeParam> v4( x, y, z, w ); 1.90 + EXPECT_FLOAT_EQ( x, v4.x ) << "x component is not " << x; 1.91 + EXPECT_FLOAT_EQ( y, v4.y ) << "y component is not " << y; 1.92 + EXPECT_FLOAT_EQ( z, v4.z ) << "z component is not " << z; 1.93 + EXPECT_FLOAT_EQ( w, v4.w ) << "w component is not " << w; 1.94 } 1.95 1.96 -TEST( Vector2iTest, ConstructFromVector ) { 1.97 - Vector2i v2i_1(1, 2); 1.98 +TYPED_TEST( VectorTest, ConstructFromVector ) { 1.99 + TypeParam x = (TypeParam ) 1.1; 1.100 + TypeParam y = (TypeParam ) 2.2; 1.101 + TypeParam z = (TypeParam ) 3.3; 1.102 + TypeParam w = (TypeParam ) 4.4; 1.103 1.104 - Vector2i v2i_2(v2i_1); 1.105 - EXPECT_EQ( 1, v2i_2.x ) << "x component is not 1"; 1.106 - EXPECT_EQ( 2, v2i_2.y ) << "y component is not 2"; 1.107 + Vector2<TypeParam> v2_1( x, y ); 1.108 + Vector2<TypeParam> v2_2( v2_1 ); 1.109 + EXPECT_FLOAT_EQ( v2_1.x, v2_2.x ) << "x component is not " << v2_1.x; 1.110 + EXPECT_FLOAT_EQ( v2_1.y, v2_2.y ) << "y component is not " << v2_1.y; 1.111 + 1.112 + Vector3<TypeParam> v3_1( x, y, z ); 1.113 + Vector3<TypeParam> v3_2( v3_1 ); 1.114 + EXPECT_FLOAT_EQ( v3_1.x, v3_2.x ) << "x component is not " << v3_1.x; 1.115 + EXPECT_FLOAT_EQ( v3_1.y, v3_2.y ) << "y component is not " << v3_1.y; 1.116 + EXPECT_FLOAT_EQ( v3_1.z, v3_2.z ) << "z component is not " << v3_1.z; 1.117 + 1.118 + Vector4<TypeParam> v4_2_1( x, y, z, w ); 1.119 + Vector4<TypeParam> v2( v4_2_1 ); 1.120 + EXPECT_FLOAT_EQ( v4_2_1.x, v2.x ) << "x component is not " << v4_2_1.x; 1.121 + EXPECT_FLOAT_EQ( v4_2_1.y, v2.y ) << "y component is not " << v4_2_1.y; 1.122 + EXPECT_FLOAT_EQ( v4_2_1.z, v2.z ) << "z component is not " << v4_2_1.z; 1.123 + EXPECT_FLOAT_EQ( v4_2_1.w, v2.w ) << "w component is not " << v4_2_1.w; 1.124 + 1.125 + } 1.126 + 1.127 +TYPED_TEST( VectorTest, Indexing ) { 1.128 + TypeParam x = (TypeParam ) 1.1; 1.129 + TypeParam y = (TypeParam ) 2.2; 1.130 + TypeParam z = (TypeParam ) 3.3; 1.131 + TypeParam w = (TypeParam ) 4.4; 1.132 + 1.133 + Vector2<TypeParam> v2( x, y); 1.134 + ASSERT_EQ( x, v2.x ) << "x component is not " << x; 1.135 + ASSERT_EQ( y, v2.y ) << "y component is not " << y; 1.136 + 1.137 + Vector3<TypeParam> v3( x, y, z); 1.138 + ASSERT_FLOAT_EQ( x, v3.x ) << "x component is not " << x; 1.139 + ASSERT_FLOAT_EQ( y, v3.y ) << "y component is not " << y; 1.140 + ASSERT_FLOAT_EQ( z, v3.z ) << "z component is not " << z; 1.141 + 1.142 + Vector4<TypeParam> v4( x, y, z, w); 1.143 + ASSERT_FLOAT_EQ( x, v4.x ) << "x component is not " << x; 1.144 + ASSERT_FLOAT_EQ( y, v4.y ) << "y component is not " << y; 1.145 + ASSERT_FLOAT_EQ( z, v4.z ) << "z component is not " << z; 1.146 + ASSERT_FLOAT_EQ( w, v4.w ) << "w component is not " << w; 1.147 + 1.148 } 1.149 1.150 //////////////////////////////////////////////////////////////////////////////// 1.151 -// Vector3fTest 1.152 - 1.153 -TEST( Vector3fTest, ConstructFromSingleValue ) { 1.154 - Vector3f v3f_0(0.0); 1.155 - EXPECT_EQ( 0.0, v3f_0.x ) << "x component is not 0.0"; 1.156 - EXPECT_EQ( 0.0, v3f_0.y ) << "y component is not 0.0"; 1.157 - EXPECT_EQ( 0.0, v3f_0.z ) << "z component is not 0.0"; 1.158 - 1.159 - Vector3f v3f_1(1.0); 1.160 - EXPECT_EQ( 1.0, v3f_1.x ) << "x component is not 1.0"; 1.161 - EXPECT_EQ( 1.0, v3f_1.y ) << "y component is not 1.0"; 1.162 - EXPECT_EQ( 1.0, v3f_1.y ) << "z component is not 1.0"; 1.163 - } 1.164 - 1.165 -TEST( Vector3fTest, ConstructFromMultipleValue ) { 1.166 - Vector3f v3f(1.0, 2.0, 3.0); 1.167 - EXPECT_EQ( 1.0, v3f.x ) << "x component is not 1.0"; 1.168 - EXPECT_EQ( 2.0, v3f.y ) << "y component is not 2.0"; 1.169 - EXPECT_EQ( 3.0, v3f.z ) << "z component is not 3.0"; 1.170 - } 1.171 - 1.172 -TEST( Vector3fTest, ConstructFromVector ) { 1.173 - Vector3f v3f_1 (1.0, 2.0, 3.0); 1.174 - 1.175 - Vector3f v3f (v3f_1); 1.176 - EXPECT_EQ( 1.0, v3f.x ) << "x component is not 1.0"; 1.177 - EXPECT_EQ( 2.0, v3f.y ) << "y component is not 2.0"; 1.178 - EXPECT_EQ( 3.0, v3f.z ) << "z component is not 3.0"; 1.179 - } 1.180 - 1.181 - 1.182 -//////////////////////////////////////////////////////////////////////////////// 1.183 -// Vector4dTest 1.184 - 1.185 -TEST( Vector4dTest, ConstructFromSingleValue ) { 1.186 - Vector4d v4d_0(0.0); 1.187 - EXPECT_EQ( 0.0, v4d_0.x ) << "x component is not 0.0"; 1.188 - EXPECT_EQ( 0.0, v4d_0.y ) << "y component is not 0.0"; 1.189 - EXPECT_EQ( 0.0, v4d_0.z ) << "z component is not 0.0"; 1.190 - EXPECT_EQ( 0.0, v4d_0.w ) << "w component is not 0.0"; 1.191 - 1.192 - Vector4d v4d_1(1.0); 1.193 - EXPECT_EQ( 1.0, v4d_1.x ) << "x component is not 1.0"; 1.194 - EXPECT_EQ( 1.0, v4d_1.y ) << "y component is not 1.0"; 1.195 - EXPECT_EQ( 1.0, v4d_1.z ) << "z component is not 1.0"; 1.196 - EXPECT_EQ( 1.0, v4d_1.w ) << "w component is not 1.0"; 1.197 - } 1.198 - 1.199 -TEST( Vector4dTest, ConstructFromMultipleValue ) { 1.200 - Vector4d v4d_1(1.0, 2.0, 3.0, 4.0); 1.201 - 1.202 - Vector4d v4d (v4d_1); 1.203 - EXPECT_EQ( 1.0, v4d.x ) << "x component is not 1.0"; 1.204 - EXPECT_EQ( 2.0, v4d.y ) << "y component is not 2.0"; 1.205 - EXPECT_EQ( 3.0, v4d.z ) << "z component is not 3.0"; 1.206 - EXPECT_EQ( 4.0, v4d.w ) << "w component is not 4.0"; 1.207 - } 1.208 - 1.209 -TEST( Vector4dTest, ConstructFromVector ) { 1.210 - Vector4d v4d_1 (1.0, 2.0, 3.0, 4.0); 1.211 - 1.212 - Vector4d v4d (v4d_1); 1.213 - EXPECT_EQ( 1.0, v4d.x ) << "x component is not 1.0"; 1.214 - EXPECT_EQ( 2.0, v4d.y ) << "y component is not 2.0"; 1.215 - EXPECT_EQ( 3.0, v4d.z ) << "z component is not 3.0"; 1.216 - EXPECT_EQ( 4.0, v4d.w ) << "w component is not 4.0"; 1.217 - } 1.218 - 1.219 - 1.220 - 1.221 1.222 int main(int argc, char **argv) { 1.223 ::testing::InitGoogleTest(&argc, argv);