소스 검색

Merge pull request #10864 from donmccurdy/test-object3d

Fix Object3D tests.
Mr.doob 8 년 전
부모
커밋
3e409c2e64
1개의 변경된 파일10개의 추가작업 그리고 30개의 파일을 삭제
  1. 10 30
      test/unit/src/core/Object3D.js

+ 10 - 30
test/unit/src/core/Object3D.js

@@ -12,8 +12,7 @@ QUnit.test( "rotateX" , function( assert ) {
 	var angleInRad = 1.562;
 	obj.rotateX(angleInRad);
 
-	// should calculate the correct rotation on x
-	checkIfFloatsAreEqual(obj.rotation.x, angleInRad, assert);
+	assert.numEqual( obj.rotation.x, angleInRad, "x is equal" );
 });
 
 QUnit.test( "rotateY" , function( assert ) {
@@ -22,8 +21,7 @@ QUnit.test( "rotateY" , function( assert ) {
 	var angleInRad = -0.346;
 	obj.rotateY(angleInRad);
 
-	// should calculate the correct rotation on y
-	checkIfFloatsAreEqual(obj.rotation.y, angleInRad, assert);
+	assert.numEqual( obj.rotation.y, angleInRad, "y is equal" );
 });
 
 QUnit.test( "rotateZ" , function( assert ) {
@@ -32,71 +30,53 @@ QUnit.test( "rotateZ" , function( assert ) {
 	var angleInRad = 1;
 	obj.rotateZ(angleInRad);
 
-	// should calculate the correct rotation on y
-	checkIfFloatsAreEqual(obj.rotation.z, angleInRad, assert);
+	assert.numEqual( obj.rotation.z, angleInRad, "z is equal" );
 });
 
 QUnit.test( "translateOnAxis" , function( assert ) {
 	var obj = new THREE.Object3D();
 
-	// get a reference object for comparing
-	var reference = {x: 1, y: 1.23, z: -4.56};
 	obj.translateOnAxis(new THREE.Vector3(1, 0, 0), 1);
 	obj.translateOnAxis(new THREE.Vector3(0, 1, 0), 1.23);
 	obj.translateOnAxis(new THREE.Vector3(0, 0, 1), -4.56);
 
-	checkIfPropsAreEqual(reference, obj.position, assert);
+	assert.propEqual( obj.position, { x: 1, y: 1.23, z: -4.56 } );
 });
 
 QUnit.test( "translateX" , function( assert ) {
 	var obj = new THREE.Object3D();
 	obj.translateX(1.234);
 
-	assert.ok( obj.position.x === 1.234 , "x is equal" );
+	assert.numEqual( obj.position.x, 1.234, "x is equal" );
 });
 
 QUnit.test( "translateY" , function( assert ) {
 	var obj = new THREE.Object3D();
 	obj.translateY(1.234);
 
-	assert.ok( obj.position.y === 1.234 , "y is equal" );
+	assert.numEqual( obj.position.y, 1.234, "y is equal" );
 });
 
 QUnit.test( "translateZ" , function( assert ) {
 	var obj = new THREE.Object3D();
 	obj.translateZ(1.234);
 
-	assert.ok( obj.position.z === 1.234 , "z is equal" );
+	assert.numEqual( obj.position.z, 1.234, "z is equal" );
 });
 
 QUnit.test( "lookAt" , function( assert ) {
 	var obj = new THREE.Object3D();
 	obj.lookAt(new THREE.Vector3(0, -1, 1));
 
-	assert.ok( obj.rotation.x * RadToDeg === 45 , "x is equal" );
+	assert.numEqual( obj.rotation.x * RadToDeg, 45, "x is equal" );
 });
 
 QUnit.test( "getWorldRotation" , function( assert ) {
 	var obj = new THREE.Object3D();
 
 	obj.lookAt(new THREE.Vector3(0, -1, 1));
-	assert.ok( obj.getWorldRotation().x * RadToDeg === 45 , "x is equal" );
+	assert.numEqual( obj.getWorldRotation().x * RadToDeg, 45, "x is equal" );
 
 	obj.lookAt(new THREE.Vector3(1, 0, 0));
-	assert.ok( obj.getWorldRotation().y * RadToDeg === 90 , "y is equal" );
+	assert.numEqual( obj.getWorldRotation().y * RadToDeg, 90, "y is equal" );
 });
-
-function checkIfPropsAreEqual(reference, obj, assert) {
-	assert.ok( obj.x === reference.x , "x is equal" );
-	assert.ok( obj.y === reference.y , "y is equal!" );
-	assert.ok( obj.z === reference.z , "z is equal!" );
-}
-
-// since float equal checking is a mess in js, one solution is to cut off
-// decimal places
-function checkIfFloatsAreEqual(f1, f2, assert) {
-	var f1Rounded = ((f1 * 1000) | 0) / 1000;
-	var f2Rounded = ((f2 * 1000) | 0) / 1000;
-
-	assert.ok( f1Rounded === f2Rounded, "passed" );
-}