Unittest Construction TODO: Split up these Unittests
vec3 vecClear; assert( !vecClear.ok ); vecClear.clear( 1.0f ); assert( vecClear.ok ); assert( vecClear.data == [ 1.0f, 1.0f, 1.0f ] ); assert( vecClear.data == vec3( 1.0f ).data ); vecClear.clear( float.infinity ); assert( !vecClear.ok ); vecClear.clear( float.nan ); assert( !vecClear.ok ); vecClear.clear( 1.0f ); assert( vecClear.ok ); vec4 b = vec4( 1.0f, vecClear ); assert( b.ok ); assert( b.data == [ 1.0f, 1.0f, 1.0f, 1.0f ] ); assert( b.data == vec4( 1.0f ).data ); vec2 v2_1 = vec2( vec2( 0.0f, 1.0f )); assert( v2_1.data == [ 0.0f, 1.0f ] ); vec2 v2_2 = vec2( 1.0f, 1.0f ); assert( v2_2.data == [ 1.0f, 1.0f ] ); vec3 v3 = vec3( v2_1, 2.0f ); assert( v3.data == [ 0.0f, 1.0f, 2.0f ] ); vec4 v4_1 = vec4( 1.0f, vec2( 2.0f, 3.0f ), 4.0f ); assert( v4_1.data == [ 1.0f, 2.0f, 3.0f, 4.0f ] ); assert( vec3( v4_1 ).data == [ 1.0f, 2.0f, 3.0f ] ); assert( vec2( vec3( v4_1 )).data == [ 1.0f, 2.0f ] ); assert( vec2( vec3( v4_1 )).data == vec2( v4_1 ).data ); assert( v4_1.data == vec4( [ 1.0f, 2.0f, 3.0f, 4.0f ] ).data ); vec4 v4_2 = vec4( vec2( 1.0f, 2.0f ), vec2( 3.0f, 4.0f )); assert( v4_2.data == [ 1.0f, 2.0f, 3.0f, 4.0f ] ); assert( vec3( v4_2 ).data == [ 1.0f, 2.0f, 3.0f ] ); assert( vec2( vec3( v4_2 )).data == [ 1.0f, 2.0f ] ); assert( vec2( vec3( v4_2 )).data == vec2( v4_2 ).data ); assert( v4_2.data == vec4([ 1.0f, 2.0f, 3.0f, 4.0f ] ).data ); float[2] f2 = [ 1.0f, 2.0f ]; float[3] f3 = [ 1.0f, 2.0f, 3.0f ]; float[4] f4 = [ 1.0f, 2.0f, 3.0f, 4.0f ]; assert( vec2( 1.0f, 2.0f ).data == vec2(f2).data); assert( vec3( 1.0f, 2.0f, 3.0f ).data == vec3( f3 ).data ); assert( vec3( 1.0f, 2.0f, 3.0f ).data == vec3( f2, 3.0f ).data ); assert( vec4( 1.0f, 2.0f, 3.0f, 4.0f ).data == vec4( f4 ).data ); assert( vec4( 1.0f, 2.0f, 3.0f, 4.0f ).data == vec4( f3, 4.0f ).data ); assert( vec4( 1.0f, 2.0f, 3.0f, 4.0f ).data == vec4( f2, 3.0f, 4.0f ).data ); // useful for: "vec4 v4 = […]" or "vec4 v4 = other_vector.rgba" assert( vec3( vec3i( 1, 2, 3 )) == vec3( 1.0, 2.0, 3.0 )); assert( vec3d( vec3( 1.0, 2.0, 3.0 )) == vec3d( 1.0, 2.0, 3.0 ));
Unittest for setting Values
vec2 v2 = vec2( 1.0f, 2.0f ); assert( v2.x == 1.0f ); assert( v2.y == 2.0f ); v2.x = 3.0f; assert( v2.data == [ 3.0f, 2.0f ] ); v2.y = 4.0f; assert( v2.data == [ 3.0f, 4.0f ] ); assert(( v2.x == 3.0f ) && ( v2.x == v2.r ) && ( v2.x == v2.s )); assert( v2.y == 4.0f ); assert(( v2.y == 4.0f ) && ( v2.y == v2.g ) && ( v2.y == v2.t )); v2 = [ 0.0f, 1.0f ]; assert( v2.data == [ 0.0f, 1.0f ] ); //v2.update( vec2( 3.0f, 4.0f )); //assert( v2.data == [ 3.0f, 4.0f ] ); vec3 v3 = vec3( 1.0f, 2.0f, 3.0f ); assert( v3.x == 1.0f ); assert( v3.y == 2.0f ); assert( v3.z == 3.0f ); v3.x = 3.0f; assert( v3.data == [ 3.0f, 2.0f, 3.0f ] ); v3.y = 4.0f; assert( v3.data == [ 3.0f, 4.0f, 3.0f ] ); v3.z = 5.0f; assert( v3.data == [ 3.0f, 4.0f, 5.0f ] ); assert(( v3.x == 3.0f ) && ( v3.x == v3.r ) && ( v3.x == v3.s )); assert(( v3.y == 4.0f ) && ( v3.y == v3.g ) && ( v3.y == v3.t )); assert(( v3.z == 5.0f ) && ( v3.z == v3.b ) && ( v3.z == v3.p )); v3 = [ 0.0f, 1.0f, 2.0f ]; assert( v3.data == [ 0.0f, 1.0f, 2.0f ] ); //v3.update( vec3( 3.0f, 4.0f, 5.0f )); //assert( v3.data == [ 3.0f, 4.0f, 5.0f ] ); vec4 v4 = vec4( 1.0f, 2.0f, vec2( 3.0f, 4.0f )); assert( v4.x == 1.0f ); assert( v4.y == 2.0f ); assert( v4.z == 3.0f ); assert( v4.w == 4.0f ); v4.x = 3.0f; assert( v4.data == [ 3.0f, 2.0f, 3.0f, 4.0f ] ); v4.y = 4.0f; assert( v4.data == [ 3.0f, 4.0f, 3.0f, 4.0f ] ); v4.z = 5.0f; assert( v4.data == [ 3.0f, 4.0f, 5.0f, 4.0f ] ); v4.w = 6.0f; assert( v4.data == [ 3.0f, 4.0f, 5.0f, 6.0f ] ); assert(( v4.x == 3.0f ) && ( v4.x == v4.r ) && ( v4.x == v4.s )); assert(( v4.y == 4.0f ) && ( v4.y == v4.g ) && ( v4.y == v4.t )); assert(( v4.z == 5.0f ) && ( v4.z == v4.b ) && ( v4.z == v4.p )); assert(( v4.w == 6.0f ) && ( v4.w == v4.a ) && ( v4.w == v4.q )); v4 = [ 0.0f, 1.0f, 2.0f, 3.0f ]; assert( v4.data == [ 0.0f, 1.0f, 2.0f, 3.0f ] ); //v4.update( vec4( 3.0/, 4.0f, 5.0f, 6.0f )); //assert( v4.data == [ 3.0f, 4.0f, 5.0f, 6.0f ] );
TODO : patch unittest according to access sets !!!
vec2 v2 = vec2( 1.0f, 2.0f ); assert( v2.ts == [ 2.0f, 1.0f ] ); assert( vec3( 1.0f, 2.0f, 3.0f ).xyz == [ 1.0f, 2.0f, 3.0f ] ); assert( vec4( v2, 3.0f, 4.0f ).xyzw == [ 1.0f, 2.0f, 3.0f, 4.0f ] ); assert( vec4( v2, 3.0f, 4.0f ).wxyz == [ 4.0f, 1.0f, 2.0f, 3.0f ] ); assert( vec4( 1.0f, v2.yx, 2.0f ).data == [ 1.0f, 2.0f, 1.0f, 2.0f ] );
Sets all values of the vector to value