Browse Source

Tests: Unit Tests for Cameras (#25404)

* Update ArrayCamera.tests.js

ArrayCamera extends from PerspectiveCamera
ArrayCamera.isArrayCamera should be true
Stub missing member test.

* Update Camera.tests.js

Camera extends from Object3D
Camera.isCamera should be true
Explicit block scope for variables used in tests.
Stub missing member tests.

* Update CubeCamera.tests.js

CubeCamera extends from Object3D
CubeCamera.type should be CubeCamera
Stub missing member tests.

* Update OrthographicCamera.tests.js

OrthographicCamera extends from Camera
OrthographicCamera.type should be OrthographicCamera
OrthographicCamera.isOrthographicCamera should be true
Explicit block scope for variables used in tests.
Stub missing member tests.

* Update Camera.tests.js

Tone down previous comments.

* Update PerspectiveCamera.tests.js

PerspectiveCamera extends from Camera
PerspectiveCamera.type should be PerspectiveCamera
PerspectiveCamera.isPerspectiveCamera should be true
Explicit block scope for variables used in tests.
Stub missing member tests.

* Update StereoCamera.tests.js

StereoCamera.type should be StereoCamera
Stub missing member tests.
Ed Preston 2 years ago
parent
commit
9eaa3f0fb3

+ 23 - 5
test/unit/src/cameras/ArrayCamera.tests.js

@@ -1,15 +1,21 @@
 /* global QUnit */
 
-// import { ArrayCamera } from '../../../../src/cameras/ArrayCamera.js';
+import { ArrayCamera } from '../../../../src/cameras/ArrayCamera.js';
+
+import { PerspectiveCamera } from '../../../../src/cameras/PerspectiveCamera.js';
 
 export default QUnit.module( 'Cameras', () => {
 
 	QUnit.module( 'ArrayCamera', () => {
 
 		// INHERITANCE
-		QUnit.todo( 'Extending', ( assert ) => {
+		QUnit.test( 'Extending', ( assert ) => {
 
-			assert.ok( false, 'everything\'s gonna be alright' );
+			const object = new ArrayCamera();
+			assert.strictEqual(
+				object instanceof PerspectiveCamera, true,
+				'ArrayCamera extends from PerspectiveCamera'
+			);
 
 		} );
 
@@ -20,13 +26,25 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
-		// PUBLIC STUFF
-		QUnit.todo( 'isArrayCamera', ( assert ) => {
+		// PROPERTIES
+		QUnit.todo( 'cameras', ( assert ) => {
 
+			// array
 			assert.ok( false, 'everything\'s gonna be alright' );
 
 		} );
 
+		// PUBLIC
+		QUnit.test( 'isArrayCamera', ( assert ) => {
+
+			const object = new ArrayCamera();
+			assert.ok(
+				object.isArrayCamera,
+				'ArrayCamera.isArrayCamera should be true'
+			);
+
+		} );
+
 	} );
 
 } );

+ 55 - 10
test/unit/src/cameras/Camera.tests.js

@@ -1,16 +1,22 @@
 /* global QUnit */
 
 import { Camera } from '../../../../src/cameras/Camera.js';
+
 import { Vector3 } from '../../../../src/math/Vector3.js';
+import { Object3D } from '../../../../src/core/Object3D.js';
 
 export default QUnit.module( 'Cameras', () => {
 
 	QUnit.module( 'Camera', () => {
 
 		// INHERITANCE
-		QUnit.todo( 'Extending', ( assert ) => {
+		QUnit.test( 'Extending', ( assert ) => {
 
-			assert.ok( false, 'everything\'s gonna be alright' );
+			const object = new Camera();
+			assert.strictEqual(
+				object instanceof Object3D, true,
+				'Camera extends from Object3D'
+			);
 
 		} );
 
@@ -21,13 +27,46 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
-		// PUBLIC STUFF
-		QUnit.todo( 'isCamera', ( assert ) => {
+		// PROPERTIES
+		QUnit.test( 'type', ( assert ) => {
+
+			const object = new Camera();
+			assert.ok(
+				object.type === 'Camera',
+				'Camera.type should be Camera'
+			);
+
+		} );
+
+		QUnit.todo( 'matrixWorldInverse', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );
 
 		} );
 
+		QUnit.todo( 'projectionMatrix', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'projectionMatrixInverse', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// PUBLIC
+		QUnit.test( 'isCamera', ( assert ) => {
+
+			const object = new Camera();
+			assert.ok(
+				object.isCamera,
+				'Camera.isCamera should be true'
+			);
+
+		} );
+
 		QUnit.todo( 'copy', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );
@@ -46,18 +85,24 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
+		QUnit.todo( 'updateWorldMatrix', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
 		QUnit.test( 'clone', ( assert ) => {
 
-			var cam = new Camera();
+			const cam = new Camera();
 
 			// fill the matrices with any nonsense values just to see if they get copied
 			cam.matrixWorldInverse.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
 			cam.projectionMatrix.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
 
-			var clonedCam = cam.clone();
+			const clonedCam = cam.clone();
 
-			// TODO: Uuuummmhhh DO NOT relie equality on object methods !
-			// TODO: What's append if matrix.equal is wrongly implemented ???
+			// TODO: do not rely equality on object methods
+			// TODO: What's append if matrix.equal is wrongly implemented
 			// TODO: this MUST be check by assert
 			assert.ok( cam.matrixWorldInverse.equals( clonedCam.matrixWorldInverse ), 'matrixWorldInverse is equal' );
 			assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), 'projectionMatrix is equal' );
@@ -65,10 +110,10 @@ export default QUnit.module( 'Cameras', () => {
 		} );
 
 		// OTHERS
-		// TODO: this should not be here !!! This is Object3D stuff !!!
+		// TODO: this should not be here, Object3D related
 		QUnit.test( 'lookAt', ( assert ) => {
 
-			var cam = new Camera();
+			const cam = new Camera();
 			cam.lookAt( new Vector3( 0, 1, - 1 ) );
 
 			assert.numEqual( cam.rotation.x * ( 180 / Math.PI ), 45, 'x is equal' );

+ 34 - 3
test/unit/src/cameras/CubeCamera.tests.js

@@ -1,15 +1,21 @@
 /* global QUnit */
 
-// import { CubeCamera } from '../../../../src/cameras/CubeCamera.js';
+import { CubeCamera } from '../../../../src/cameras/CubeCamera.js';
+
+import { Object3D } from '../../../../src/core/Object3D.js';
 
 export default QUnit.module( 'Cameras', () => {
 
 	QUnit.module( 'CubeCamera', () => {
 
 		// INHERITANCE
-		QUnit.todo( 'Extending', ( assert ) => {
+		QUnit.test( 'Extending', ( assert ) => {
 
-			assert.ok( false, 'everything\'s gonna be alright' );
+			const object = new CubeCamera();
+			assert.strictEqual(
+				object instanceof Object3D, true,
+				'CubeCamera extends from Object3D'
+			);
 
 		} );
 
@@ -20,6 +26,31 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
+		// PROPERTIES
+		QUnit.test( 'type', ( assert ) => {
+
+			const object = new CubeCamera();
+			assert.ok(
+				object.type === 'CubeCamera',
+				'CubeCamera.type should be CubeCamera'
+			);
+
+		} );
+
+		QUnit.todo( 'renderTarget', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// PUBLIC
+		QUnit.todo( 'update', ( assert ) => {
+
+			// update( renderer, scene )
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
 	} );
 
 } );

+ 80 - 11
test/unit/src/cameras/OrthographicCamera.tests.js

@@ -2,14 +2,20 @@
 
 import { OrthographicCamera } from '../../../../src/cameras/OrthographicCamera.js';
 
+import { Camera } from '../../../../src/cameras/Camera.js';
+
 export default QUnit.module( 'Cameras', () => {
 
 	QUnit.module( 'OrthographicCamera', () => {
 
 		// INHERITANCE
-		QUnit.todo( 'Extending', ( assert ) => {
+		QUnit.test( 'Extending', ( assert ) => {
 
-			assert.ok( false, 'everything\'s gonna be alright' );
+			const object = new OrthographicCamera();
+			assert.strictEqual(
+				object instanceof Camera, true,
+				'OrthographicCamera extends from Camera'
+			);
 
 		} );
 
@@ -20,13 +26,76 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
-		// PUBLIC STUFF
-		QUnit.todo( 'isOrthographicCamera', ( assert ) => {
+		// PROPERTIES
+		QUnit.test( 'type', ( assert ) => {
+
+			const object = new OrthographicCamera();
+			assert.ok(
+				object.type === 'OrthographicCamera',
+				'OrthographicCamera.type should be OrthographicCamera'
+			);
+
+		} );
+
+		QUnit.todo( 'zoom', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'view', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );
 
 		} );
 
+		QUnit.todo( 'left', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'right', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'top', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'bottom', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'near', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'far', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// PUBLIC
+		QUnit.test( 'isOrthographicCamera', ( assert ) => {
+
+			const object = new OrthographicCamera();
+			assert.ok(
+				object.isOrthographicCamera,
+				'OrthographicCamera.isOrthographicCamera should be true'
+			);
+
+		} );
+
 		QUnit.todo( 'copy', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );
@@ -47,11 +116,11 @@ export default QUnit.module( 'Cameras', () => {
 
 		QUnit.test( 'updateProjectionMatrix', ( assert ) => {
 
-			var left = - 1, right = 1, top = 1, bottom = - 1, near = 1, far = 3;
-			var cam = new OrthographicCamera( left, right, top, bottom, near, far );
+			const left = - 1, right = 1, top = 1, bottom = - 1, near = 1, far = 3;
+			const cam = new OrthographicCamera( left, right, top, bottom, near, far );
 
 			// updateProjectionMatrix is called in constructor
-			var pMatrix = cam.projectionMatrix.elements;
+			const pMatrix = cam.projectionMatrix.elements;
 
 			// orthographic projection is given my the 4x4 Matrix
 			// 2/r-l		0			 0		-(l+r/r-l)
@@ -75,13 +144,13 @@ export default QUnit.module( 'Cameras', () => {
 		} );
 
 		// OTHERS
-		// TODO: no no no clone is a camera methods that relied to copy method
+		// TODO: clone is a camera methods that relied to copy method
 		QUnit.test( 'clone', ( assert ) => {
 
-			var left = - 1.5, right = 1.5, top = 1, bottom = - 1, near = 0.1, far = 42;
-			var cam = new OrthographicCamera( left, right, top, bottom, near, far );
+			const left = - 1.5, right = 1.5, top = 1, bottom = - 1, near = 0.1, far = 42;
+			const cam = new OrthographicCamera( left, right, top, bottom, near, far );
 
-			var clonedCam = cam.clone();
+			const clonedCam = cam.clone();
 
 			assert.ok( cam.left === clonedCam.left, 'left is equal' );
 			assert.ok( cam.right === clonedCam.right, 'right is equal' );

+ 87 - 12
test/unit/src/cameras/PerspectiveCamera.tests.js

@@ -1,7 +1,9 @@
 /* global QUnit */
 
 import { PerspectiveCamera } from '../../../../src/cameras/PerspectiveCamera.js';
+
 import { Matrix4 } from '../../../../src/math/Matrix4.js';
+import { Camera } from '../../../../src/cameras/Camera.js';
 
 export default QUnit.module( 'Cameras', () => {
 
@@ -17,7 +19,7 @@ export default QUnit.module( 'Cameras', () => {
 
 			}
 
-			for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
+			for ( let i = 0, il = a.elements.length; i < il; i ++ ) {
 
 				var delta = a.elements[ i ] - b.elements[ i ];
 				if ( delta > tolerance ) {
@@ -33,9 +35,13 @@ export default QUnit.module( 'Cameras', () => {
 		};
 
 		// INHERITANCE
-		QUnit.todo( 'Extending', ( assert ) => {
+		QUnit.test( 'Extending', ( assert ) => {
 
-			assert.ok( false, 'everything\'s gonna be alright' );
+			const object = new PerspectiveCamera();
+			assert.strictEqual(
+				object instanceof Camera, true,
+				'PerspectiveCamera extends from Camera'
+			);
 
 		} );
 
@@ -46,13 +52,82 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
-		// PUBLIC STUFF
-		QUnit.todo( 'isPerspectiveCamera', ( assert ) => {
+		// PROPERTIES
+		QUnit.test( 'type', ( assert ) => {
+
+			const object = new PerspectiveCamera();
+			assert.ok(
+				object.type === 'PerspectiveCamera',
+				'PerspectiveCamera.type should be PerspectiveCamera'
+			);
+
+		} );
+
+		QUnit.todo( 'fov', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'zoom', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );
 
 		} );
 
+		QUnit.todo( 'near', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'far', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'focus', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'aspect', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'view', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'filmGauge', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'filmOffset', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// PUBLIC
+		QUnit.test( 'isPerspectiveCamera', ( assert ) => {
+
+			const object = new PerspectiveCamera();
+			assert.ok(
+				object.isPerspectiveCamera,
+				'PerspectiveCamera.isPerspectiveCamera should be true'
+			);
+
+		} );
+
 		QUnit.todo( 'copy', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );
@@ -103,10 +178,10 @@ export default QUnit.module( 'Cameras', () => {
 
 		QUnit.test( 'updateProjectionMatrix', ( assert ) => {
 
-			var cam = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
+			const cam = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
 
 			// updateProjectionMatrix is called in constructor
-			var m = cam.projectionMatrix;
+			const m = cam.projectionMatrix;
 
 			// perspective projection is given my the 4x4 Matrix
 			// 2n/r-l		0			l+r/r-l				 0
@@ -116,7 +191,7 @@ export default QUnit.module( 'Cameras', () => {
 
 			// this matrix was calculated by hand via glMatrix.perspective(75, 16 / 9, 0.1, 300.0, pMatrix)
 			// to get a reference matrix from plain WebGL
-			var reference = new Matrix4().set(
+			const reference = new Matrix4().set(
 				0.7330642938613892, 0, 0, 0,
 				0, 1.3032253980636597, 0, 0,
 				0, 0, - 1.000666856765747, - 0.2000666856765747,
@@ -135,17 +210,17 @@ export default QUnit.module( 'Cameras', () => {
 		} );
 
 		// OTHERS
-		// TODO: no no no clone is a camera methods that relied to copy method
+		// TODO: clone is a camera methods that relied to copy method
 		QUnit.test( 'clone', ( assert ) => {
 
-			var near = 1,
+			const near = 1,
 				far = 3,
 				aspect = 16 / 9,
 				fov = 90;
 
-			var cam = new PerspectiveCamera( fov, aspect, near, far );
+			const cam = new PerspectiveCamera( fov, aspect, near, far );
 
-			var clonedCam = cam.clone();
+			const clonedCam = cam.clone();
 
 			assert.ok( cam.fov === clonedCam.fov, 'fov is equal' );
 			assert.ok( cam.aspect === clonedCam.aspect, 'aspect is equal' );

+ 37 - 2
test/unit/src/cameras/StereoCamera.tests.js

@@ -1,6 +1,6 @@
 /* global QUnit */
 
-// import { StereoCamera } from '../../../../src/cameras/StereoCamera.js';
+import { StereoCamera } from '../../../../src/cameras/StereoCamera.js';
 
 export default QUnit.module( 'Cameras', () => {
 
@@ -13,7 +13,42 @@ export default QUnit.module( 'Cameras', () => {
 
 		} );
 
-		// PUBLIC STUFF
+		// PROPERTIES
+		QUnit.test( 'type', ( assert ) => {
+
+			const object = new StereoCamera();
+			assert.ok(
+				object.type === 'StereoCamera',
+				'StereoCamera.type should be StereoCamera'
+			);
+
+		} );
+
+		QUnit.todo( 'aspect', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'eyeSep', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'cameraL', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		QUnit.todo( 'cameraR', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// PUBLIC
 		QUnit.todo( 'update', ( assert ) => {
 
 			assert.ok( false, 'everything\'s gonna be alright' );