Permalink
Browse files

Moved unittest code into Qt

  • Loading branch information...
1 parent 11aa42d commit 001ddfc046ec0df9db51e6585ec4d53c009577f9 @bheads committed Nov 1, 2011
View
@@ -1,20 +0,0 @@
-CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )
-
-# rtrt build
- ADD_SUBDIRECTORY( src )
-# rtrt testing
- ADD_SUBDIRECTORY( src/test )
-
-# Document Build System
- find_package(Doxygen)
-
- if(DOXYGEN_FOUND)
- configure_file( Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
- add_custom_target(doc
- ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with Doxygen" VERBATIM
- )
- endif(DOXYGEN_FOUND)
-
-
View
@@ -1,3 +0,0 @@
-*
-!.gitignore
-
@@ -542,7 +542,7 @@ vec4 & operator/=( vec4 &lhs, float rhs )
*/
float dot( const vec4 &a, const vec4 &b )
{
- register float ret = 0.0f; // Used to store the return value.
+ float ret = 0.0f; // Used to store the return value.
asm( "movaps %1, %%xmm0 \n\t" //vec4 is aligned, load the two vectors
"movaps %2, %%xmm1 \n\t"
"mulps %%xmm1, %%xmm0 \n\t" //x*x, y*y, z*z, w*w
View
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by Qt Creator 2.3.1, 2011-10-30T15:24:55. -->
+<!-- Written by Qt Creator 2.3.1, 2011-11-01T07:17:06. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
View
@@ -0,0 +1,10 @@
+
+#include <UnitTest++/UnitTest++.h>
+
+
+
+int main( int argc, char **argv )
+{
+ return UnitTest::RunAllTests();
+}
+
View
@@ -0,0 +1,20 @@
+QT -= core gui
+
+QMAKE_CXXFLAGS += -sse -sse2 -fopenmp
+
+INCLUDEPATH += ../rtrt
+
+LIBS += -lunittest++
+
+SOURCES += \
+ test_math_vec4.cpp \
+ test_math_vec_func.cpp \
+ main.cpp \
+ ../rtrt/modules/vec_func.cpp
+
+HEADERS += \
+ ../rtrt/modules/vec4.h \
+ ../rtrt/modules/vec_func.h
+
+
+

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,70 @@
+
+
+#include <UnitTest++/UnitTest++.h>
+
+#include <modules/vec4.h>
+#include <modules/vec_func.h>
+
+SUITE( Vec4Tests )
+{
+ TEST( Construction )
+ {
+ vec4 a;
+ CHECK_EQUAL( a.x, 0 );
+ CHECK_EQUAL( a.y, 0 );
+ CHECK_EQUAL( a.z, 0 );
+ CHECK_EQUAL( a.w, 0 );
+
+ vec4 b( 1, 2, 3, 4 );
+ CHECK_EQUAL( b.x, 1 );
+ CHECK_EQUAL( b.y, 2 );
+ CHECK_EQUAL( b.z, 3 );
+ CHECK_EQUAL( b.w, 4 );
+
+ float data[4] = { 8,9,10,11};
+ vec4 c( data );
+ CHECK_EQUAL( c.x, 8 );
+ CHECK_EQUAL( c.y, 9 );
+ CHECK_EQUAL( c.z, 10 );
+ CHECK_EQUAL( c.w, 11 );
+
+ vec4 d( 33, false );
+ CHECK_EQUAL( d.x, 33 );
+ CHECK_EQUAL( d.y, 33 );
+ CHECK_EQUAL( d.z, 33 );
+ CHECK_EQUAL( d.w, 0 );
+
+ vec4 e( 45, true );
+ CHECK_EQUAL( e.x, 45 );
+ CHECK_EQUAL( e.y, 45 );
+ CHECK_EQUAL( e.z, 45 );
+ CHECK_EQUAL( e.w, 45 );
+
+ vec4 f( e );
+ CHECK_EQUAL( f.x, e.x );
+ CHECK_EQUAL( f.y, e.y );
+ CHECK_EQUAL( f.z, e.z );
+ CHECK_EQUAL( f.w, e.w );
+ }
+
+ TEST( Assignment )
+ {
+ vec4 a( 1, 2, 3, 4 ), b;
+ CHECK_EQUAL( b.x, 0 );
+ CHECK_EQUAL( b.y, 0 );
+ CHECK_EQUAL( b.z, 0 );
+ CHECK_EQUAL( b.w, 0 );
+ b = a;
+ CHECK_EQUAL( b.x, a.x );
+ CHECK_EQUAL( b.y, a.y );
+ CHECK_EQUAL( b.z, a.z );
+ CHECK_EQUAL( b.w, a.w );
+ b = 3.14;
+ CHECK_CLOSE( b.x, 3.14, 0.001 );
+ CHECK_CLOSE( b.y, 3.14, 0.001 );
+ CHECK_CLOSE( b.z, 3.14, 0.001 );
+ CHECK_CLOSE( b.w, 3.14, 0.001 );
+ }
+}
+
+
@@ -0,0 +1,240 @@
+
+
+#include <UnitTest++/UnitTest++.h>
+
+#include <modules/vec4.h>
+#include <modules/vec_func.h>
+
+SUITE( VecFuncTests )
+{
+ TEST( Vec4Addition )
+ {
+ vec4 a( 1, 2, 3, 4 ), b( 5, 5, 5, 5 );
+ vec4 c = a + b;
+ CHECK_CLOSE( c.x, a.x + b.x, 0.00001 );
+ CHECK_CLOSE( c.y, a.y + b.y, 0.00001 );
+ CHECK_CLOSE( c.z, a.z + b.z, 0.00001 );
+ CHECK_CLOSE( c.w, a.w + b.w, 0.00001 );
+
+ c = a + 10;
+ CHECK_CLOSE( c.x, a.x + 10, 0.00001 );
+ CHECK_CLOSE( c.y, a.y + 10, 0.00001 );
+ CHECK_CLOSE( c.z, a.z + 10, 0.00001 );
+ CHECK_CLOSE( c.w, a.w + 10, 0.00001 );
+
+ c = 10 + b;
+ CHECK_CLOSE( c.x, 10 + b.x, 0.00001 );
+ CHECK_CLOSE( c.y, 10 + b.y, 0.00001 );
+ CHECK_CLOSE( c.z, 10 + b.z, 0.00001 );
+ CHECK_CLOSE( c.w, 10 + b.w, 0.00001 );
+
+ vec4 d = +a;
+ CHECK_CLOSE( d.x, +a.x, 0.00001 );
+ CHECK_CLOSE( d.y, +a.y, 0.00001 );
+ CHECK_CLOSE( d.z, +a.z, 0.00001 );
+ CHECK_CLOSE( d.w, +a.w, 0.00001 );
+
+ vec4 e( 1, 2, 3, 4 );
+ e += a;
+ CHECK_CLOSE( e.x, 2, 0.00001 );
+ CHECK_CLOSE( e.y, 4, 0.00001 );
+ CHECK_CLOSE( e.z, 6, 0.00001 );
+ CHECK_CLOSE( e.w, 8, 0.00001 );
+
+ vec4 f( 1, 2, 3, 4 );
+ f += 2;
+ CHECK_CLOSE( f.x, 1+2.0f, 0.00001 );
+ CHECK_CLOSE( f.y, 2+2.0f, 0.00001 );
+ CHECK_CLOSE( f.z, 3+2.0f, 0.00001 );
+ CHECK_CLOSE( f.w, 4+2.0f, 0.00001 );
+
+
+ }
+
+ TEST( Vec4Subtraction )
+ {
+ vec4 a( 1, 2, 3, 4 ), b( 5, 5, 5, 5 );
+ vec4 c = a - b;
+ CHECK_CLOSE( c.x, a.x - b.x, 0.00001 );
+ CHECK_CLOSE( c.y, a.y - b.y, 0.00001 );
+ CHECK_CLOSE( c.z, a.z - b.z, 0.00001 );
+ CHECK_CLOSE( c.w, a.w - b.w, 0.00001 );
+
+ c = a - 10;
+ CHECK_CLOSE( c.x, a.x - 10, 0.00001 );
+ CHECK_CLOSE( c.y, a.y - 10, 0.00001 );
+ CHECK_CLOSE( c.z, a.z - 10, 0.00001 );
+ CHECK_CLOSE( c.w, a.w - 10, 0.00001 );
+
+ c = 10 - b;
+ CHECK_CLOSE( c.x, 10 - b.x, 0.00001 );
+ CHECK_CLOSE( c.y, 10 - b.y, 0.00001 );
+ CHECK_CLOSE( c.z, 10 - b.z, 0.00001 );
+ CHECK_CLOSE( c.w, 10 - b.w, 0.00001 );
+
+ vec4 d = -a;
+ CHECK_CLOSE( d.x, -a.x, 0.00001 );
+ CHECK_CLOSE( d.y, -a.y, 0.00001 );
+ CHECK_CLOSE( d.z, -a.z, 0.00001 );
+ CHECK_CLOSE( d.w, -a.w, 0.00001 );
+
+ vec4 e( 1, 2, 3, 6 );
+ e -= a;
+ CHECK_CLOSE( e.x, 0, 0.00001 );
+ CHECK_CLOSE( e.y, 0, 0.00001 );
+ CHECK_CLOSE( e.z, 0, 0.00001 );
+ CHECK_CLOSE( e.w, 2, 0.00001 );
+
+ vec4 f( 1, 2, 3, 4 );
+ f -= 2;
+ CHECK_CLOSE( f.x, 1-2.0f, 0.00001 );
+ CHECK_CLOSE( f.y, 2-2.0f, 0.00001 );
+ CHECK_CLOSE( f.z, 3-2.0f, 0.00001 );
+ CHECK_CLOSE( f.w, 4-2.0f, 0.00001 );
+ }
+
+ TEST( Vec4Multiplication )
+ {
+ vec4 a( 1, 2, 3, 4 ), b( 5, 5, 5, 5 );
+ vec4 c = a * b;
+ CHECK_CLOSE( c.x, a.x * b.x, 0.00001 );
+ CHECK_CLOSE( c.y, a.y * b.y, 0.00001 );
+ CHECK_CLOSE( c.z, a.z * b.z, 0.00001 );
+ CHECK_CLOSE( c.w, a.w * b.w, 0.00001 );
+
+ c = a * 10;
+ CHECK_CLOSE( c.x, a.x * 10, 0.00001 );
+ CHECK_CLOSE( c.y, a.y * 10, 0.00001 );
+ CHECK_CLOSE( c.z, a.z * 10, 0.00001 );
+ CHECK_CLOSE( c.w, a.w * 10, 0.00001 );
+
+ c = 10 * b;
+ CHECK_CLOSE( c.x, 10 * b.x, 0.00001 );
+ CHECK_CLOSE( c.y, 10 * b.y, 0.00001 );
+ CHECK_CLOSE( c.z, 10 * b.z, 0.00001 );
+ CHECK_CLOSE( c.w, 10 * b.w, 0.00001 );
+
+ vec4 e( 1, 2, 3, 4 );
+ e *= a;
+ CHECK_CLOSE( e.x, 1, 0.00001 );
+ CHECK_CLOSE( e.y, 4, 0.00001 );
+ CHECK_CLOSE( e.z, 9, 0.00001 );
+ CHECK_CLOSE( e.w, 16, 0.00001 );
+
+ vec4 f( 1, 2, 3, 4 );
+ f *= 2;
+ CHECK_CLOSE( f.x, 2.0f, 0.00001 );
+ CHECK_CLOSE( f.y, 4.0f, 0.00001 );
+ CHECK_CLOSE( f.z, 6.0f, 0.00001 );
+ CHECK_CLOSE( f.w, 8.0f, 0.00001 );
+ }
+
+
+ TEST( Vec4Diviaion )
+ {
+ vec4 a( 1, 2, 3, 4 ), b( 5, 5, 5, 5 );
+ vec4 c = a / b;
+ CHECK_CLOSE( c.x, a.x / b.x, 0.00001 );
+ CHECK_CLOSE( c.y, a.y / b.y, 0.00001 );
+ CHECK_CLOSE( c.z, a.z / b.z, 0.00001 );
+ CHECK_CLOSE( c.w, a.w / b.w, 0.00001 );
+
+ c = a / 10;
+ CHECK_CLOSE( c.x, a.x / 10, 0.00001 );
+ CHECK_CLOSE( c.y, a.y / 10, 0.00001 );
+ CHECK_CLOSE( c.z, a.z / 10, 0.00001 );
+ CHECK_CLOSE( c.w, a.w / 10, 0.00001 );
+
+ c = 10 / b;
+ CHECK_CLOSE( c.x, 10 / b.x, 0.00001 );
+ CHECK_CLOSE( c.y, 10 / b.y, 0.00001 );
+ CHECK_CLOSE( c.z, 10 / b.z, 0.00001 );
+ CHECK_CLOSE( c.w, 10 / b.w, 0.00001 );
+
+ vec4 e( 1, 2, 3, 8 );
+ e /= a;
+ CHECK_CLOSE( e.x, 1, 0.00001 );
+ CHECK_CLOSE( e.y, 1, 0.00001 );
+ CHECK_CLOSE( e.z, 1, 0.00001 );
+ CHECK_CLOSE( e.w, 2, 0.00001 );
+
+ vec4 f( 1, 2, 3, 4 );
+ f /= 2;
+ CHECK_CLOSE( f.x, 1/2.0f, 0.00001 );
+ CHECK_CLOSE( f.y, 2/2.0f, 0.00001 );
+ CHECK_CLOSE( f.z, 3/2.0f, 0.00001 );
+ CHECK_CLOSE( f.w, 4/2.0f, 0.00001 );
+
+ }
+
+ TEST( DotProduct )
+ {
+ CHECK_CLOSE( dot( vec4( 2.0f, 4.0f ),
+ vec4( 1.0f, 5.0f )), 22, 0.001 );
+ CHECK_CLOSE( dot( vec4( 10.0f, 2.0f, 30.0f ),
+ vec4( 3.0f, 9.0f, 4.0f )), 168, 0.001 );
+ CHECK_CLOSE( dot( vec4( 1.0f, 2.0f, 3.0f, 4 ),
+ vec4( 9, 8, 7, 6 )), 70, 0.001 );
+ }
+
+ TEST( CrossProduct )
+ {
+ /*b.set = [1,2,3,0];
+ a.set = [9,8,7,0];
+ assert( cross(a,b).cell == [10,-20,10,0], "Bad Cross Product" );
+ c.set = 0;
+ */
+ vec4 a( 3, -3, 1 ), b( 4, 9, 2 );
+ vec4 c = cross( a, b );
+ CHECK_CLOSE( c.x, -15, 0.00001 );
+ CHECK_CLOSE( c.y, -2, 0.00001 );
+ CHECK_CLOSE( c.z, 39, 0.00001 );
+ CHECK_CLOSE( c.w, 0, 0.00001 );
+
+ vec4 d( 3, -2, -2 ), e( -1, 0, 5 );
+ vec4 f = cross( d, e );
+ CHECK_CLOSE( f.x, -10, 0.00001 );
+ CHECK_CLOSE( f.y, -13, 0.00001 );
+ CHECK_CLOSE( f.z, -2, 0.00001 );
+ CHECK_CLOSE( f.w, 0, 0.00001 );
+ }
+
+ TEST( ColorClamp )
+ {
+ color a( 5.0, 6.0, -4.5, 1.9 ), b( 0.0, 1.0, 0.5, 3.00 );
+
+ color ca = clamped( a );
+ CHECK_CLOSE( ca.x, 1.0000, 0.00001 );
+ CHECK_CLOSE( ca.y, 1.0000, 0.00001 );
+ CHECK_CLOSE( ca.z, 0.0000, 0.00001 );
+ CHECK_CLOSE( ca.w, 1.0000, 0.00001 );
+ CHECK_CLOSE( a.x, 5.0, 0.00001 );
+ CHECK_CLOSE( a.y, 6.0, 0.00001 );
+ CHECK_CLOSE( a.z, -4.5, 0.00001 );
+ CHECK_CLOSE( a.w, 1.9, 0.00001 );
+
+ color cb = clamped( b, 1.0, 2.0 );
+ CHECK_CLOSE( cb.x, 1.0000, 0.00001 );
+ CHECK_CLOSE( cb.y, 1.0000, 0.00001 );
+ CHECK_CLOSE( cb.z, 1.0000, 0.00001 );
+ CHECK_CLOSE( cb.w, 2.0000, 0.00001 );
+ CHECK_CLOSE( b.x, 0.0, 0.00001 );
+ CHECK_CLOSE( b.y, 1.0, 0.00001 );
+ CHECK_CLOSE( b.z, 0.5, 0.00001 );
+ CHECK_CLOSE( b.w, 3.00, 0.00001 );
+
+
+ clamp( a );
+ CHECK_CLOSE( a.x, 1.0000, 0.00001 );
+ CHECK_CLOSE( a.y, 1.0000, 0.00001 );
+ CHECK_CLOSE( a.z, 0.0000, 0.00001 );
+ CHECK_CLOSE( a.w, 1.0000, 0.00001 );
+
+ clamp( b );
+ CHECK_CLOSE( b.x, 0.0000, 0.00001 );
+ CHECK_CLOSE( b.y, 1.0000, 0.00001 );
+ CHECK_CLOSE( b.z, 0.5, 0.00001 );
+ CHECK_CLOSE( b.w, 1.0, 0.00001 );
+ }
+}
+

0 comments on commit 001ddfc

Please sign in to comment.