Skip to content

Commit

Permalink
Merge pull request #13550 from Mugen87/dev4
Browse files Browse the repository at this point in the history
Tests: Added target parameter Part I
  • Loading branch information
mrdoob authored Mar 9, 2018
2 parents 7e7f7fc + 2c7ce59 commit d3c3abe
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 156 deletions.
2 changes: 2 additions & 0 deletions test/three.source.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @author TristanVALCKE / https://github.com/Itee
*/

import './unit/qunit-utils.js';

//src
import './unit/src/constants.tests';
import './unit/src/polyfills.tests';
Expand Down
84 changes: 54 additions & 30 deletions test/unit/src/math/Box2.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,65 +113,72 @@ export default QUnit.module( 'Maths', () => {
QUnit.test( "getCenter", ( assert ) => {

var a = new Box2( zero2.clone(), zero2.clone() );

assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
var center = new Vector2();
assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );

var a = new Box2( zero2, one2 );
var midpoint = one2.clone().multiplyScalar( 0.5 );
assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
assert.ok( a.getCenter( center ).equals( midpoint ), "Passed!" );

} );

QUnit.test( "getSize", ( assert ) => {

var a = new Box2( zero2.clone(), zero2.clone() );
var size = new Vector2();

assert.ok( a.getSize().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );

var a = new Box2( zero2.clone(), one2.clone() );
assert.ok( a.getSize().equals( one2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );

} );

QUnit.test( "expandByPoint", ( assert ) => {

var a = new Box2( zero2.clone(), zero2.clone() );
var size = new Vector2();
var center = new Vector2();

a.expandByPoint( zero2 );
assert.ok( a.getSize().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );

a.expandByPoint( one2 );
assert.ok( a.getSize().equals( one2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );

a.expandByPoint( one2.clone().negate() );
assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );

} );

QUnit.test( "expandByVector", ( assert ) => {

var a = new Box2( zero2.clone(), zero2.clone() );
var size = new Vector2();
var center = new Vector2();

a.expandByVector( zero2 );
assert.ok( a.getSize().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );

a.expandByVector( one2 );
assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );

} );

QUnit.test( "expandByScalar", ( assert ) => {

var a = new Box2( zero2.clone(), zero2.clone() );
var size = new Vector2();
var center = new Vector2();

a.expandByScalar( 0 );
assert.ok( a.getSize().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );

a.expandByScalar( 1 );
assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );

} );

Expand Down Expand Up @@ -210,12 +217,19 @@ export default QUnit.module( 'Maths', () => {
var a = new Box2( zero2.clone(), one2.clone() );
var b = new Box2( one2.clone().negate(), one2.clone() );

assert.ok( a.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
assert.ok( a.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
var parameter = new Vector2();

a.getParameter( zero2, parameter );
assert.ok( parameter.equals( zero2 ), "Passed!" );
a.getParameter( one2, parameter );
assert.ok( parameter.equals( one2 ), "Passed!" );

assert.ok( b.getParameter( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
assert.ok( b.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
assert.ok( b.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
b.getParameter( one2.clone().negate(), parameter );
assert.ok( parameter.equals( zero2 ), "Passed!" );
b.getParameter( zero2, parameter );
assert.ok( parameter.equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
b.getParameter( one2, parameter );
assert.ok( parameter.equals( one2 ), "Passed!" );

} );

Expand All @@ -233,7 +247,7 @@ export default QUnit.module( 'Maths', () => {
assert.ok( c.intersectsBox( a ), "Passed!" );
assert.ok( b.intersectsBox( c ), "Passed!" );

b.translate( new Vector2( 2, 2 ) );
b.translate( two2 );
assert.ok( ! a.intersectsBox( b ), "Passed!" );
assert.ok( ! b.intersectsBox( a ), "Passed!" );
assert.ok( ! b.intersectsBox( c ), "Passed!" );
Expand All @@ -245,15 +259,25 @@ export default QUnit.module( 'Maths', () => {
var a = new Box2( zero2.clone(), zero2.clone() );
var b = new Box2( one2.clone().negate(), one2.clone() );

assert.ok( a.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
assert.ok( a.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
assert.ok( a.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );

assert.ok( b.clampPoint( new Vector2( 2, 2 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector2( - 2, - 2 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
var point = new Vector2();

a.clampPoint( zero2, point );
assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
a.clampPoint( one2, point );
assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
a.clampPoint( one2.clone().negate(), point );
assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );

b.clampPoint( two2, point );
assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );
b.clampPoint( one2, point );
assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );
b.clampPoint( zero2, point );
assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
b.clampPoint( one2.clone().negate(), point );
assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );
b.clampPoint( two2.clone().negate(), point );
assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );

} );

Expand Down
109 changes: 72 additions & 37 deletions test/unit/src/math/Box3.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,31 @@ export default QUnit.module( 'Maths', () => {

var a = new Box3( zero3.clone(), one3.clone() );
var b = a.clone();
var centerA = new Vector3();
var sizeA = new Vector3();
var sizeB = new Vector3();
var newCenter = one3;
var newSize = two3;

a.setFromCenterAndSize( a.getCenter(), a.getSize() );
a.getCenter( centerA );
a.getSize( sizeA );
a.setFromCenterAndSize( centerA, sizeA );
assert.ok( a.equals( b ), "Same values: no changes" );

a.setFromCenterAndSize( newCenter, a.getSize() );
assert.ok( a.getCenter().equals( newCenter ), "Move center: correct new center" );
assert.ok( a.getSize().equals( b.getSize() ), "Move center: no change in size" );
a.setFromCenterAndSize( newCenter, sizeA );
a.getCenter( centerA );
a.getSize( sizeA );
b.getSize( sizeB );

assert.ok( centerA.equals( newCenter ), "Move center: correct new center" );
assert.ok( sizeA.equals( sizeB ), "Move center: no change in size" );
assert.notOk( a.equals( b ), "Move center: no longer equal to old values" );

a.setFromCenterAndSize( a.getCenter(), newSize );
assert.ok( a.getCenter().equals( newCenter ), "Resize: no change to center" );
assert.ok( a.getSize().equals( newSize ), "Resize: correct new size" );
a.setFromCenterAndSize( centerA, newSize );
a.getCenter( centerA );
a.getSize( sizeA );
assert.ok( centerA.equals( newCenter ), "Resize: no change to center" );
assert.ok( sizeA.equals( newSize ), "Resize: correct new size" );
assert.notOk( a.equals( b ), "Resize: no longer equal to old values" );

} );
Expand Down Expand Up @@ -197,65 +208,73 @@ export default QUnit.module( 'Maths', () => {
QUnit.test( "getCenter", ( assert ) => {

var a = new Box3( zero3.clone(), zero3.clone() );
var center = new Vector3();

assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );

var a = new Box3( zero3.clone(), one3.clone() );
var midpoint = one3.clone().multiplyScalar( 0.5 );
assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
assert.ok( a.getCenter( center ).equals( midpoint ), "Passed!" );

} );

QUnit.test( "getSize", ( assert ) => {

var a = new Box3( zero3.clone(), zero3.clone() );
var size = new Vector3();

assert.ok( a.getSize().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );

var a = new Box3( zero3.clone(), one3.clone() );
assert.ok( a.getSize().equals( one3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one3 ), "Passed!" );

} );

QUnit.test( "expandByPoint", ( assert ) => {

var a = new Box3( zero3.clone(), zero3.clone() );
var center = new Vector3();
var size = new Vector3();

a.expandByPoint( zero3 );
assert.ok( a.getSize().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );

a.expandByPoint( one3 );
assert.ok( a.getSize().equals( one3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one3 ), "Passed!" );

a.expandByPoint( one3.clone().negate() );
assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );

} );

QUnit.test( "expandByVector", ( assert ) => {

var a = new Box3( zero3.clone(), zero3.clone() );
var center = new Vector3();
var size = new Vector3();

a.expandByVector( zero3 );
assert.ok( a.getSize().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );

a.expandByVector( one3 );
assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );

} );

QUnit.test( "expandByScalar", ( assert ) => {

var a = new Box3( zero3.clone(), zero3.clone() );
var center = new Vector3();
var size = new Vector3();

a.expandByScalar( 0 );
assert.ok( a.getSize().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );

a.expandByScalar( 1 );
assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
assert.ok( a.getSize( size ).equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );

} );

Expand Down Expand Up @@ -335,13 +354,19 @@ export default QUnit.module( 'Maths', () => {

var a = new Box3( zero3.clone(), one3.clone() );
var b = new Box3( one3.clone().negate(), one3.clone() );
var parameter = new Vector3();

assert.ok( a.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
assert.ok( a.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
a.getParameter( zero3, parameter );
assert.ok( parameter.equals( zero3 ), "Passed!" );
a.getParameter( one3, parameter );
assert.ok( parameter.equals( one3 ), "Passed!" );

assert.ok( b.getParameter( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
assert.ok( b.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
assert.ok( b.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
b.getParameter( one3.clone().negate(), parameter );
assert.ok( parameter.equals( zero3 ), "Passed!" );
b.getParameter( zero3, parameter );
assert.ok( parameter.equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
b.getParameter( one3, parameter );
assert.ok( parameter.equals( one3 ), "Passed!" );

} );

Expand Down Expand Up @@ -412,16 +437,25 @@ export default QUnit.module( 'Maths', () => {

var a = new Box3( zero3.clone(), zero3.clone() );
var b = new Box3( one3.clone().negate(), one3.clone() );
var point = new Vector3();

assert.ok( a.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
assert.ok( a.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
assert.ok( a.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
a.clampPoint( zero3, point );
assert.ok( point.equals( zero3 ), "Passed!" );
a.clampPoint( one3, point );
assert.ok( point.equals( zero3 ), "Passed!" );
a.clampPoint( one3.clone().negate(), point );
assert.ok( point.equals( zero3 ), "Passed!" );

assert.ok( b.clampPoint( new Vector3( 2, 2, 2 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
assert.ok( b.clampPoint( new Vector3( - 2, - 2, - 2 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
b.clampPoint( new Vector3( 2, 2, 2 ), point );
assert.ok( point.equals( one3 ), "Passed!" );
b.clampPoint( one3, point );
assert.ok( point.equals( one3 ), "Passed!" );
b.clampPoint( zero3, point );
assert.ok( point.equals( zero3 ), "Passed!" );
b.clampPoint( one3.clone().negate(), point );
assert.ok( point.equals( one3.clone().negate() ), "Passed!" );
b.clampPoint( new Vector3( - 2, - 2, - 2 ), point );
assert.ok( point.equals( one3.clone().negate() ), "Passed!" );

} );

Expand All @@ -447,10 +481,11 @@ export default QUnit.module( 'Maths', () => {
var a = new Box3( zero3.clone(), zero3.clone() );
var b = new Box3( zero3.clone(), one3.clone() );
var c = new Box3( one3.clone().negate(), one3.clone() );
var sphere = new Sphere();

assert.ok( a.getBoundingSphere().equals( new Sphere( zero3, 0 ) ), "Passed!" );
assert.ok( b.getBoundingSphere().equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
assert.ok( c.getBoundingSphere().equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );
assert.ok( a.getBoundingSphere( sphere ).equals( new Sphere( zero3, 0 ) ), "Passed!" );
assert.ok( b.getBoundingSphere( sphere ).equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
assert.ok( c.getBoundingSphere( sphere ).equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );

} );

Expand Down
Loading

0 comments on commit d3c3abe

Please sign in to comment.