Saturday 1 October 2011

Unit Tests, Love Hate

Today I decided to try and get some unit tests created for the matrix functions which I implemented in yesterdays push (https://github.com/saecob/gladius.math/tree/Matrix2).

After spending some time identifying how unit tests are launched (index.html),


I created my own test script with the name Math.Matrix2.js which tests 2 x 2 matrices.

When I first ran the newly created test, I noticed that none of the coded implementations of any size matrix had been tested.  After further inspection, the matrix functions seem to be direct logic and code copies of all the implemented vector functions.

At first glance this doesn't seem to be such a big problem but I don't think that they correlate exactly.

The second issue which came about from these discoveries is, that at the moment I feel like I am implementing and adding functions arbitrarily not knowing if they will even be useful to someone using the library.

For example, we have a function rotate() which creates a rotation matrix given a Quaternion(http://en.wikipedia.org/wiki/Quaternion). This function is implemented under matrix4 functions, i.e 4x4 matrices.

The question is: Do we need this function for 2x2 and 3x3 matrices as well?

        // Construct a 2x2 rotation matrix from a Quaternion.
        rotate: function() {
            if( 0 === arguments.length ) {
                return Matrix( 4, that.matrix2.identity );
            } else if( 1 === arguments.length ) {
                var v = arguments[0];
                var r = v[0];
//              return Matrix( 4, [] );
            // Todo (Quaternion = w + xi + yj + zk)
            } else {
                return Matrix( 4, arguments );
            }
        }
    };


It seems like it would be a good idea to collaborate with the different areas of the project (Physics, Rendering, etc.) and come up with an interface with a list of functions, parameters, and return types/values so that everything put in Gladius.Math is useful as a library.

No comments:

Post a Comment