Forráskód Böngészése

Tests: Added more tests for src/lights/* and renamed old ones
Renamed all 'lights/foo.tests.js' to 'lights/foo.js'
Updated old tests to new test pattern
Small fixes to 'qunit-utils.js'

moraxy 7 éve
szülő
commit
1c1f2c4167

+ 43 - 14
test/unit/qunit-utils.js

@@ -243,33 +243,62 @@ function runStdGeometryTests( assert, geometries ) {
 //
 
 // Run common light tests.
-function runStdLightTests( assert, lights ) {
+function runStdLightTests( lights ) {
 
-	for ( var i = 0, l = lights.length; i < l; i++ ) {
+	for ( var i = 0, l = lights.length; i < l; i ++ ) {
 
-		var light = lights[i];
+		var light = lights[ i ];
 
-		// Clone
-		checkLightClone( light );
+		// copy and clone
+		checkLightCopyClone( light );
+
+		// THREE.Light doesn't get parsed by ObjectLoader as it's only
+		// used as an abstract base class - so we skip the JSON tests
+		if ( light.type !== "Light" ) {
+
+			// json round trip
+			checkLightJsonRoundtrip( light );
+
+		}
 
-		// json round trip
-		checkLightJsonRoundtrip( light );
 	}
 
 }
 
+function checkLightCopyClone( light ) {
 
-function checkLightClone( light ) {
+	// copy
+	var newLight = new light.constructor( 0xc0ffee );
+	newLight.copy( light );
+
+	QUnit.assert.notEqual( newLight.uuid, light.uuid, "Copied light's UUID differs from original" );
+	QUnit.assert.notEqual( newLight.id, light.id, "Copied light's id differs from original" );
+	QUnit.assert.smartEqual( newLight, light, "Copied light is equal to original" );
+
+	// real copy?
+	newLight.color.setHex( 0xc0ffee );
+	QUnit.assert.notStrictEqual(
+		newLight.color.getHex(), light.color.getHex(), "Copied light is independent from original"
+	);
 
 	// Clone
-	var copy = light.clone();
-	QUnit.assert.notEqual( copy.uuid, light.uuid, "clone uuid should differ from original" );
-	QUnit.assert.notEqual( copy.id, light.id, "clone id should differ from original" );
-	QUnit.assert.smartEqual( copy, light, "clone is equal to original" );
+	var clone = light.clone(); // better get a new var
+	QUnit.assert.notEqual( clone.uuid, light.uuid, "Cloned light's UUID differs from original" );
+	QUnit.assert.notEqual( clone.id, light.id, "Clone light's id differs from original" );
+	QUnit.assert.smartEqual( clone, light, "Clone light is equal to original" );
 
+	// real clone?
+	clone.color.setHex( 0xc0ffee );
+	QUnit.assert.notStrictEqual(
+		clone.color.getHex(), light.color.getHex(), "Clone light is independent from original"
+	);
 
-	// json round trip with clone
-	checkLightJsonRoundtrip( copy );
+	if ( light.type !== "Light" ) {
+
+		// json round trip with clone
+		checkLightJsonRoundtrip( clone );
+
+	}
 
 }
 

+ 21 - 0
test/unit/src/lights/AmbientLight.js

@@ -0,0 +1,21 @@
+/**
+ * @author moraxy / https://github.com/moraxy
+ */
+
+QUnit.module( "AmbientLight" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		color: 0xaaaaaa,
+		intensity: 0.5
+	};
+
+	var lights = [
+		new THREE.AmbientLight( parameters.color ),
+		new THREE.AmbientLight( parameters.color, parameters.intensity )
+	];
+
+	runStdLightTests( lights );
+
+} );

+ 0 - 27
test/unit/src/lights/AmbientLight.tests.js

@@ -1,27 +0,0 @@
-(function () {
-
-	'use strict';
-
-	var lights;
-
-	QUnit.module( "Lights - AmbientLight", {
-
-		beforeEach: function() {
-
-			lights = [
-
-				new THREE.AmbientLight( 0xaaaaaa ),
-
-			];
-
-		}
-
-	});
-
-	QUnit.test( "standard light tests", function( assert ) {
-
-		runStdLightTests( assert, lights );
-
-	});
-
-})();

+ 21 - 0
test/unit/src/lights/DirectionalLight.js

@@ -0,0 +1,21 @@
+/**
+ * @author moraxy / https://github.com/moraxy
+ */
+
+QUnit.module( "DirectionalLight" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		color: 0xaaaaaa,
+		intensity: 0.5
+	};
+
+	var lights = [
+		new THREE.DirectionalLight( parameters.color ),
+		new THREE.DirectionalLight( parameters.color, parameters.intensity )
+	];
+
+	runStdLightTests( lights );
+
+} );

+ 0 - 28
test/unit/src/lights/DirectionalLight.tests.js

@@ -1,28 +0,0 @@
-(function () {
-
-	'use strict';
-
-	var lights;
-
-	QUnit.module( "Lights - DirectionalLight", {
-
-		beforeEach: function() {
-
-			lights = [
-
-				new THREE.DirectionalLight( 0xaaaaaa ),
-				new THREE.DirectionalLight( 0xaaaaaa, 0.8 ),
-
-			];
-
-		}
-
-	});
-
-	QUnit.test( "standard light tests", function( assert ) {
-
-		runStdLightTests( assert, lights );
-
-	});
-
-})();

+ 40 - 5
test/unit/src/lights/DirectionalLightShadow.js

@@ -1,6 +1,41 @@
-/**
- * @author TristanVALCKE / https://github.com/TristanVALCKE
- */
 
-//Todo
-console.warn("Todo: Unit tests of DirectionalLightShadow")
+QUnit.module( "DirectionalLightShadow" );
+
+QUnit.test( "clone/copy", function ( assert ) {
+
+	var a = new THREE.DirectionalLightShadow();
+	var b = new THREE.DirectionalLightShadow();
+	var c;
+
+	assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
+
+	c = a.clone();
+	assert.smartEqual( a, c, "Shadows are identical after clone()" );
+
+	c.mapSize.set( 1024, 1024 );
+	assert.notDeepEqual( a, c, "Shadows are different again after change" );
+
+	b.copy( a );
+	assert.smartEqual( a, b, "Shadows are identical after copy()" );
+
+	b.mapSize.set( 512, 512 );
+	assert.notDeepEqual( a, b, "Shadows are different again after change" );
+
+} );
+
+QUnit.test( "toJSON", function ( assert ) {
+
+	var light = new THREE.DirectionalLight();
+	var shadow = new THREE.DirectionalLightShadow();
+
+	shadow.bias = 10;
+	shadow.radius = 5;
+	shadow.mapSize.set( 1024, 1024 );
+	light.shadow = shadow;
+
+	var json = light.toJSON();
+	var newLight = new THREE.ObjectLoader().parse( json );
+
+	assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is identical to the original one" );
+
+} );

+ 25 - 0
test/unit/src/lights/HemisphereLight.js

@@ -0,0 +1,25 @@
+/**
+ * @author moraxy / https://github.com/moraxy
+ */
+
+QUnit.module( "HemisphereLight" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		skyColor: 0x123456,
+		groundColor: 0xabc012,
+		intensity: 0.6
+	};
+
+	var lights = [
+		new THREE.HemisphereLight( parameters.skyColor ),
+		new THREE.HemisphereLight( parameters.skyColor, parameters.groundColor ),
+		new THREE.HemisphereLight(
+			parameters.skyColor, parameters.groundColor, parameters.intensity
+		)
+	];
+
+	runStdLightTests( lights );
+
+} );

+ 0 - 35
test/unit/src/lights/HemisphereLight.tests.js

@@ -1,35 +0,0 @@
-(function () {
-
-	'use strict';
-
-	var parameters = {
-		skyColor: 0x123456,
-		groundColor: 0xabc012,
-		intensity: 0.6
-	};
-
-	var lights;
-
-	QUnit.module( "Lights - HemisphereLight", {
-
-		beforeEach: function() {
-
-			lights = [
-
-				new THREE.HemisphereLight( parameters.skyColor ),
-				new THREE.HemisphereLight( parameters.skyColor, parameters.groundColor ),
-				new THREE.HemisphereLight( parameters.skyColor, parameters.groundColor, parameters.intensity ),
-
-			];
-
-		}
-
-	});
-
-	QUnit.test( "standard light tests", function( assert ) {
-
-		runStdLightTests( assert, lights );
-
-	});
-
-})();

+ 18 - 3
test/unit/src/lights/Light.js

@@ -1,6 +1,21 @@
 /**
- * @author TristanVALCKE / https://github.com/TristanVALCKE
+ * @author moraxy / https://github.com/moraxy
  */
 
-//Todo
-console.warn("Todo: Unit tests of Light")
+QUnit.module( "Light" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		color: 0xaaaaaa,
+		intensity: 0.5
+	};
+
+	var lights = [
+		new THREE.Light( parameters.color ),
+		new THREE.Light( parameters.color, parameters.intensity )
+	];
+
+	runStdLightTests( lights, true );
+
+} );

+ 23 - 5
test/unit/src/lights/LightShadow.js

@@ -1,6 +1,24 @@
-/**
- * @author TristanVALCKE / https://github.com/TristanVALCKE
- */
 
-//Todo
-console.warn("Todo: Unit tests of LightShadow")
+QUnit.module( "LightShadow" );
+
+QUnit.test( "clone/copy", function ( assert ) {
+
+	var a = new THREE.LightShadow( new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
+	var b = new THREE.LightShadow( new THREE.OrthographicCamera( - 3, 3, 3, - 3, 0.3, 300 ) );
+	var c;
+
+	assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
+
+	c = a.clone();
+	assert.smartEqual( a, c, "Shadows are identical after clone()" );
+
+	c.mapSize.set( 256, 256 );
+	assert.notDeepEqual( a, c, "Shadows are different again after change" );
+
+	b.copy( a );
+	assert.smartEqual( a, b, "Shadows are identical after copy()" );
+
+	b.mapSize.set( 512, 512 );
+	assert.notDeepEqual( a, b, "Shadows are different again after change" );
+
+} );

+ 45 - 0
test/unit/src/lights/PointLight.js

@@ -0,0 +1,45 @@
+/**
+ * @author moraxy / https://github.com/moraxy
+ */
+
+QUnit.module( "PointLight" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		color: 0xaaaaaa,
+		intensity: 0.5,
+		distance: 100,
+		decay: 2
+	};
+
+	var lights = [
+		new THREE.PointLight( parameters.color ),
+		new THREE.PointLight( parameters.color, parameters.intensity ),
+		new THREE.PointLight(
+			parameters.color, parameters.intensity, parameters.distance
+		),
+		new THREE.PointLight(
+			parameters.color, parameters.intensity, parameters.distance,
+			parameters.decay
+		)
+	];
+
+	runStdLightTests( lights );
+
+} );
+
+QUnit.test( "power", function ( assert ) {
+
+	var a = new THREE.PointLight( 0xaaaaaa );
+
+	a.intensity = 100;
+	assert.numEqual( a.power, 100 * Math.PI * 4, "Correct power for an intensity of 100" );
+
+	a.intensity = 40;
+	assert.numEqual( a.power, 40 * Math.PI * 4, "Correct power for an intensity of 40" );
+
+	a.power = 100;
+	assert.numEqual( a.intensity, 100 / ( 4 * Math.PI ), "Correct intensity for a power of 100" );
+
+} );

+ 0 - 27
test/unit/src/lights/PointLight.tests.js

@@ -1,27 +0,0 @@
-(function () {
-
-	'use strict';
-
-	var lights;
-
-	QUnit.module( "Lights - PointLight", {
-
-		beforeEach: function() {
-
-			lights = [
-
-				new THREE.PointLight( 0xaaaaaa ),
-
-			];
-
-		}
-
-	});
-
-	QUnit.test( "standard light tests", function( assert ) {
-
-		runStdLightTests( assert, lights );
-
-	});
-
-})();

+ 29 - 0
test/unit/src/lights/RectAreaLight.js

@@ -0,0 +1,29 @@
+/**
+ * @author moraxy / https://github.com/moraxy
+ */
+
+QUnit.module( "RectAreaLight" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		color: 0xaaaaaa,
+		intensity: 0.5,
+		width: 100,
+		height: 50
+	};
+
+	var lights = [
+		new THREE.RectAreaLight( parameters.color ),
+		new THREE.RectAreaLight( parameters.color, parameters.intensity ),
+		new THREE.RectAreaLight(
+			parameters.color, parameters.intensity, parameters.width
+		),
+		new THREE.RectAreaLight(
+			parameters.color, parameters.intensity, parameters.width, parameters.height
+		)
+	];
+
+	runStdLightTests( lights );
+
+} );

+ 0 - 38
test/unit/src/lights/RectAreaLight.tests.js

@@ -1,38 +0,0 @@
-(function () {
-
-	'use strict';
-
-	var parameters = {
-		color: 0xaaaaaa,
-		intensity: 0.5,
-	};
-
-	var lights;
-
-	// TODO (abelnation): verify this works
-
-	QUnit.module( "Lights - RectAreaLight", {
-
-		beforeEach: function() {
-
-			lights = [
-
-				new THREE.RectAreaLight( parameters.color ),
-				new THREE.RectAreaLight( parameters.color, parameters.intensity ),
-				new THREE.RectAreaLight( parameters.color, parameters.intensity, 5.0 ),
-				new THREE.RectAreaLight( parameters.color, parameters.intensity, 5.0, 20.0 ),
-				new THREE.RectAreaLight( parameters.color, parameters.intensity, undefined, 20.0 ),
-
-			];
-
-		}
-
-	});
-
-	QUnit.test( "standard light tests", function( assert ) {
-
-		runStdLightTests( assert, lights );
-
-	});
-
-})();

+ 55 - 0
test/unit/src/lights/SpotLight.js

@@ -0,0 +1,55 @@
+/**
+ * @author moraxy / https://github.com/moraxy
+ */
+
+QUnit.module( "SpotLight" );
+
+QUnit.test( "Standard Light tests", function ( assert ) {
+
+	var parameters = {
+		color: 0xaaaaaa,
+		intensity: 0.5,
+		distance: 100,
+		angle: 0.8,
+		penumbra: 8,
+		decay: 2
+	};
+
+	var lights = [
+		new THREE.SpotLight( parameters.color ),
+		new THREE.SpotLight( parameters.color, parameters.intensity ),
+		new THREE.SpotLight(
+			parameters.color, parameters.intensity, parameters.distance
+		),
+		new THREE.SpotLight(
+			parameters.color, parameters.intensity, parameters.distance,
+			parameters.angle
+		),
+		new THREE.SpotLight(
+			parameters.color, parameters.intensity, parameters.distance,
+			parameters.angle, parameters.penumbra
+		),
+		new THREE.SpotLight(
+			parameters.color, parameters.intensity, parameters.distance,
+			parameters.angle, parameters.penumbra, parameters.decay
+		)
+	];
+
+	runStdLightTests( lights );
+
+} );
+
+QUnit.test( "power", function ( assert ) {
+
+	var a = new THREE.SpotLight( 0xaaaaaa );
+
+	a.intensity = 100;
+	assert.numEqual( a.power, 100 * Math.PI, "Correct power for an intensity of 100" );
+
+	a.intensity = 40;
+	assert.numEqual( a.power, 40 * Math.PI, "Correct power for an intensity of 40" );
+
+	a.power = 100;
+	assert.numEqual( a.intensity, 100 / Math.PI, "Correct intensity for a power of 100" );
+
+} );

+ 0 - 41
test/unit/src/lights/SpotLight.tests.js

@@ -1,41 +0,0 @@
-(function () {
-
-	'use strict';
-
-	var parameters = {
-		color: 0xaaaaaa,
-		intensity: 0.5,
-		distance: 100,
-		angle: 0.8,
-		exponent: 8,
-		decay: 2
-	};
-
-	var lights;
-
-	QUnit.module( "Lights - SpotLight", {
-
-		beforeEach: function() {
-
-			lights = [
-
-				new THREE.SpotLight( parameters.color ),
-				new THREE.SpotLight( parameters.color, parameters.intensity ),
-				new THREE.SpotLight( parameters.color, parameters.intensity, parameters.distance ),
-				new THREE.SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle ),
-				new THREE.SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.exponent ),
-				new THREE.SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.exponent, parameters.decay ),
-
-			];
-
-		}
-
-	});
-
-	QUnit.test( "standard light tests", function( assert ) {
-
-		runStdLightTests( assert, lights );
-
-	});
-
-})();

+ 40 - 5
test/unit/src/lights/SpotLightShadow.js

@@ -1,6 +1,41 @@
-/**
- * @author TristanVALCKE / https://github.com/TristanVALCKE
- */
 
-//Todo
-console.warn("Todo: Unit tests of SpotLightShadow")
+QUnit.module( "SpotLightShadow" );
+
+QUnit.test( "clone/copy", function ( assert ) {
+
+	var a = new THREE.SpotLightShadow();
+	var b = new THREE.SpotLightShadow();
+	var c;
+
+	assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
+
+	c = a.clone();
+	assert.smartEqual( a, c, "Shadows are identical after clone()" );
+
+	c.mapSize.set( 256, 256 );
+	assert.notDeepEqual( a, c, "Shadows are different again after change" );
+
+	b.copy( a );
+	assert.smartEqual( a, b, "Shadows are identical after copy()" );
+
+	b.mapSize.set( 512, 512 );
+	assert.notDeepEqual( a, b, "Shadows are different again after change" );
+
+} );
+
+QUnit.test( "toJSON", function ( assert ) {
+
+	var light = new THREE.SpotLight();
+	var shadow = new THREE.SpotLightShadow();
+
+	shadow.bias = 10;
+	shadow.radius = 5;
+	shadow.mapSize.set( 128, 128 );
+	light.shadow = shadow;
+
+	var json = light.toJSON();
+	var newLight = new THREE.ObjectLoader().parse( json );
+
+	assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is equal to the original one" );
+
+} );

+ 6 - 6
test/unit/unittests_sources.html

@@ -157,15 +157,15 @@
 
 
   <!-- /src/lights -->
-  <script src="src/lights/AmbientLight.tests.js"></script>
-  <script src="src/lights/DirectionalLight.tests.js"></script>
+  <script src="src/lights/AmbientLight.js"></script>
+  <script src="src/lights/DirectionalLight.js"></script>
   <script src="src/lights/DirectionalLightShadow.js"></script>
-  <script src="src/lights/HemisphereLight.tests.js"></script>
+  <script src="src/lights/HemisphereLight.js"></script>
   <script src="src/lights/Light.js"></script>
   <script src="src/lights/LightShadow.js"></script>
-  <script src="src/lights/PointLight.tests.js"></script>
-  <script src="src/lights/RectAreaLight.tests.js"></script>
-  <script src="src/lights/SpotLight.tests.js"></script>
+  <script src="src/lights/PointLight.js"></script>
+  <script src="src/lights/RectAreaLight.js"></script>
+  <script src="src/lights/SpotLight.js"></script>
   <script src="src/lights/SpotLightShadow.js"></script>