Skip to content

Commit

Permalink
Add unit tests of multiplyMatrices methods for both Matrix3 and Matrix4
Browse files Browse the repository at this point in the history
  • Loading branch information
yellcorp committed Mar 28, 2017
1 parent 1b963b9 commit 22b7fcd
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/unit/src/math/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,39 @@ QUnit.test( "identity" , function( assert ) {
assert.ok( matrixEquals3( a, b ), "Passed!" );
});

QUnit.test( "multiplyMatrices" , function ( assert ) {
// Reference:
//
// #!/usr/bin/env python
// from __future__ import print_function
// import numpy as np
// print(
// np.dot(
// np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23], (3, 3)),
// np.reshape([29, 31, 37, 41, 43, 47, 53, 59, 61], (3, 3))
// )
// )
//
// [[ 446 486 520]
// [1343 1457 1569]
// [2491 2701 2925]]
var lhs = new THREE.Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
var rhs = new THREE.Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
var ans = new THREE.Matrix3();

ans.multiplyMatrices(lhs, rhs);

assert.ok( ans.elements[0] == 446 );
assert.ok( ans.elements[1] == 1343 );
assert.ok( ans.elements[2] == 2491 );
assert.ok( ans.elements[3] == 486 );
assert.ok( ans.elements[4] == 1457 );
assert.ok( ans.elements[5] == 2701 );
assert.ok( ans.elements[6] == 520 );
assert.ok( ans.elements[7] == 1569 );
assert.ok( ans.elements[8] == 2925 );
});

QUnit.test( "multiplyScalar" , function( assert ) {
var b = new THREE.Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
assert.ok( b.elements[0] == 0 );
Expand Down
41 changes: 41 additions & 0 deletions test/unit/src/math/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,47 @@ QUnit.test( "identity" , function( assert ) {
assert.ok( matrixEquals4( a, b ), "Passed!" );
});

QUnit.test( "multiplyMatrices" , function ( assert ) {
// Reference:
//
// #!/usr/bin/env python
// from __future__ import print_function
// import numpy as np
// print(
// np.dot(
// np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53], (4, 4)),
// np.reshape([59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131], (4, 4))
// )
// )
//
// [[ 1585 1655 1787 1861]
// [ 5318 5562 5980 6246]
// [10514 11006 11840 12378]
// [15894 16634 17888 18710]]
var lhs = new THREE.Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
var rhs = new THREE.Matrix4().set( 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131 );
var ans = new THREE.Matrix4();

ans.multiplyMatrices(lhs, rhs);

assert.ok( ans.elements[0] == 1585 );
assert.ok( ans.elements[1] == 5318 );
assert.ok( ans.elements[2] == 10514 );
assert.ok( ans.elements[3] == 15894 );
assert.ok( ans.elements[4] == 1655 );
assert.ok( ans.elements[5] == 5562 );
assert.ok( ans.elements[6] == 11006 );
assert.ok( ans.elements[7] == 16634 );
assert.ok( ans.elements[8] == 1787 );
assert.ok( ans.elements[9] == 5980 );
assert.ok( ans.elements[10] == 11840 );
assert.ok( ans.elements[11] == 17888 );
assert.ok( ans.elements[12] == 1861 );
assert.ok( ans.elements[13] == 6246 );
assert.ok( ans.elements[14] == 12378 );
assert.ok( ans.elements[15] == 18710 );
});

QUnit.test( "multiplyScalar" , function( assert ) {
var b = new THREE.Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
assert.ok( b.elements[0] == 0 );
Expand Down

0 comments on commit 22b7fcd

Please sign in to comment.