提交 d208473d 编写于 作者: M Mr.doob

Merge pull request #7708 from simonThiele/unittests

Unittests
......@@ -184,8 +184,6 @@ test( "computeBoundingBox", function() {
ok( bb.min.x === bb.max.x && bb.min.y === bb.max.y && bb.min.z === bb.max.z, "since there is only one vertex, max and min are equal" );
ok( bb.min.x === -1 && bb.min.y === -1 && bb.min.z === -1, "since there is only one vertex, min and max are this vertex" );
bb = getBBForVertices( [-1] );
});
test( "computeBoundingSphere", function() {
......
......@@ -20,16 +20,16 @@ test( "copy", function() {
var instanceMock1 = {};
var instanceMock2 = {};
var indexMock = createClonableMock();
var attributeMock1 = {};
var attributeMock2 = {};
var defaultAttribute1 = new THREE.BufferAttribute([1]);
var defaultAttribute2 = new THREE.BufferAttribute([2]);
var instance = new THREE.InstancedBufferGeometry();
instance.addGroup( 0, 10, instanceMock1 );
instance.addGroup( 10, 5, instanceMock2 );
instance.setIndex( indexMock );
instance.addAttribute( 'attributeMock1', attributeMock1 );
instance.addAttribute( 'attributeMock2', attributeMock2 );
instance.addAttribute( 'defaultAttribute1', defaultAttribute1 );
instance.addAttribute( 'defaultAttribute2', defaultAttribute2 );
var copiedInstance = instance.copy( instance );
......@@ -38,10 +38,10 @@ test( "copy", function() {
ok( copiedInstance.index === indexMock, "index was copied" );
ok( copiedInstance.index.callCount === 1, "index.clone was called once" );
ok( copiedInstance.attributes['attributeMock1'] instanceof THREE.BufferAttribute, "attribute was created" );
ok( copiedInstance.attributes['defaultAttribute1'] instanceof THREE.BufferAttribute, "attribute was created" );
// the given attribute mock was passed to the array property of the created buffer attribute
ok( copiedInstance.attributes['attributeMock1'].array === attributeMock1, "attribute was copied" );
ok( copiedInstance.attributes['attributeMock2'].array === attributeMock2, "attribute was copied" );
ok( copiedInstance.attributes['defaultAttribute1'].array[0] === defaultAttribute1.array, "attribute was copied" );
ok( copiedInstance.attributes['defaultAttribute2'].array[0] === defaultAttribute2.array, "attribute was copied" );
ok( copiedInstance.groups[0].start === 0, "group was copied" );
ok( copiedInstance.groups[0].count === 10, "group was copied" );
......
......@@ -17,20 +17,19 @@ QUnit.test( "test load handler", function( assert ) {
var done = assert.async();
THREE.ImageUtils.loadTexture( good_url, undefined, function ( tex ) {
new THREE.TextureLoader().load(good_url, function ( tex ) {
assert.success( "load handler should be called" );
assert.ok( tex, "texture is defined" );
assert.ok( tex.image, "texture.image is defined" );
done();
}, function () {
}, undefined, function () {
assert.fail( "error handler should not be called" );
done();
});
});
......@@ -38,12 +37,16 @@ QUnit.test( "test error handler", function( assert ) {
var done = assert.async();
THREE.ImageUtils.loadTexture( bad_url, undefined, function () {
new THREE.TextureLoader().load(bad_url, function () {
assert.fail( "load handler should not be called" );
done();
}, function ( event ) {
},
undefined,
function ( event ) {
assert.success( "error handler should be called" );
assert.ok( event.type === 'error', "should have error event" );
......@@ -59,12 +62,12 @@ QUnit.test( "test cached texture", function( assert ) {
var done = assert.async();
var rtex1 = THREE.ImageUtils.loadTexture( good_url, undefined, function ( tex1 ) {
var rtex1 = new THREE.TextureLoader().load(good_url, function ( tex1 ) {
assert.ok( rtex1.image !== undefined, "texture 1 image is loaded" );
assert.equal( rtex1, tex1, "texture 1 callback is equal to return" );
var rtex2 = THREE.ImageUtils.loadTexture( good_url, undefined, function ( tex2 ) {
var rtex2 = new THREE.TextureLoader().load(good_url, function ( tex2 ) {
assert.ok( rtex2 !== undefined, "cached callback is async" );
assert.ok( rtex2.image !== undefined, "texture 2 image is loaded" );
......@@ -82,4 +85,3 @@ QUnit.test( "test cached texture", function( assert ) {
assert.ok( rtex1.image === undefined, "texture 1 image is not loaded" );
});
......@@ -21,7 +21,7 @@
box = new THREE.BoxGeometry( parameters.width, parameters.height, parameters.depth );
cube = new THREE.CubeGeometry( parameters.width, parameters.height, parameters.depth );
boxWithSegments = new THREE.BoxGeometry( parameters.width, parameters.height, parameters.depth,
parameters.widthSegments, parameters.heightSegments, parameters.depthSegments );
parameters.widthSegments, parameters.heightSegments, parameters.depthSegments );
geometries = [ box, cube, boxWithSegments ];
......
......@@ -152,7 +152,7 @@ function createIndexedBufferGeometry ( vertList, idxList ) {
vertices = vertices.subarray( 0, 3 * numVerts );
geom.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
geom.setIndex( new THREE.BufferAttribute( indices, 1 ) );
geom.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
geom.computeFaceNormals();
......@@ -163,7 +163,7 @@ function createIndexedBufferGeometry ( vertList, idxList ) {
function addDrawCalls ( geometry ) {
var numTris = geometry.getAttribute( 'index' ).count / 3;
var numTris = geometry.index.count / 3;
var offset = 0;
for ( var i = 0 ; i < numTris; i ++ ) {
......@@ -171,8 +171,7 @@ function addDrawCalls ( geometry ) {
var start = i * 3;
var count = 3;
geometry.addDrawCall ( start, count, offset );
geometry.addGroup( start, count );
}
return geometry;
......
......@@ -7,7 +7,7 @@ module( "Euler" );
var eulerZero = new THREE.Euler( 0, 0, 0, "XYZ" );
var eulerAxyz = new THREE.Euler( 1, 0, 0, "XYZ" );
var eulerAzyx = new THREE.Euler( 0, 1, 0, "ZYX" );
var matrixEquals4 = function( a, b, tolerance ) {
tolerance = tolerance || 0.0001;
if( a.elements.length != b.elements.length ) {
......@@ -24,14 +24,14 @@ var matrixEquals4 = function( a, b, tolerance ) {
var eulerEquals = function( a, b, tolerance ) {
tolerance = tolerance || 0.0001;
var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
return ( diff < tolerance );
};
var quatEquals = function( a, b, tolerance ) {
tolerance = tolerance || 0.0001;
var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z ) + Math.abs( a.w - b.w );
var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z ) + Math.abs( a.w - b.w );
return ( diff < tolerance );
};
......@@ -66,11 +66,9 @@ test( "set/setFromVector3/toVector3", function() {
var vec = new THREE.Vector3( 0, 1, 0 );
var b = new THREE.Euler().setFromVector3( vec, "ZYX" );
console.log( a, b );
ok( a.equals( b ), "Passed!" );
var c = b.toVector3();
console.log( c, vec );
ok( c.equals( vec ), "Passed!" );
});
......@@ -82,7 +80,7 @@ test( "Quaternion.setFromEuler/Euler.fromQuaternion", function() {
var v2 = new THREE.Euler().setFromQuaternion( q, v.order );
var q2 = new THREE.Quaternion().setFromEuler( v2 );
ok( eulerEquals( q, q2 ), "Passed!" );
ok( eulerEquals( q, q2 ), "Passed!" );
}
});
......@@ -95,7 +93,7 @@ test( "Matrix4.setFromEuler/Euler.fromRotationMatrix", function() {
var v2 = new THREE.Euler().setFromRotationMatrix( m, v.order );
var m2 = new THREE.Matrix4().makeRotationFromEuler( v2 );
ok( matrixEquals4( m, m2, 0.0001 ), "Passed!" );
ok( matrixEquals4( m, m2, 0.0001 ), "Passed!" );
}
});
......@@ -105,13 +103,13 @@ test( "reorder", function() {
var v = testValues[i];
var q = new THREE.Quaternion().setFromEuler( v );
v.reorder( 'YZX' );
v.reorder( 'YZX' );
var q2 = new THREE.Quaternion().setFromEuler( v );
ok( quatEquals( q, q2 ), "Passed!" );
ok( quatEquals( q, q2 ), "Passed!" );
v.reorder( 'ZXY' );
var q3 = new THREE.Quaternion().setFromEuler( v );
ok( quatEquals( q, q3 ), "Passed!" );
ok( quatEquals( q, q3 ), "Passed!" );
}
});
......@@ -133,4 +131,4 @@ test( "gimbalLocalQuat", function() {
// the results here are different
ok( eulerEquals( eViaQ1, eViaMViaQ1 ), "Passed!" ); // this result is correct
});
\ No newline at end of file
});
......@@ -167,7 +167,7 @@ test( "getInverse", function() {
b.getInverse( a, false );
ok( matrixEquals4( b, new THREE.Matrix4() ), "Passed!" );
try {
try {
b.getInverse( c, true );
ok( false, "Passed!" ); // should never get here.
}
......@@ -225,8 +225,7 @@ test( "makeBasis/extractBasis", function() {
b.extractBasis( outBasis[0], outBasis[1], outBasis[2] );
// check what goes in, is what comes out.
for( var j = 0; j < outBasis.length; j ++ ) {
console.log( outBasis[j], testBasis[j] );
ok( outBasis[j].equals( testBasis[j] ), "Passed!" );
ok( outBasis[j].equals( testBasis[j] ), "Passed!" );
}
// get the basis out the hard war
......@@ -236,9 +235,9 @@ test( "makeBasis/extractBasis", function() {
}
// did the multiply method of basis extraction work?
for( var j = 0; j < outBasis.length; j ++ ) {
ok( outBasis[j].equals( testBasis[j] ), "Passed!" );
ok( outBasis[j].equals( testBasis[j] ), "Passed!" );
}
}
}
});
test( "transpose", function() {
......@@ -248,9 +247,9 @@ test( "transpose", function() {
b = new THREE.Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
var c = b.clone().transpose();
ok( ! matrixEquals4( b, c ), "Passed!" );
ok( ! matrixEquals4( b, c ), "Passed!" );
c.transpose();
ok( matrixEquals4( b, c ), "Passed!" );
ok( matrixEquals4( b, c ), "Passed!" );
});
test( "clone", function() {
......@@ -313,7 +312,7 @@ test( "compose/decompose", function() {
m.decompose( t2, r2, s2 );
var m2 = new THREE.Matrix4().compose( t2, r2, s2 );
var matrixIsSame = matrixEquals4( m, m2 );
/* debug code
if( ! matrixIsSame ) {
......@@ -326,4 +325,4 @@ test( "compose/decompose", function() {
}
}
}
});
\ No newline at end of file
});
......@@ -334,9 +334,6 @@ function slerpTestSkeleton( doSlerp, maxError ) {
result = doSlerp( [ 0, D, 0, D ], [ 0, -D, 0, D ], 0.5 );
ok( result.equals( 0, 0, 0, 1 ), "W-Unit from diagonals" );
ok( isNormal( result ), "Approximately normal (W-Unit)" );
console.log( "maxNormError", maxNormError );
}
......
......@@ -56,14 +56,47 @@ function checkGeometryClone( geom ) {
var copy = geom.clone();
QUnit.assert.notEqual( copy.uuid, geom.uuid, "clone uuid should differ from original" );
QUnit.assert.notEqual( copy.id, geom.id, "clone id should differ from original" );
QUnit.assert.smartEqual( copy, geom, "clone is equal to original" );
var excludedProperties = [ 'parameters', 'widthSegments', 'heightSegments', 'depthSegments' ];
var differingProp = getDifferingProp( geom, copy, excludedProperties );
ok( differingProp === undefined, 'properties are equal' );
differingProp = getDifferingProp( copy, geom, excludedProperties );
ok( differingProp === undefined, 'properties are equal' );
// json round trip with clone
checkGeometryJsonRoundtrip( copy );
}
function getDifferingProp( geometryA, geometryB, excludedProperties) {
excludedProperties = excludedProperties || [];
var geometryKeys = Object.keys( geometryA );
var cloneKeys = Object.keys( geometryB );
var keysWhichAreNotChecked = [ 'parameters', 'widthSegments', 'heightSegments', 'depthSegments' ];
var differingProp = undefined;
for ( var i = 0, l = geometryKeys.length; i < l; i++ ) {
var key = geometryKeys[ i ];
if ( excludedProperties.indexOf(key) >= 0 ) {
continue;
}
if ( cloneKeys.indexOf( key ) < 0 ) {
differingProp = key;
break;
}
}
return differingProp;
}
// Compare json file with its source geometry.
function checkGeometryJsonWriting( geom, json ) {
......@@ -108,7 +141,20 @@ function checkGeometryJsonReading( json, geom ) {
var output = loader.parseGeometries( wrap );
QUnit.assert.ok( output[ geom.uuid ], 'geometry matching source uuid not in output' );
QUnit.assert.smartEqual( output[ geom.uuid ], geom, 'Reconstruct geometry from ObjectLoader' );
// QUnit.assert.smartEqual( output[ geom.uuid ], geom, 'Reconstruct geometry from ObjectLoader' );
var differing = getDifferingProp(output[ geom.uuid ], geom, ['bones']);
if (differing) {
console.log(differing);
}
var excludedProperties = [ 'bones' ];
var differingProp = getDifferingProp( output[ geom.uuid ], geom, excludedProperties );
ok( differingProp === undefined, 'properties are equal' );
differingProp = getDifferingProp( geom, output[ geom.uuid ], excludedProperties );
ok( differingProp === undefined, 'properties are equal' );
}
// Verify geom -> json -> geom
......@@ -207,9 +253,11 @@ function checkLightClone( light ) {
function checkLightJsonWriting( light, json ) {
QUnit.assert.equal( json.metadata.version, "4.4", "check metadata version" );
QUnit.assert.equalKey( light, json, 'type' );
QUnit.assert.equalKey( light, json, 'uuid' );
QUnit.assert.equal( json.id, undefined, "should not persist id" );
var object = json.object;
QUnit.assert.equalKey( light, object, 'type' );
QUnit.assert.equalKey( light, object, 'uuid' );
QUnit.assert.equal( object.id, undefined, "should not persist id" );
}
......@@ -227,7 +275,7 @@ function checkLightJsonReading( json, light ) {
function checkLightJsonRoundtrip( light ) {
var json = light.toJSON();
checkLightJsonWriting( light, json.object );
checkLightJsonWriting( light, json );
checkLightJsonReading( json, light );
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册