Jelajahi Sumber

Merge pull request #10868 from donmccurdy/test-camera-core-curves

Fix tests for Camera, Clock, InstancedBufferGeometry, InterleavedBuffer.
Mr.doob 8 tahun lalu
induk
melakukan
18473b3eb9

+ 1 - 1
test/unit/src/cameras/Camera.js

@@ -8,7 +8,7 @@ QUnit.test( "lookAt" , function( assert ) {
 	var cam = new THREE.Camera();
 	cam.lookAt(new THREE.Vector3(0, 1, -1));
 
-	assert.ok( cam.rotation.x * (180 / Math.PI) === 45 , "x is equal" );
+	assert.numEqual( cam.rotation.x * ( 180 / Math.PI ), 45, "x is equal" );
 });
 
 QUnit.test( "clone" , function( assert ) {

+ 7 - 7
test/unit/src/core/Clock.js

@@ -21,18 +21,18 @@ function mockPerformance() {
 QUnit.test( "clock with performance", function( assert ) {
 	mockPerformance();
 
-	var clock = new THREE.Clock();
+	var clock = new THREE.Clock( false );
 
 	clock.start();
 
-	self.performance.next(123);
-	assert.ok( clock.getElapsedTime() === 0.123 , "okay");
+	self.performance.next( 123 );
+	assert.numEqual( clock.getElapsedTime(), 0.123, "okay" );
 
-	self.performance.next(100);
-	assert.ok( clock.getElapsedTime() === 0.223 , "okay");
+	self.performance.next( 100 );
+	assert.numEqual( clock.getElapsedTime(), 0.223, "okay" );
 
 	clock.stop();
 
-	self.performance.next(1000);
-	assert.ok( clock.getElapsedTime() === 0.223 , "don't update time if the clock was stopped");
+	self.performance.next( 1000 );
+	assert.numEqual( clock.getElapsedTime(), 0.223, "don't update time if the clock was stopped" );
 });

+ 12 - 13
test/unit/src/core/InstancedBufferGeometry.js

@@ -20,8 +20,8 @@ QUnit.test( "copy" , function( assert ) {
 	var instanceMock1 = {};
 	var instanceMock2 = {};
 	var indexMock = createClonableMock();
-	var defaultAttribute1 = new THREE.BufferAttribute([1]);
-	var defaultAttribute2 = new THREE.BufferAttribute([2]);
+	var defaultAttribute1 = new THREE.BufferAttribute( new Float32Array( [ 1 ] ) );
+	var defaultAttribute2 = new THREE.BufferAttribute( new Float32Array( [ 2 ] ) );
 
 	var instance = new THREE.InstancedBufferGeometry();
 
@@ -35,19 +35,18 @@ QUnit.test( "copy" , function( assert ) {
 
 	assert.ok( copiedInstance instanceof THREE.InstancedBufferGeometry, "the clone has the correct type" );
 
-	assert.ok( copiedInstance.index === indexMock, "index was copied" );
-	assert.ok( copiedInstance.index.callCount === 1, "index.clone was called once" );
+	assert.equal( copiedInstance.index, indexMock, "index was copied" );
+	assert.equal( copiedInstance.index.callCount, 1, "index.clone was called once" );
 
 	assert.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
-	assert.ok( copiedInstance.attributes['defaultAttribute1'].array[0] === defaultAttribute1.array, "attribute was copied" );
-	assert.ok( copiedInstance.attributes['defaultAttribute2'].array[0] === defaultAttribute2.array, "attribute was copied" );
+	assert.deepEqual( copiedInstance.attributes['defaultAttribute1'].array, defaultAttribute1.array, "attribute was copied" );
+	assert.deepEqual( copiedInstance.attributes['defaultAttribute2'].array, defaultAttribute2.array, "attribute was copied" );
 
-	assert.ok( copiedInstance.groups[0].start === 0, "group was copied" );
-	assert.ok( copiedInstance.groups[0].count === 10, "group was copied" );
-	assert.ok( copiedInstance.groups[0].instances === instanceMock1, "group was copied" );
+	assert.equal( copiedInstance.groups[0].start, 0, "group was copied" );
+	assert.equal( copiedInstance.groups[0].count, 10, "group was copied" );
+	assert.equal( copiedInstance.groups[0].materialIndex, instanceMock1, "group was copied" );
 
-	assert.ok( copiedInstance.groups[1].start === 10, "group was copied" );
-	assert.ok( copiedInstance.groups[1].count === 5, "group was copied" );
-	assert.ok( copiedInstance.groups[1].instances === instanceMock2, "group was copied" );
+	assert.equal( copiedInstance.groups[1].start, 10, "group was copied" );
+	assert.equal( copiedInstance.groups[1].count, 5, "group was copied" );
+	assert.equal( copiedInstance.groups[1].materialIndex, instanceMock2, "group was copied" );
 });

+ 2 - 3
test/unit/src/core/InterleavedBuffer.js

@@ -15,11 +15,10 @@ function checkInstanceAgainstCopy( instance, copiedInstance, assert ) {
 	assert.ok( copiedInstance.dynamic === true, "dynamic was copied" );
 }
 
-QUnit.test( "length and count", function( assert ) {
+QUnit.test( "count", function( assert ) {
 	var instance = new THREE.InterleavedBuffer( new Float32Array( [1, 2, 3, 7, 8 ,9] ), 3 );
 
-	assert.ok( instance.length === 6, "length is calculated via array length" );
-	assert.ok( instance.count === 2, "count is calculated via array length / stride" );
+	assert.equal( instance.count, 2, "count is calculated via array length / stride" );
 });
 
 QUnit.test( "copy" , function( assert ) {

+ 48 - 24
test/unit/src/extras/curves/CatmullRomCurve3.js

@@ -17,7 +17,7 @@ QUnit.test( "catmullrom check", function( assert ) {
 	var curve = new THREE.CatmullRomCurve3( positions );
 	curve.type = 'catmullrom';
 
-	var catmullPoints = [
+	var expectedPoints = [
 
 		new THREE.Vector3( - 60, - 100, 60 ),
 		new THREE.Vector3( - 60, - 51.04, 60 ),
@@ -33,11 +33,17 @@ QUnit.test( "catmullrom check", function( assert ) {
 
 	];
 
-	var getPoints = curve.getPoints( 10 );
-	var error = vectorsAreEqual( getPoints, catmullPoints );
-	assert.ok( getPoints.length == 11, 'getPoints should be equal.' );
-	var desc = error ? ' ' + error : '';
-	assert.ok( ! error, 'Lists of Vectors3 should be equal.' + desc );
+	var points = curve.getPoints( 10 );
+
+	assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
+
+	points.forEach( function ( point, i ) {
+
+		assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
+		assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
+		assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
+
+	} );
 
 } );
 
@@ -47,7 +53,7 @@ QUnit.test( "chordal basic check", function( assert ) {
 
 	curve.type = 'chordal';
 
-	var chordalPoints = [
+	var expectedPoints = [
 		new THREE.Vector3( - 60, - 100, 60 ),
 		new THREE.Vector3( - 60, - 52, 60 ),
 		new THREE.Vector3( - 60, - 4, 60 ),
@@ -61,11 +67,17 @@ QUnit.test( "chordal basic check", function( assert ) {
 		new THREE.Vector3( 60.00000000000001, - 100, - 60.00000000000001 )
 	];
 
-	var getPoints = curve.getPoints( 10 );
-	var error = vectorsAreEqual( getPoints, chordalPoints );
-	assert.ok( getPoints.length == 11, 'getPoints should be equal.' );
-	var desc = error ? ' ' + error : '';
-	assert.ok( ! error, 'Lists of Vectors3 should be equal.' + desc );
+	var points = curve.getPoints( 10 );
+
+	assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
+
+	points.forEach( function ( point, i ) {
+
+		assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
+		assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
+		assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
+
+	} );
 
 } );
 
@@ -74,7 +86,7 @@ QUnit.test( "centripetal basic check", function( assert ) {
 	var curve = new THREE.CatmullRomCurve3( positions );
 	curve.type = 'centripetal';
 
-	var centripetalPoints = [
+	var expectedPoints = [
 		new THREE.Vector3( - 60, - 100, 60 ),
 		new THREE.Vector3( - 60, - 51.47527724919028, 60 ),
 		new THREE.Vector3( - 60, - 3.300369665587032, 60 ),
@@ -88,11 +100,17 @@ QUnit.test( "centripetal basic check", function( assert ) {
 		new THREE.Vector3( 59.99999999999999, - 100, - 59.99999999999999 ),
 	];
 
-	var getPoints = curve.getPoints( 10 );
-	var error = vectorsAreEqual( getPoints, centripetalPoints );
-	assert.ok( getPoints.length == 11, 'getPoints should be equal.' );
-	var desc = error ? ' ' + error : '';
-	assert.ok( ! error, 'Lists of Vectors3 should be equal.' + desc );
+	var points = curve.getPoints( 10 );
+
+	assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
+
+	points.forEach( function ( point, i ) {
+
+		assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
+		assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
+		assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
+
+	} );
 
 } );
 
@@ -102,7 +120,7 @@ QUnit.test( "closed catmullrom basic check", function( assert ) {
 	curve.type = 'catmullrom';
 	curve.closed = true;
 
-	var closedSplinePoints = [
+	var expectedPoints = [
 		new THREE.Vector3( - 60, - 100, 60 ),
 		new THREE.Vector3( - 67.5, - 46.25, 67.5 ),
 		new THREE.Vector3( - 60, 20, 60 ),
@@ -116,10 +134,16 @@ QUnit.test( "closed catmullrom basic check", function( assert ) {
 		new THREE.Vector3( - 60, - 100, 60 ),
 	];
 
-	var getPoints = curve.getPoints( 10 );
-	var error = vectorsAreEqual( getPoints, closedSplinePoints );
-	assert.ok( getPoints.length == 11, 'getPoints should be equal.' );
-	var desc = error ? ' ' + error : '';
-	assert.ok( ! error, 'Lists of Vectors3 should be equal.' + desc );
+	var points = curve.getPoints( 10 );
+
+	assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
+
+	points.forEach( function ( point, i ) {
+
+		assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
+		assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
+		assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
+
+	} );
 
 } );