Browse Source

Merge pull request #16780 from gero3/AddMathUnitTests

Add box2 unittests
Mr.doob 6 years ago
parent
commit
38da3e9b59
2 changed files with 73 additions and 8 deletions
  1. 70 8
      test/unit/src/math/Box2.tests.js
  2. 3 0
      test/unit/src/math/Constants.tests.js

+ 70 - 8
test/unit/src/math/Box2.tests.js

@@ -9,6 +9,7 @@ import { Vector2 } from '../../../../src/math/Vector2';
 import {
 	negInf2,
 	posInf2,
+	negOne2,
 	zero2,
 	one2,
 	two2
@@ -63,15 +64,37 @@ export default QUnit.module( 'Maths', () => {
 
 		} );
 
-		QUnit.todo( "setFromCenterAndSize", ( assert ) => {
+		QUnit.test( "setFromCenterAndSize", ( assert ) => {
 
-			assert.ok( false, "everything's gonna be alright" );
+			var a = new Box2();
+
+			a.setFromCenterAndSize( zero2, two2 );
+			assert.ok( a.min.equals( negOne2 ), "Passed!" );
+			assert.ok( a.max.equals( one2 ), "Passed!" );
+
+			a.setFromCenterAndSize( one2, two2 );
+			assert.ok( a.min.equals( zero2 ), "Passed!" );
+			assert.ok( a.max.equals( two2 ), "Passed!" );
+
+			a.setFromCenterAndSize( zero2, zero2 );
+			assert.ok( a.min.equals( zero2 ), "Passed!" );
+			assert.ok( a.max.equals( zero2 ), "Passed!" );
 
 		} );
 
-		QUnit.todo( "clone", ( assert ) => {
+		QUnit.test( "clone", ( assert ) => {
+
+
+			var a = new Box2( zero2, zero2 );
+
+			var b = a.clone();
+			assert.ok( b.min.equals( zero2 ), "Passed!" );
+			assert.ok( b.max.equals( zero2 ), "Passed!" );
 
-			assert.ok( false, "everything's gonna be alright" );
+			a = new Box2();
+			var b = a.clone();
+			assert.ok( b.min.equals( posInf2 ), "Passed!" );
+			assert.ok( b.max.equals( negInf2 ), "Passed!" );
 
 		} );
 
@@ -104,9 +127,19 @@ export default QUnit.module( 'Maths', () => {
 
 		} );
 
-		QUnit.todo( "isEmpty", ( assert ) => {
+		QUnit.test( "isEmpty", ( assert ) => {
+
+			var a = new Box2( zero2.clone(), zero2.clone() );
+			assert.ok( ! a.isEmpty(), "Passed!" );
+
+			var a = new Box2( zero2.clone(), one2.clone() );
+			assert.ok( ! a.isEmpty(), "Passed!" );
+
+			var a = new Box2( two2.clone(), one2.clone() );
+			assert.ok( a.isEmpty(), "Passed!" );
 
-			assert.ok( false, "everything's gonna be alright" );
+			var a = new Box2( posInf2.clone(), negInf2.clone() );
+			assert.ok( a.isEmpty(), "Passed!" );
 
 		} );
 
@@ -340,9 +373,38 @@ export default QUnit.module( 'Maths', () => {
 
 		} );
 
-		QUnit.todo( "equals", ( assert ) => {
+		QUnit.test( "equals", ( assert ) => {
+
 
-			assert.ok( false, "everything's gonna be alright" );
+			var a = new Box2();
+			var b = new Box2();
+			assert.ok( b.equals( a ), "Passed!" );
+			assert.ok( a.equals( b ), "Passed!" );
+
+			a = new Box2( one2, two2 );
+			b = new Box2( one2, two2 );
+			assert.ok( b.equals( a ), "Passed!" );
+			assert.ok( a.equals( b ), "Passed!" );
+
+			a = new Box2( one2, two2 );
+			b = a.clone();
+			assert.ok( b.equals( a ), "Passed!" );
+			assert.ok( a.equals( b ), "Passed!" );
+
+			a = new Box2( one2, two2 );
+			b = new Box2( one2, one2 );
+			assert.ok( ! b.equals( a ), "Passed!" );
+			assert.ok( ! a.equals( b ), "Passed!" );
+
+			a = new Box2();
+			b = new Box2( one2, one2 );
+			assert.ok( ! b.equals( a ), "Passed!" );
+			assert.ok( ! a.equals( b ), "Passed!" );
+
+			a = new Box2( one2, two2 );
+			b = new Box2( one2, one2 );
+			assert.ok( ! b.equals( a ), "Passed!" );
+			assert.ok( ! a.equals( b ), "Passed!" );
 
 		} );
 

+ 3 - 0
test/unit/src/math/Constants.tests.js

@@ -13,6 +13,9 @@ export const w = 5;
 export const negInf2 = new Vector2( - Infinity, - Infinity );
 export const posInf2 = new Vector2( Infinity, Infinity );
 
+
+export const negOne2 = new Vector2( - 1, - 1 );
+
 export const zero2 = new Vector2();
 export const one2 = new Vector2( 1, 1 );
 export const two2 = new Vector2( 2, 2 );