提交 829b97d8 编写于 作者: M Mario Schuettel

formatted code according to mrdoob codestyle

上级 cd5d8ee6
......@@ -8,8 +8,10 @@ function mergeParams( defaults, customParams ) {
var params = {};
defaultKeys.map( function( key ) {
params[ key ] = customParams[ key ] || defaultKeys[ key ];
});
} );
return params;
......@@ -19,9 +21,11 @@ function mergeParams( defaults, customParams ) {
function getGeometryParams( type, customParams ) {
if ( typeof customParams != "undefined" &&
typeof customParams.geometry != "undefined" &&
typeof customParams.geometry.parameters != "undefined" ) {
typeof customParams.geometry != "undefined" &&
typeof customParams.geometry.parameters != "undefined" ) {
var customGeometryParams = customParams.geometry.parameters;
}
var defaults = {};
......@@ -58,24 +62,24 @@ function getGeometry( type, customParams ) {
case "BoxGeometry":
return new THREE.BoxGeometry(
params['width'],
params['height'],
params['depth'],
params['widthSegments'],
params['heightSegments'],
params['depthSegments']
params[ 'width' ],
params[ 'height' ],
params[ 'depth' ],
params[ 'widthSegments' ],
params[ 'heightSegments' ],
params[ 'depthSegments' ]
);
case "SphereGeometry":
return new THREE.SphereGeometry(
params['radius'],
params['widthSegments'],
params['heightSegments'],
params['phiStart'],
params['phiLength'],
params['thetaStart'],
params['thetaLength']
params[ 'radius' ],
params[ 'widthSegments' ],
params[ 'heightSegments' ],
params[ 'phiStart' ],
params[ 'phiLength' ],
params[ 'thetaStart' ],
params[ 'thetaLength' ]
);
default:
......@@ -102,6 +106,7 @@ function getObject( name, type, customParams ) {
function aBox( name, customParams ) {
return getObject( name, "BoxGeometry", customParams );
}
function aSphere( name, customParams ) {
......@@ -133,13 +138,14 @@ function getScriptCount( editor ) {
var scriptsKeys = Object.keys( editor.scripts );
var scriptCount = 0;
for ( var i = 0; i < scriptsKeys.length; i++ ) {
for ( var i = 0; i < scriptsKeys.length; i ++ ) {
scriptCount += editor.scripts[ scriptsKeys[i] ].length;
scriptCount += editor.scripts[ scriptsKeys[ i ] ].length;
}
return scriptCount;
}
function exportScene( editor ) {
......@@ -159,4 +165,4 @@ function importScene( data ) {
return result;
}
\ No newline at end of file
}
......@@ -24,7 +24,7 @@ test( "Test CmdAddObject and CmdRemoveObject (Undo and Redo)", function() {
ok( editor.scene.children.length == 0, "OK, adding '" + object.type + "' is undone (was removed)" );
editor.redo();
ok( editor.scene.children[ 0 ].name == object.name , "OK, removed '" + object.type + "' was added again (redo)" );
ok( editor.scene.children[ 0 ].name == object.name, "OK, removed '" + object.type + "' was added again (redo)" );
// Test Remove
......@@ -35,13 +35,13 @@ test( "Test CmdAddObject and CmdRemoveObject (Undo and Redo)", function() {
ok( editor.scene.children.length == 0, "OK, removing object was successful" );
editor.undo();
ok( editor.scene.children[ 0 ].name == object.name , "OK, removed object was added again (undo)" );
ok( editor.scene.children[ 0 ].name == object.name, "OK, removed object was added again (undo)" );
editor.redo();
ok( editor.scene.children.length == 0, "OK, object was removed again (redo)" );
});
} );
});
\ No newline at end of file
} );
module("CmdAddScript");
module( "CmdAddScript" );
test( "Test CmdAddScript (Undo and Redo)" , function() {
test( "Test CmdAddScript (Undo and Redo)", function() {
var editor = new Editor();
......@@ -15,14 +15,16 @@ test( "Test CmdAddScript (Undo and Redo)" , function() {
// add objects to editor
objects.map( function( item ) {
editor.execute( new CmdAddObject( item ) );
});
} );
ok( editor.scene.children.length == 2, "OK, the box and the sphere have been added" );
// add scripts to the objects
for ( var i = 0; i < scripts.length; i++ ) {
for ( var i = 0; i < scripts.length; i ++ ) {
var cmd = new CmdAddScript( objects[i], scripts[i] );
var cmd = new CmdAddScript( objects[ i ], scripts[ i ] );
cmd.updatable = false;
editor.execute( cmd );
......@@ -31,9 +33,9 @@ test( "Test CmdAddScript (Undo and Redo)" , function() {
var scriptsKeys = Object.keys( editor.scripts );
ok( getScriptCount( editor ) == scripts.length, "OK, correct number of scripts have been added" );
for ( var i = 0; i < objects.length; i++ ) {
for ( var i = 0; i < objects.length; i ++ ) {
ok( objects[i].uuid == scriptsKeys[i], "OK, script key #" + i + " matches the object's UUID" );
ok( objects[ i ].uuid == scriptsKeys[ i ], "OK, script key #" + i + " matches the object's UUID" );
}
......@@ -44,11 +46,12 @@ test( "Test CmdAddScript (Undo and Redo)" , function() {
ok( getScriptCount( editor ) == scripts.length, "OK, one script has been added again by redo" );
for (var i = 0; i < scriptsKeys.length; i++ ) {
for ( var i = 0; i < scriptsKeys.length; i ++ ) {
ok( editor.scripts[ scriptsKeys[i] ][0] == scripts[i], "OK, script #" + i + " is still assigned correctly" );
ok( editor.scripts[ scriptsKeys[ i ] ][ 0 ] == scripts[ i ], "OK, script #" + i + " is still assigned correctly" );
}
});
\ No newline at end of file
} );
......@@ -14,24 +14,24 @@ test( "Test CmdMoveObject (Undo and Redo)", function() {
editor.execute( new CmdAddObject( lukeSkywalker ) );
ok( anakinSkywalker.parent.name == "Scene", "OK, Anakin's parent is 'Scene' ");
ok( lukeSkywalker.parent.name == "Scene", "OK, Luke's parent is 'Scene' ");
ok( anakinSkywalker.parent.name == "Scene", "OK, Anakin's parent is 'Scene' " );
ok( lukeSkywalker.parent.name == "Scene", "OK, Luke's parent is 'Scene' " );
// Tell Luke, Anakin is his father
editor.execute( new CmdMoveObject( lukeSkywalker, anakinSkywalker ) );
ok( true === true, "(Luke has been told who his father is)");
ok( anakinSkywalker.parent.name == "Scene" , "OK, Anakin's parent is still 'Scene' ");
ok( lukeSkywalker.parent.name == anakinsName, "OK, Luke's parent is '" + anakinsName + "' ");
ok( true === true, "(Luke has been told who his father is)" );
ok( anakinSkywalker.parent.name == "Scene", "OK, Anakin's parent is still 'Scene' " );
ok( lukeSkywalker.parent.name == anakinsName, "OK, Luke's parent is '" + anakinsName + "' " );
editor.undo();
ok( true === true, "(Statement undone)");
ok( anakinSkywalker.parent.name == "Scene", "OK, Anakin's parent is still 'Scene' ");
ok( lukeSkywalker.parent.name == "Scene", "OK, Luke's parent is 'Scene' again ");
ok( true === true, "(Statement undone)" );
ok( anakinSkywalker.parent.name == "Scene", "OK, Anakin's parent is still 'Scene' " );
ok( lukeSkywalker.parent.name == "Scene", "OK, Luke's parent is 'Scene' again " );
editor.redo();
ok( true === true, "(Statement redone)");
ok( anakinSkywalker.parent.name == "Scene" , "OK, Anakin's parent is still 'Scene' ");
ok( lukeSkywalker.parent.name == anakinsName, "OK, Luke's parent is '" + anakinsName + "' again ");
ok( true === true, "(Statement redone)" );
ok( anakinSkywalker.parent.name == "Scene", "OK, Anakin's parent is still 'Scene' " );
ok( lukeSkywalker.parent.name == anakinsName, "OK, Luke's parent is '" + anakinsName + "' again " );
});
\ No newline at end of file
} );
......@@ -14,14 +14,19 @@ test( "Test CmdMultiCmds (Undo and Redo)", function() {
// setup first multi commands
var firstMultiCmds = [
new CmdSetGeometry( box, boxGeometries[0] ),
new CmdSetGeometry( box, boxGeometries[ 0 ] ),
new CmdSetPosition( box, new THREE.Vector3( 1, 2, 3 ) ),
new CmdSetRotation( box, new THREE.Euler( 0.1, 0.2, 0.2 ) ),
new CmdSetScale( box, new THREE.Vector3( 1.1, 1.2, 1.3 ) )
];
firstMultiCmds.map( function( cmd ) {
cmd.updatable = false;
});
} );
var firstMultiCmd = new CmdMultiCmds( firstMultiCmds );
firstMultiCmd.updatable = false;
......@@ -30,14 +35,19 @@ test( "Test CmdMultiCmds (Undo and Redo)", function() {
// setup second multi commands
var secondMultiCmds = [
new CmdSetGeometry( box, boxGeometries[1] ),
new CmdSetGeometry( box, boxGeometries[ 1 ] ),
new CmdSetPosition( box, new THREE.Vector3( 4, 5, 6 ) ),
new CmdSetRotation( box, new THREE.Euler( 0.4, 0.5, 0.6 ) ),
new CmdSetScale( box, new THREE.Vector3( 1.4, 1.5, 1.6 ) )
];
secondMultiCmds.map( function( cmd ) {
cmd.updatable = false;
});
} );
var secondMultiCmd = new CmdMultiCmds( secondMultiCmds );
secondMultiCmd.updatable = false;
......@@ -62,4 +72,4 @@ test( "Test CmdMultiCmds (Undo and Redo)", function() {
ok( box.rotation.x == 0.4, "OK, x rotation has been modified accordingly after two multi executes (expected: 0.4, actual: " + box.rotation.x + ") " );
ok( box.scale.z == 1.6, "OK, z scale has been modified accordingly after two multi executes (expected: 1.6, actual: " + box.scale.z + ")" );
});
\ No newline at end of file
} );
module("CmdRemoveScript");
module( "CmdRemoveScript" );
test( "Test CmdRemoveScript (Undo and Redo)", function() {
......@@ -15,22 +15,24 @@ test( "Test CmdRemoveScript (Undo and Redo)", function() {
// add objects to editor
objects.map( function( item ) {
editor.execute( new CmdAddObject( item ) );
});
} );
ok( editor.scene.children.length == 2, "OK, the box and the sphere have been added" );
// add scripts to the objects
for ( var i = 0; i < scripts.length; i++ ) {
for ( var i = 0; i < scripts.length; i ++ ) {
var cmd = new CmdAddScript( objects[i], scripts[i] );
var cmd = new CmdAddScript( objects[ i ], scripts[ i ] );
cmd.updatable = false;
editor.execute( cmd );
}
for ( var i = 0; i < scripts.length; i++ ) {
for ( var i = 0; i < scripts.length; i ++ ) {
var cmd = new CmdRemoveScript( objects[i], scripts[i] );
var cmd = new CmdRemoveScript( objects[ i ], scripts[ i ] );
cmd.updatable = false;
editor.execute( cmd );
......@@ -38,18 +40,20 @@ test( "Test CmdRemoveScript (Undo and Redo)", function() {
ok( getScriptCount( editor ) == 0, "OK, all scripts have been removed" );
scripts.map( function() {
editor.undo();
});
} );
ok( getScriptCount( editor ) == scripts.length, "OK, all scripts have been added again by undo(s)" );
var scriptsKeys = Object.keys( editor.scripts );
for (var i = 0; i < scriptsKeys.length; i++ ) {
for ( var i = 0; i < scriptsKeys.length; i ++ ) {
ok( editor.scripts[ scriptsKeys[i] ][0] == scripts[i], "OK, script #" + i + " is still assigned correctly" );
ok( editor.scripts[ scriptsKeys[ i ] ][ 0 ] == scripts[ i ], "OK, script #" + i + " is still assigned correctly" );
}
editor.redo();
ok( getScriptCount( editor ) == scripts.length - 1, "OK, one script has been removed again by redo" );
});
\ No newline at end of file
} );
module( "CmdSetColor" );
test("Test CmdSetColor (Undo and Redo)", function() {
test( "Test CmdSetColor (Undo and Redo)", function() {
var editor = new Editor();
var pointLight = aPointlight( "The light Light" );
......@@ -18,7 +18,7 @@ test("Test CmdSetColor (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
ok( pointLight.color.getHex() == colors[ colors.length - 1 ],
"OK, color has been set successfully (expected: '" + colors[ colors.length - 1 ] + "', actual: '" + pointLight.color.getHex() + "')" );
......@@ -32,4 +32,4 @@ test("Test CmdSetColor (Undo and Redo)", function() {
"OK, color has been set successfully after redo (expected: '" + colors[ colors.length - 1 ] + "', actual: '" + pointLight.color.getHex() + "')" );
});
\ No newline at end of file
} );
......@@ -16,7 +16,7 @@ test( "Test CmdSetGeometry (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
for ( var i = 0; i < geometryParams.length; i++ ) {
for ( var i = 0; i < geometryParams.length; i ++ ) {
var cmd = new CmdSetGeometry( box, getGeometry( "BoxGeometry", geometryParams[ i ] ) );
cmd.updatable = false;
......@@ -37,22 +37,22 @@ test( "Test CmdSetGeometry (Undo and Redo)", function() {
editor.undo();
var actualParams = box.geometry.parameters;
var expectedParams = geometryParams[ 0 ].geometry.parameters;
ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry1 (after undo)");
ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry1 (after undo)");
ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry1 (after undo)");
ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry1 (after undo)");
ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry1 (after undo)");
ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry1 (after undo)");
ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry1 (after undo)" );
ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry1 (after undo)" );
ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry1 (after undo)" );
ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry1 (after undo)" );
ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry1 (after undo)" );
ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry1 (after undo)" );
editor.redo();
var actualParams = box.geometry.parameters;
var expectedParams = geometryParams[ 1 ].geometry.parameters;
ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry2 (after redo)");
ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry2 (after redo)");
ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry2 (after redo)");
ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry2 (after redo)");
ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry2 (after redo)");
ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry2 (after redo)");
ok( actualParams.width == expectedParams.width, "OK, box width matches the corresponding value from boxGeometry2 (after redo)" );
ok( actualParams.height == expectedParams.height, "OK, box height matches the corresponding value from boxGeometry2 (after redo)" );
ok( actualParams.depth == expectedParams.depth, "OK, box depth matches the corresponding value from boxGeometry2 (after redo)" );
ok( actualParams.widthSegments == expectedParams.widthSegments, "OK, box widthSegments matches the corresponding value from boxGeometry2 (after redo)" );
ok( actualParams.heightSegments == expectedParams.heightSegments, "OK, box heightSegments matches the corresponding value from boxGeometry2 (after redo)" );
ok( actualParams.depthSegments == expectedParams.depthSegments, "OK, box depthSegments matches the corresponding value from boxGeometry2 (after redo)" );
});
\ No newline at end of file
} );
......@@ -14,7 +14,7 @@ test( "Test CmdSetGeometryValue (Undo and Redo)", function() {
{ uuid: THREE.Math.generateUUID(), name: 'Jack' }
];
for( var i = 0; i < testData.length; i++ ) {
for ( var i = 0; i < testData.length; i ++ ) {
var keys = Object.keys( testData[ i ] );
......@@ -24,7 +24,7 @@ test( "Test CmdSetGeometryValue (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
}
......@@ -43,4 +43,4 @@ test( "Test CmdSetGeometryValue (Undo and Redo)", function() {
ok( box.geometry.name == testData[ 1 ].name, "OK, box.geometry.name is correct after executes" );
ok( box.geometry.uuid == testData[ 1 ].uuid, "OK, box.geometry.uuid is correct after executes" );
});
\ No newline at end of file
} );
module("CmdSetMaterial");
module( "CmdSetMaterial" );
test( "Test for CmdSetMaterial (Undo and Redo)", function() {
......@@ -10,6 +10,7 @@ test( "Test for CmdSetMaterial (Undo and Redo)", function() {
editor.execute( cmd );
materialClasses = [
'LineBasicMaterial',
'LineDashedMaterial',
'MeshBasicMaterial',
......@@ -19,6 +20,7 @@ test( "Test for CmdSetMaterial (Undo and Redo)", function() {
'MeshPhongMaterial',
'ShaderMaterial',
'SpriteMaterial'
];
materialClasses.map( function( materialClass ) {
......@@ -26,7 +28,7 @@ test( "Test for CmdSetMaterial (Undo and Redo)", function() {
material = new THREE[ materialClass ]();
editor.execute( new CmdSetMaterial( box, material ) );
});
} );
var i = materialClasses.length - 1;
......@@ -37,23 +39,23 @@ test( "Test for CmdSetMaterial (Undo and Redo)", function() {
// test undos
while( i > 0 ) {
while ( i > 0 ) {
editor.undo();
--i;
-- i;
ok( box.material.type == materialClasses[ i ],
"OK, material type was set correctly after undo (expected: '" + materialClasses[ i ] + "', actual: '" + box.material.type + "')" );
}
// test redos
while( i < materialClasses.length - 1 ) {
while ( i < materialClasses.length - 1 ) {
editor.redo();
++i;
++ i;
ok( box.material.type == materialClasses[ i ],
"OK, material type was set correctly after redo (expected: '" + materialClasses[ i ] + "', actual: '" + box.material.type + "')" );
}
});
\ No newline at end of file
} );
module("CmdSetMaterialColor");
module( "CmdSetMaterialColor" );
test("Test for CmdSetMaterialColor (Undo and Redo)", function() {
test( "Test for CmdSetMaterialColor (Undo and Redo)", function() {
// Setup scene
var editor = new Editor();
......@@ -24,17 +24,17 @@ test("Test for CmdSetMaterialColor (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
ok( box.material[ attributeName ].getHex() == colors[ colors.length - 1 ], "OK, " + attributeName + " was set correctly to last color " );
editor.undo();
ok( box.material[ attributeName ].getHex() == colors[ colors.length - 2 ], "OK, " + attributeName + " is set correctly to second to last color after undo");
ok( box.material[ attributeName ].getHex() == colors[ colors.length - 2 ], "OK, " + attributeName + " is set correctly to second to last color after undo" );
editor.redo();
ok( box.material[ attributeName ].getHex() == colors[ colors.length - 1 ], "OK, " + attributeName + " is set correctly to last color after redo");
ok( box.material[ attributeName ].getHex() == colors[ colors.length - 1 ], "OK, " + attributeName + " is set correctly to last color after redo" );
});
} );
});
\ No newline at end of file
} );
module("CmdSetMaterialMap");
module( "CmdSetMaterialMap" );
test( "Test for CmdSetMaterialMap (Undo and Redo)", function() {
......@@ -18,10 +18,12 @@ test( "Test for CmdSetMaterialMap (Undo and Redo)", function() {
// define images for given files
var images = files.map( function( file ) {
var i = new Image();
i.src = file.data;
return { name: file.name, image: i };
});
} );
// test all maps
......@@ -30,10 +32,12 @@ test( "Test for CmdSetMaterialMap (Undo and Redo)", function() {
// define textures for given images
var textures = images.map( function( img ) {
var texture = new THREE.Texture( img.image, mapName );
texture.sourceFile = img.name;
return texture;
});
} );
// apply the textures
textures.map( function( texture ) {
......@@ -42,7 +46,7 @@ test( "Test for CmdSetMaterialMap (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
ok( box.material[ mapName ].image.src == images[ images.length - 1 ].image.src,
......@@ -56,6 +60,6 @@ test( "Test for CmdSetMaterialMap (Undo and Redo)", function() {
ok( box.material[ mapName ].image.src == images[ images.length - 1 ].image.src,
"OK, " + mapName + " set correctly after redo" );
});
} );
});
\ No newline at end of file
} );
module("CmdSetMaterialValue");
module( "CmdSetMaterialValue" );
test( "Test for CmdSetMaterialValue (Undo and Redo)", function() {
......@@ -11,12 +11,13 @@ test( "Test for CmdSetMaterialValue (Undo and Redo)", function() {
// every attribute gets three test values
var testData = {
uuid: [ THREE.Math.generateUUID(), THREE.Math.generateUUID(), THREE.Math.generateUUID() ],
name: [ 'Alpha', 'Bravo', 'Charlie' ],
shininess: [ 11.1, 22.2, 33.3 ],
vertexColors: [ 'No', 'Face', 'Vertex' ],
bumpScale: [ 1.1, 2.2, 3.3 ],
reflectivity: [ -1.3, 2.1, 5.0 ],
reflectivity: [ - 1.3, 2.1, 5.0 ],
aoMapIntensity: [ 0.1, 0.4, 0.7 ],
side: [ 'Front', 'Back', 'Double' ],
shading: [ 'No', 'Flat', 'Smooth' ],
......@@ -24,6 +25,7 @@ test( "Test for CmdSetMaterialValue (Undo and Redo)", function() {
opacity: [ 0.2, 0.5, 0.8 ],
alphaTest: [ 0.1, 0.6, 0.9 ],
wirefrimeLinewidth: [ 1.2, 3.4, 5.6 ]
};
var testDataKeys = Object.keys( testData );
......@@ -36,21 +38,21 @@ test( "Test for CmdSetMaterialValue (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
var length = testData[ attributeName].length;
var length = testData[ attributeName ].length;
ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
"OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')");
"OK, " + attributeName + " was set correctly to the last value (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
editor.undo();
ok( box.material[ attributeName ] == testData[ attributeName ][ length - 2 ],
"OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')");
"OK, " + attributeName + " was set correctly to the second to the last value after undo (expected: '" + testData[ attributeName ][ length - 2 ] + "', actual: '" + box.material[ attributeName ] + "')" );
editor.redo();
ok( box.material[ attributeName ] == testData[ attributeName ][ length - 1 ],
"OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')");
"OK, " + attributeName + " was set correctly to the last value again after redo (expected: '" + testData[ attributeName ][ length - 1 ] + "', actual: '" + box.material[ attributeName ] + "')" );
});
} );
});
\ No newline at end of file
} );
......@@ -9,9 +9,9 @@ test( "Test CmdSetPosition (Undo and Redo)", function() {
var positions = [
{ x: 50, y: -80, z: 30 },
{ x: -10, y: 100, z: 0 },
{ x: 44, y: -20, z: 90 }
{ x: 50, y: - 80, z: 30 },
{ x: - 10, y: 100, z: 0 },
{ x: 44, y: - 20, z: 90 }
];
......@@ -22,7 +22,7 @@ test( "Test CmdSetPosition (Undo and Redo)", function() {
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" );
......@@ -40,4 +40,4 @@ test( "Test CmdSetPosition (Undo and Redo)", function() {
ok( box.position.z == positions[ positions.length - 1 ].z, "OK, changing Z position was successful (after redo)" );
});
\ No newline at end of file
} );
......@@ -10,9 +10,9 @@ test( "Test CmdSetRotation (Undo and Redo)", function() {
var rotations = [
{ 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 }
{ 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 }
];
......@@ -24,7 +24,7 @@ test( "Test CmdSetRotation (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute ( cmd );
});
} );
ok( box.rotation.x == rotations[ rotations.length - 1 ].x, "OK, changing X rotation was successful" );
......@@ -43,4 +43,4 @@ test( "Test CmdSetRotation (Undo and Redo)", function() {
});
\ No newline at end of file
} );
......@@ -24,8 +24,7 @@ test( "Test CmdSetScale (Undo and Redo)", function() {
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" );
......@@ -44,4 +43,4 @@ test( "Test CmdSetScale (Undo and Redo)", function() {
ok( box.scale.z == scales[ scales.length - 1 ].z, "OK, Z scale is correct after redo" );
});
\ No newline at end of file
} );
module("TestCmdSetScene");
module( "TestCmdSetScene" );
test("Test for CmdSetScene (Undo and Redo)", function() {
test( "Test for CmdSetScene (Undo and Redo)", function() {
// setup
var editor = new Editor();
......@@ -16,7 +16,7 @@ test("Test for CmdSetScene (Undo and Redo)", function() {
editor.execute( cmd );
return { obj: object, exportedData: exportScene( editor ) };
});
} );
// create new empty editor (scene), merge the other editors (scenes)
......@@ -28,41 +28,41 @@ test("Test for CmdSetScene (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
// tests
ok( editor.scene.children.length = scenes.length,
"OK, all scenes have been merged");
"OK, all scenes have been merged" );
var i = 0;
while( i < editor.scene.children.length ) {
while ( i < editor.scene.children.length ) {
ok( editor.scene.children[ i ].name == scenes[ i ].obj.name,
"OK, editor.scene.children[ " + i + " ].name matches scenes[ " + i + " ].obj.name");
i++;
"OK, editor.scene.children[ " + i + " ].name matches scenes[ " + i + " ].obj.name" );
i ++;
}
editor.undo();
var i = 0;
while( i < editor.scene.children.length ) {
while ( i < editor.scene.children.length ) {
ok( editor.scene.children[ i ].name == scenes[ i ].obj.name,
"OK, editor.scene.children[ " + i + " ].name matches scenes[ " + i + " ].obj.name after undo");
i++;
"OK, editor.scene.children[ " + i + " ].name matches scenes[ " + i + " ].obj.name after undo" );
i ++;
}
editor.redo();
var i = 0;
while( i < editor.scene.children.length ) {
while ( i < editor.scene.children.length ) {
ok( editor.scene.children[ i ].name == scenes[ i ].obj.name,
"OK, editor.scene.children[ " + i + " ].name matches scenes[ " + i + " ].obj.name after redo");
i++;
"OK, editor.scene.children[ " + i + " ].name matches scenes[ " + i + " ].obj.name after redo" );
i ++;
}
});
\ No newline at end of file
} );
......@@ -29,28 +29,25 @@ test( "Test CmdSetScriptValue for source (Undo and Redo)", function() {
testSourceData.map( function( script ) {
var cmd = new CmdSetScriptValue( box, translateScript, 'source', script.source , 0 );
var cmd = new CmdSetScriptValue( box, translateScript, 'source', script.source, 0 );
cmd.updatable = false;
editor.execute( cmd );
});
} );
var length = testSourceData.length;
ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1].source,
"OK, 'source' was set correctly to the last value (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
ok( editor.scripts[ box.uuid ][ 0 ][ 'source' ] == testSourceData[ length - 1 ].source,
"OK, 'source' was set correctly to the last value (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][ 0 ][ 'source' ] + "')" );
editor.undo();
ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 2 ].source,
"OK, 'source' was set correctly to the second to the last value after undo (expected: '" + testSourceData[ length - 2 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
ok( editor.scripts[ box.uuid ][ 0 ][ 'source' ] == testSourceData[ length - 2 ].source,
"OK, 'source' was set correctly to the second to the last value after undo (expected: '" + testSourceData[ length - 2 ].source + "', actual: '" + editor.scripts[ box.uuid ][ 0 ][ 'source' ] + "')" );
editor.redo();
ok( editor.scripts[ box.uuid ][0][ 'source' ] == testSourceData[ length - 1 ].source,
"OK, 'source' was set correctly to the last value again after redo (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][0][ 'source' ] + "')");
ok( editor.scripts[ box.uuid ][ 0 ][ 'source' ] == testSourceData[ length - 1 ].source,
"OK, 'source' was set correctly to the last value again after redo (expected: '" + testSourceData[ length - 1 ].source + "', actual: '" + editor.scripts[ box.uuid ][ 0 ][ 'source' ] + "')" );
// test name
var names = [ "X Script", "Y Script", "Z Script" ];
names.map( function( name ) {
......@@ -59,17 +56,17 @@ test( "Test CmdSetScriptValue for source (Undo and Redo)", function() {
cmd.updatable = false;
editor.execute( cmd );
});
} );
var scriptName = editor.scripts[ box.uuid ][0][ "name" ];
var scriptName = editor.scripts[ box.uuid ][ 0 ][ "name" ];
ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned" );
editor.undo();
scriptName = editor.scripts[ box.uuid ][0][ "name" ];
scriptName = editor.scripts[ box.uuid ][ 0 ][ "name" ];
ok( scriptName == names[ names.length - 2 ], "OK, the script name corresponds to the second last script name that was assigned" );
editor.redo();
scriptName = editor.scripts[ box.uuid ][0][ "name" ];
scriptName = editor.scripts[ box.uuid ][ 0 ][ "name" ];
ok( scriptName == names[ names.length - 1 ], "OK, the script name corresponds to the last script name that was assigned, again" );
});
\ No newline at end of file
} );
module( "CmdSetUuid" );
test( "Test CmdSetUuid (Undo and Redo)", function(){
test( "Test CmdSetUuid (Undo and Redo)", function() {
var editor = new Editor();
var object = aBox( 'UUID test box' );
......@@ -15,7 +15,7 @@ test( "Test CmdSetUuid (Undo and Redo)", function(){
cmd.updatable = false;
editor.execute( cmd );
});
} );
ok( object.uuid == uuids[ uuids.length - 1 ],
"OK, UUID on actual object matches last UUID in the test data array " );
......@@ -29,4 +29,4 @@ test( "Test CmdSetUuid (Undo and Redo)", function(){
"OK, UUID on actual object matches last UUID in the test data array again (after redo) " );
});
\ No newline at end of file
} );
module( "CmdSetValue" );
test( "Test CmdSetValue (Undo and Redo)", function(){
test( "Test CmdSetValue (Undo and Redo)", function() {
var editor = new Editor();
......@@ -15,35 +15,35 @@ test( "Test CmdSetValue (Undo and Redo)", function(){
editor.execute( new CmdAddObject( object ) );
ok( 0 == 0, "Testing object of type '" + object.type + "'");
ok( 0 == 0, "Testing object of type '" + object.type + "'" );
[ 'name', 'fov', 'near', 'far', 'intensity', 'distance', 'angle', 'exponent', 'decay', 'visible', 'userData' ].map( function( item ) {
if( object[ item ] !== undefined ) {
if ( object[ item ] !== undefined ) {
var cmd = new CmdSetValue( object, item, valueBefore );
cmd.updatable = false;
editor.execute( cmd );
ok( object[ item ] == valueBefore, " OK, the attribute '" + item + "' is correct after first execute (expected: '" + valueBefore + "', actual: '" + object[ item ] + "')");
ok( object[ item ] == valueBefore, " OK, the attribute '" + item + "' is correct after first execute (expected: '" + valueBefore + "', actual: '" + object[ item ] + "')" );
var cmd = new CmdSetValue( object, item, valueAfter );
cmd.updatable = false;
editor.execute( cmd );
ok( object[ item ] == valueAfter , " OK, the attribute '" + item + "' is correct after second execute (expected: '" + valueAfter + "', actual: '" + object[ item ] + "')");
ok( object[ item ] == valueAfter, " OK, the attribute '" + item + "' is correct after second execute (expected: '" + valueAfter + "', actual: '" + object[ item ] + "')" );
editor.undo();
ok( object[ item ] == valueBefore, " OK, the attribute '" + item + "' is correct after undo (expected: '" + valueBefore + "', actual: '" + object[ item ] + "')");
ok( object[ item ] == valueBefore, " OK, the attribute '" + item + "' is correct after undo (expected: '" + valueBefore + "', actual: '" + object[ item ] + "')" );
editor.redo();
ok( object[ item ] == valueAfter , " OK, the attribute '" + item + "' is correct after redo (expected: '" + valueAfter + "', actual: '" + object[ item ] + "')");
ok( object[ item ] == valueAfter, " OK, the attribute '" + item + "' is correct after redo (expected: '" + valueAfter + "', actual: '" + object[ item ] + "')" );
}
});
} );
});
} );
});
\ No newline at end of file
} );
module("MassUndoAndRedo");
module( "MassUndoAndRedo" );
test( "MassUndoAndRedo (stress test)", function() {
......@@ -8,14 +8,14 @@ test( "MassUndoAndRedo (stress test)", function() {
// add objects
var i = 0;
while( i < MAX_OBJECTS ) {
while ( i < MAX_OBJECTS ) {
var object = aSphere( 'Sphere #' + i );
var cmd = new CmdAddObject( object );
cmd.updatable = false;
editor.execute( cmd );
i++;
i ++;
}
......@@ -24,10 +24,10 @@ test( "MassUndoAndRedo (stress test)", function() {
// remove all objects
i = 0;
while( i < MAX_OBJECTS ) {
while ( i < MAX_OBJECTS ) {
editor.undo();
i++;
i ++;
}
......@@ -37,13 +37,14 @@ test( "MassUndoAndRedo (stress test)", function() {
i = 0;
while( i < MAX_OBJECTS ) {
while ( i < MAX_OBJECTS ) {
editor.redo();
i++;
i ++;
}
ok( editor.scene.children.lenght = MAX_OBJECTS,
"OK, " + MAX_OBJECTS + " objects have been added again by redos" );
});
\ No newline at end of file
} );
module("NegativeCases");
module( "NegativeCases" );
test( "Test unwanted situations ", function() {
......@@ -6,13 +6,13 @@ test( "Test unwanted situations ", function() {
// illegal
editor.undo();
ok( editor.history.undos.length == 0, "OK, (illegal) undo did not affect the undo history");
ok( editor.history.redos.length == 0, "OK, (illegal) undo did not affect the redo history");
ok( editor.history.undos.length == 0, "OK, (illegal) undo did not affect the undo history" );
ok( editor.history.redos.length == 0, "OK, (illegal) undo did not affect the redo history" );
// illegal
editor.redo();
ok( editor.history.undos.length == 0, "OK, (illegal) redo did not affect the undo history");
ok( editor.history.redos.length == 0, "OK, (illegal) redo did not affect the redo history");
ok( editor.history.undos.length == 0, "OK, (illegal) redo did not affect the undo history" );
ok( editor.history.redos.length == 0, "OK, (illegal) redo did not affect the redo history" );
var box = aBox();
......@@ -20,31 +20,31 @@ test( "Test unwanted situations ", function() {
cmd.updatable = false;
editor.execute( cmd );
ok( editor.history.undos.length == 1, "OK, execute changed undo history");
ok( editor.history.redos.length == 0, "OK, execute did not change redo history");
ok( editor.history.undos.length == 1, "OK, execute changed undo history" );
ok( editor.history.redos.length == 0, "OK, execute did not change redo history" );
// illegal
editor.redo();
ok( editor.history.undos.length == 1, "OK, (illegal) redo did not affect the undo history");
ok( editor.history.redos.length == 0, "OK, (illegal) redo did not affect the redo history");
ok( editor.history.undos.length == 1, "OK, (illegal) redo did not affect the undo history" );
ok( editor.history.redos.length == 0, "OK, (illegal) redo did not affect the redo history" );
editor.undo();
ok( editor.history.undos.length == 0, "OK, undo changed the undo history");
ok( editor.history.redos.length == 1, "OK, undo changed the redo history");
ok( editor.history.undos.length == 0, "OK, undo changed the undo history" );
ok( editor.history.redos.length == 1, "OK, undo changed the redo history" );
// illegal
editor.undo();
ok( editor.history.undos.length == 0, "OK, (illegal) undo did not affect the undo history");
ok( editor.history.redos.length == 1, "OK, (illegal) undo did not affect the redo history");
ok( editor.history.undos.length == 0, "OK, (illegal) undo did not affect the undo history" );
ok( editor.history.redos.length == 1, "OK, (illegal) undo did not affect the redo history" );
editor.redo();
ok( editor.history.undos.length == 1, "OK, redo changed the undo history");
ok( editor.history.redos.length == 0, "OK, undo changed the redo history");
ok( editor.history.undos.length == 1, "OK, redo changed the undo history" );
ok( editor.history.redos.length == 0, "OK, undo changed the redo history" );
// illegal
editor.redo();
ok( editor.history.undos.length == 1, "OK, (illegal) did not affect the undo history");
ok( editor.history.redos.length == 0, "OK, (illegal) did not affect the redo history");
ok( editor.history.undos.length == 1, "OK, (illegal) did not affect the undo history" );
ok( editor.history.redos.length == 0, "OK, (illegal) did not affect the redo history" );
});
\ No newline at end of file
} );
module( "NestedDoUndoRedo" );
test( "Test nested Do's, Undo's and Redo's ", function() {
// TODO: replace CmdNameObject by CmdSetValue
test( "Test nested Do's, Undo's and Redo's", function() {
var editor = new Editor();
......@@ -102,4 +100,4 @@ test( "Test nested Do's, Undo's and Redo's ", function() {
ok( mesh.scale.z == 24, "OK, Z scale is correct " );
});
\ No newline at end of file
} );
......@@ -26,6 +26,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "addObject";
};
var addScript = function () {
......@@ -38,7 +39,7 @@ test( "Test Serialization", function( assert ) {
var cmd = new CmdAddObject( box );
editor.execute( cmd );
var cmd = new CmdAddScript( box, { "name":"test","source":"console.log(\"hello world\");" } );
var cmd = new CmdAddScript( box, { "name": "test", "source": "console.log(\"hello world\");" } );
cmd.updatable = false;
editor.execute( cmd );
......@@ -62,6 +63,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( new CmdMoveObject( lukeSkywalker, anakinSkywalker ) );
return "moveObject";
};
var removeScript = function () {
......@@ -69,7 +71,7 @@ test( "Test Serialization", function( assert ) {
var box = aBox( 'Box with no script' );
editor.execute( new CmdAddObject( box ) );
var script = { "name":"test","source":"console.log(\"hello world\");" } ;
var script = { "name": "test", "source": "console.log(\"hello world\");" } ;
var cmd = new CmdAddScript( box, script );
cmd.updatable = false;
......@@ -79,6 +81,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "removeScript";
};
var setColor = function () {
......@@ -91,6 +94,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setColor";
};
var setGeometry = function () {
......@@ -105,6 +109,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setGeometry";
};
var setGeometryValue = function() {
......@@ -117,6 +122,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setGeometryValue";
};
var setMaterial = function () {
......@@ -130,6 +136,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setMaterial";
};
var setMaterialColor = function () {
......@@ -142,6 +149,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setMaterialColor";
};
var setMaterialMap = function () {
......@@ -162,6 +170,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setMaterialMap";
};
var setMaterialValue = function () {
......@@ -174,6 +183,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setMaterialValue";
};
var setPosition = function () {
......@@ -187,6 +197,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setPosition";
};
var setRotation = function () {
......@@ -194,7 +205,7 @@ test( "Test Serialization", function( assert ) {
var box = aBox( 'Box with rotation' );
editor.execute( new CmdAddObject( box ) );
var newRotation = new THREE.Euler( 0.3, -1.7, 2 );
var newRotation = new THREE.Euler( 0.3, - 1.7, 2 );
var cmd = new CmdSetRotation( box, newRotation );
cmd.updatable = false;
editor.execute ( cmd );
......@@ -206,7 +217,7 @@ test( "Test Serialization", function( assert ) {
var setScale = function () {
var sphere = aSphere( 'Sphere with scale' );
editor.execute( new CmdAddObject( sphere) );
editor.execute( new CmdAddObject( sphere ) );
var newScale = new THREE.Vector3( 1.2, 3.3, 4.6 );
var cmd = new CmdSetScale( sphere, newScale );
......@@ -214,6 +225,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setScale";
};
var setScriptValue = function () {
......@@ -224,7 +236,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( new CmdAddScript( box, script ) );
var newScript = { name: "Console", source: "console.log( null );" };
var cmd = new CmdSetScriptValue( box, script, 'source', newScript.source , 0 );
var cmd = new CmdSetScriptValue( box, script, 'source', newScript.source, 0 );
cmd.updatable = false;
editor.execute( cmd );
......@@ -242,6 +254,7 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setUuid";
};
var setValue = function () {
......@@ -254,9 +267,11 @@ test( "Test Serialization", function( assert ) {
editor.execute( cmd );
return "setValue";
};
var setups = [
addObject,
addScript,
moveObject,
......@@ -274,15 +289,16 @@ test( "Test Serialization", function( assert ) {
setScriptValue,
setUuid,
setValue
];
function performTests() {
// Forward tests
for ( var i = 0; i < setups.length ; i++ ) {
for ( var i = 0; i < setups.length ; i ++ ) {
var name = setups[i]();
var name = setups[ i ]();
// Check for correct serialization
......@@ -300,7 +316,7 @@ test( "Test Serialization", function( assert ) {
var history2 = JSON.stringify( editor.history.toJSON() );
ok( history == history2 , "OK, forward serializing was successful for " + name );
ok( history == history2, "OK, forward serializing was successful for " + name );
editor.clear();
......@@ -308,9 +324,9 @@ test( "Test Serialization", function( assert ) {
// Backward tests
for (var i = 0; i < setups.length ; i++ ) {
for ( var i = 0; i < setups.length ; i ++ ) {
var name = setups[i]();
var name = setups[ i ]();
editor.history.goToState( 0 );
......@@ -325,7 +341,7 @@ test( "Test Serialization", function( assert ) {
var history2 = JSON.stringify( editor.history.toJSON() );
ok( history == history2 , "OK, backward serializing was successful for " + name );
ok( history == history2, "OK, backward serializing was successful for " + name );
editor.clear();
......@@ -333,4 +349,5 @@ test( "Test Serialization", function( assert ) {
}
});
\ No newline at end of file
} );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册