Jelajahi Sumber

simplified tests and some code cleanup

Mario Schuettel 9 tahun lalu
induk
melakukan
fea1eae4d2

+ 28 - 24
test/unit/editor/TestCmdSetPosition.js

@@ -3,37 +3,41 @@ module( "CmdSetPosition" );
 test( "Test CmdSetPosition (Undo and Redo)", function() {
 
 	var editor = new Editor();
+	var box = aBox();
+	var cmd = new CmdAddObject( box );
+	editor.execute( cmd );
 
-	var mesh = aBox();
-	var initPosX =  50 ;
-	var initPosY = -80 ;
-	var initPosZ =  30 ;
-	mesh.position.x = initPosX ;
-	mesh.position.y = initPosY ;
-	mesh.position.z = initPosZ ;
+	var positions = [
 
-	editor.execute( new CmdAddObject( mesh ) );
-	editor.select( mesh );
+		{ x:  50, y: -80, z: 30 },
+		{ x: -10, y: 100, z:  0 },
+		{ x:  44, y: -20, z: 90 }
 
-	// translate the object
-	var newPosX = 100 ;
-	var newPosY = 200 ;
-	var newPosZ = 500 ;
-	var newPosition = new THREE.Vector3( newPosX, newPosY, newPosZ );
-	editor.execute( new CmdSetPosition( mesh, newPosition ) );
+	];
+
+	positions.map( function( position ) {
+
+		var newPosition = new THREE.Vector3( position.x, position.y, position.z );
+		var cmd = new CmdSetPosition( box, newPosition );
+		cmd.updatable = false;
+		editor.execute( cmd );
+
+	});
+
+	ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful" );
+	ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful" );
+	ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful" );
 
-	ok( mesh.position.x != initPosX, "OK, changing X position was successful" );
-	ok( mesh.position.y != initPosY, "OK, changing Y position was successful" );
-	ok( mesh.position.z != initPosZ, "OK, changing Z position was successful" );
 
 	editor.undo();
-	ok( mesh.position.x == initPosX, "OK, changing X position value is undone" );
-	ok( mesh.position.y == initPosY, "OK, changing Y position value is undone" );
-	ok( mesh.position.z == initPosZ, "OK, changing Z position value is undone" );
+	ok( box.position.x == positions[ positions.length - 2 ].x, "OK, changing X position was successful (after undo)" );
+	ok( box.position.y == positions[ positions.length - 2 ].y, "OK, changing Y position was successful (after undo)" );
+	ok( box.position.z == positions[ positions.length - 2 ].z, "OK, changing Z position was successful (after undo)" );
 
 	editor.redo();
-	ok( mesh.position.x == newPosX, "OK, changing X position value is redone" );
-	ok( mesh.position.y == newPosY, "OK, changing Y position value is redone" );
-	ok( mesh.position.z == newPosZ, "OK, changing Z position value is redone" );
+	ok( box.position.x == positions[ positions.length - 1 ].x, "OK, changing X position was successful (after redo)" );
+	ok( box.position.y == positions[ positions.length - 1 ].y, "OK, changing Y position was successful (after redo)" );
+	ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful (after redo)" );
+
 
 });

+ 31 - 24
test/unit/editor/TestCmdSetRotation.js

@@ -2,38 +2,45 @@ module( "CmdSetRotation" );
 
 test( "Test CmdSetRotation (Undo and Redo)", function() {
 
+	// setup
 	var editor = new Editor();
+	var box = aBox();
+	editor.execute( new CmdAddObject( box ) );
 
-	var mesh = aBox();
-	var initRotationX =  1.1 ;
-	var initRotationY =  0.4 ;
-	var initRotationZ = -2.0 ;
-	mesh.rotation.x = initRotationX ;
-	mesh.rotation.y = initRotationY ;
-	mesh.rotation.z = initRotationZ ;
 
-	editor.execute( new CmdAddObject( mesh ) );
-	editor.select( mesh );
+	var rotations = [
 
-	// rotate the object
-	var newRotationX =  -3.2 ;
-	var newRotationY =   0.8 ;
-	var newRotationZ =   1.5 ;
-	var newRotation = new THREE.Euler( newRotationX, newRotationY, newRotationZ );
-	editor.execute ( new CmdSetRotation( mesh, newRotation ) );
+		{ x: 1.1, y:  0.4, z: -2.0 },
+		{ x: 2.2, y: -1.3, z:  1.3 },
+		{ x: 0.3, y: -0.1, z: -1.9 }
 
-	ok( mesh.rotation.x != initRotationX, "OK, changing X rotation was successful" );
-	ok( mesh.rotation.y != initRotationY, "OK, changing Y rotation was successful" );
-	ok( mesh.rotation.z != initRotationZ, "OK, changing Z rotation was successful" );
+	];
+
+
+	rotations.map( function( rotation ) {
+
+		var newRotation = new THREE.Euler( rotation.x, rotation.y, rotation.z );
+		var cmd = new CmdSetRotation( box, newRotation );
+		cmd.updatable = false;
+		editor.execute ( cmd );
+
+	});
+
+
+	ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful" );
+	ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful" );
+	ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful" );
 
 	editor.undo();
-	ok( mesh.rotation.x == initRotationX, "OK, changing X rotation value is undone" );
-	ok( mesh.rotation.y == initRotationY, "OK, changing Y rotation value is undone" );
-	ok( mesh.rotation.z == initRotationZ, "OK, changing Z rotation value is undone" );
+	ok( box.rotation.x == rotations[ rotations.length - 2 ].x, "OK, changing X rotation was successful (after undo)" );
+	ok( box.rotation.y == rotations[ rotations.length - 2 ].y, "OK, changing Y rotation was successful (after undo)" );
+	ok( box.rotation.z == rotations[ rotations.length - 2 ].z, "OK, changing Z rotation was successful (after undo)" );
 
 	editor.redo();
-	ok( mesh.rotation.x == newRotationX, "OK, changing X rotation value is redone" );
-	ok( mesh.rotation.y == newRotationY, "OK, changing Y rotation value is redone" );
-	ok( mesh.rotation.z == newRotationZ, "OK, changing Z rotation value is redone" );
+	ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful (after redo)" );
+	ok( box.rotation.y == rotations[ rotations.length - 1 ].y, "OK, changing Y rotation was successful (after redo)" );
+	ok( box.rotation.z == rotations[ rotations.length - 1 ].z, "OK, changing Z rotation was successful (after redo)" );
+
+
 
 });

+ 32 - 24
test/unit/editor/TestCmdSetScale.js

@@ -2,38 +2,46 @@ module( "CmdSetScale" );
 
 test( "Test CmdSetScale (Undo and Redo)", function() {
 
+	// setup
 	var editor = new Editor();
+	var box = aBox();
+	editor.execute( new CmdAddObject( box ) );
 
-	var mesh = aBox();
-	var initScaleX =  1.4 ;
-	var initScaleY =  2.7 ;
-	var initScaleZ =  0.4 ;
-	mesh.scale.x = initScaleX ;
-	mesh.scale.y = initScaleY ;
-	mesh.scale.z = initScaleZ ;
 
-	editor.execute( new CmdAddObject( mesh ) );
-	editor.select( mesh );
+	// scales
+	var scales = [
 
-	// (re)scale the object
-	var newScaleX = 0.1 ;
-	var newScaleY = 5.3 ;
-	var newScaleZ = 1.0 ;
-	var newScale = new THREE.Vector3( newScaleX, newScaleY, newScaleZ );
-	editor.execute ( new CmdSetScale( mesh, newScale ) );
+		{ x: 1.4, y: 2.7, z: 0.4 },
+		{ x: 0.1, y: 1.3, z: 2.9 },
+		{ x: 3.2, y: 0.3, z: 2.0 }
+
+	];
+
+	scales.map( function( scale ) {
+
+		var newScale = new THREE.Vector3( scale.x, scale.y, scale.z );
+		var cmd = new CmdSetScale( box, newScale );
+		cmd.updatable = false;
+		editor.execute( cmd );
+
+
+	});
+
+	ok( box.scale.x == scales[ scales.length - 1 ].x, "OK, setting X scale value was successful" );
+	ok( box.scale.y == scales[ scales.length - 1 ].y, "OK, setting Y scale value was successful" );
+	ok( box.scale.z == scales[ scales.length - 1 ].z, "OK, setting Z scale value was successful" );
 
-	ok( mesh.scale.x != initScaleX, "OK, changing X scale was successful" );
-	ok( mesh.scale.y != initScaleY, "OK, changing Y scale was successful" );
-	ok( mesh.scale.z != initScaleZ, "OK, changing Z scale was successful" );
 
 	editor.undo();
-	ok( mesh.scale.x == initScaleX, "OK, changing X scale value is undone" );
-	ok( mesh.scale.y == initScaleY, "OK, changing Y scale value is undone" );
-	ok( mesh.scale.z == initScaleZ, "OK, changing Z scale value is undone" );
+	ok( box.scale.x == scales[ scales.length - 2 ].x, "OK, X scale is correct after undo" );
+	ok( box.scale.y == scales[ scales.length - 2 ].y, "OK, Y scale is correct after undo" );
+	ok( box.scale.z == scales[ scales.length - 2 ].z, "OK, Z scale is correct after undo" );
+
 
 	editor.redo();
-	ok( mesh.scale.x == newScaleX, "OK, changing X scale value is redone" );
-	ok( mesh.scale.y == newScaleY, "OK, changing Y scale value is redone" );
-	ok( mesh.scale.z == newScaleZ, "OK, changing Z scale value is redone" );
+	ok( box.scale.x == scales[ scales.length - 1 ].x, "OK, X scale is correct after redo" );
+	ok( box.scale.y == scales[ scales.length - 1 ].y, "OK, Y scale is correct after redo" );
+	ok( box.scale.z == scales[ scales.length - 1 ].z, "OK, Z scale is correct after redo" );
+
 
 });

+ 17 - 15
test/unit/editor/TestCmdSetUuid.js

@@ -3,28 +3,30 @@ module( "CmdSetUuid" );
 test( "Test CmdSetUuid (Undo and Redo)", function(){
 
 	var editor = new Editor();
-	var theName = "Initial name";
-	var object = aBox( theName );
+	var object = aBox( 'UUID test box' );
+	editor.execute( new CmdAddObject( object ) );
 
-	var uuidBefore = THREE.Math.generateUUID();
-	var uuidAfter  = THREE.Math.generateUUID();
 
-	editor.execute( new CmdAddObject( object ) );
+	var uuids = [ THREE.Math.generateUUID(), THREE.Math.generateUUID(), THREE.Math.generateUUID() ];
+
+	uuids.map( function( uuid ) {
 
-	var cmd = new CmdSetUuid( object, uuidBefore );
-	cmd.updatable = false;
-	editor.execute( cmd );
-	ok( object[ 'uuid' ] == uuidBefore, "OK, UUID is correct after first execute ");
+		var cmd = new CmdSetUuid( object, uuid );
+		cmd.updatable = false;
+		editor.execute( cmd );
 
-	var cmd = new CmdSetUuid( object, uuidAfter );
-	cmd.updatable = false;
-	editor.execute( cmd );
-	ok( object[ 'uuid' ] == uuidAfter, "OK, UUID is correct after second execute ");
+	});
+
+	ok( object.uuid == uuids[ uuids.length - 1 ],
+		"OK, UUID on actual object matches last UUID in the test data array " );
 
 	editor.undo();
-	ok( object[ 'uuid' ] == uuidBefore, "OK, UUID is correct after undo ");
+	ok( object.uuid == uuids[ uuids.length - 2 ],
+		"OK, UUID on actual object matches second to the last UUID in the test data array (after undo)" );
 
 	editor.redo();
-	ok( object[ 'uuid' ] == uuidAfter, "OK, UUID is correct after redo ");
+	ok( object.uuid == uuids[ uuids.length - 1 ],
+		"OK, UUID on actual object matches last UUID in the test data array again (after redo) " );
+
 
 });

+ 0 - 7
test/unit/editor/TestNestedDoUndoRedo.js

@@ -31,8 +31,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
 	// let's begin
 	editor.execute( new CmdAddObject( mesh ) );
 
-//	editor.execute( new CmdNameObject( editor, mesh, 'Nothing is as it was before' ) );
-
 	var newPos = new THREE.Vector3( initPosX + 100, initPosY, initPosZ );
 	editor.execute( new CmdSetPosition( mesh, newPos ) );
 
@@ -44,7 +42,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
 
 
 	/* full check */
-//	ok( mesh.name == "Nothing is as it was before", "OK, name is correct" );
 
 	ok( mesh.position.x ==   102, "OK, X position is correct " );
 	ok( mesh.position.y ==     3, "OK, Y position is correct " );
@@ -62,10 +59,8 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
 	editor.undo();  // rescaling undone
 	editor.undo();  // rotation undone
 	editor.undo();  // translation undone
-//	editor.undo();  // renaming undone
 
 	/* full check */
-//	ok( mesh.name == "One box unlike all others", "OK, name is correct" );
 
 	ok( mesh.position.x ==     2, "OK, X position is correct " );
 	ok( mesh.position.y ==     3, "OK, Y position is correct " );
@@ -80,7 +75,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
 	ok( mesh.scale.z    ==    24, "OK, Z scale is correct " );
 
 
-//	editor.redo();  // renaming redone
 	editor.redo();  // translation redone
 	editor.redo();  // rotation redone
 
@@ -94,7 +88,6 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
 	editor.undo();  // rotation undone (expected!)
 
 	/* full check */
-//	ok( mesh.name == "Nothing is as it was before", "OK, name is correct" );
 
 	ok( mesh.position.x ==   102, "OK, X position is correct " );
 	ok( mesh.position.y ==     3, "OK, Y position is correct " );

+ 1 - 1
test/unit/editor/TestSerialization.js

@@ -55,7 +55,7 @@ test( "Test Serialization (simple)", function() {
 
 	// Forward tests
 
-	for (var i = 0; i < setups.length ; i++ ) {
+	for ( var i = 0; i < setups.length ; i++ ) {
 
 		setups[i]();