Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Unit Tests for Math #25385

Merged
merged 26 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/unit/src/animation/AnimationMixer.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnimationMixer } from '../../../../src/animation/AnimationMixer.js';
import { AnimationClip } from '../../../../src/animation/AnimationClip.js';
import { VectorKeyframeTrack } from '../../../../src/animation/tracks/VectorKeyframeTrack.js';
import { Object3D } from '../../../../src/core/Object3D.js';
import { zero3, one3, two3 } from '../math/Constants.tests.js';
import { zero3, one3, two3 } from '../../utils/math-constants.js';

function getClips( pos1, pos2, scale1, scale2, dur ) {

Expand Down
2 changes: 1 addition & 1 deletion test/unit/src/core/BufferGeometry.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Vector3 } from '../../../../src/math/Vector3.js';
import { Matrix4 } from '../../../../src/math/Matrix4.js';
import { Quaternion } from '../../../../src/math/Quaternion.js';
import { Sphere } from '../../../../src/math/Sphere.js';
import { x, y, z } from '../math/Constants.tests.js';
import { x, y, z } from '../../utils/math-constants.js';

var DegToRad = Math.PI / 180;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/src/core/Object3D.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
z,
w,
eps
} from '../math/Constants.tests.js';
} from '../../utils/math-constants.js';
import { EventDispatcher } from '../../../../src/core/EventDispatcher.js';

const matrixEquals4 = ( a, b ) => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/src/core/Uniform.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
x,
y,
z
} from '../math/Constants.tests.js';
} from '../../utils/math-constants.js';

export default QUnit.module( 'Core', () => {

Expand Down
12 changes: 11 additions & 1 deletion test/unit/src/math/Box2.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
zero2,
one2,
two2
} from './Constants.tests.js';
} from '../../utils/math-constants.js';

export default QUnit.module( 'Maths', () => {

Expand All @@ -33,6 +33,16 @@ export default QUnit.module( 'Maths', () => {
} );

// PUBLIC STUFF
QUnit.test( 'isBox2', ( assert ) => {

var a = new Box2();
assert.ok( a.isBox2 === true, 'Passed!' );

var b = new Object();
assert.ok( ! b.isBox2, 'Passed!' );

} );

QUnit.test( 'set', ( assert ) => {

var a = new Box2();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/src/math/Box3.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
zero3,
one3,
two3
} from './Constants.tests.js';
} from '../../utils/math-constants.js';

function compareBox( a, b, threshold ) {

Expand Down
66 changes: 47 additions & 19 deletions test/unit/src/math/Color.tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global QUnit */

import { Color } from '../../../../src/math/Color.js';
import { eps } from './Constants.tests.js';
import { eps } from '../../utils/math-constants.js';
import { CONSOLE_LEVEL } from '../../utils/console-wrapper.js';

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

} );

QUnit.todo( 'getRGB', ( assert ) => {

// getRGB( target, colorSpace = ColorManagement.workingColorSpace )
assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.test( 'getStyle', ( assert ) => {

var c = new Color( 'plum' );
Expand Down Expand Up @@ -344,33 +351,29 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.test( 'copyHex', ( assert ) => {
QUnit.test( 'lerp', ( assert ) => {

var c = new Color();
var c2 = new Color( 0xF5FFFA );
c.copy( c2 );
assert.ok( c.getHex() == c2.getHex(), 'Hex c: ' + c.getHex() + ' Hex c2: ' + c2.getHex() );
var c2 = new Color();
c.setRGB( 0, 0, 0 );
c.lerp( c2, 0.2 );
assert.ok( c.r == 0.2, 'Red: ' + c.r );
assert.ok( c.g == 0.2, 'Green: ' + c.g );
assert.ok( c.b == 0.2, 'Blue: ' + c.b );

} );

QUnit.test( 'copyColorString', ( assert ) => {
QUnit.todo( 'lerpColors', ( assert ) => {

var c = new Color();
var c2 = new Color( 'ivory' );
c.copy( c2 );
assert.ok( c.getHex() == c2.getHex(), 'Hex c: ' + c.getHex() + ' Hex c2: ' + c2.getHex() );
// lerpColors( color1, color2, alpha )
assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.test( 'lerp', ( assert ) => {
QUnit.todo( 'lerpHSL', ( assert ) => {

var c = new Color();
var c2 = new Color();
c.setRGB( 0, 0, 0 );
c.lerp( c2, 0.2 );
assert.ok( c.r == 0.2, 'Red: ' + c.r );
assert.ok( c.g == 0.2, 'Green: ' + c.g );
assert.ok( c.b == 0.2, 'Blue: ' + c.b );
// lerpHSL( color, alpha )
assert.ok( false, 'everything\'s gonna be alright' );

} );

Expand Down Expand Up @@ -438,6 +441,13 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.todo( 'fromBufferAttribute', ( assert ) => {

// fromBufferAttribute( attribute, index )
assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.test( 'toJSON', ( assert ) => {

var a = new Color( 0.0, 0.0, 0.0 );
Expand All @@ -452,7 +462,25 @@ export default QUnit.module( 'Maths', () => {

} );

// OTHERS
// OTHERS - FUNCTIONAL
QUnit.test( 'copyHex', ( assert ) => {

var c = new Color();
var c2 = new Color( 0xF5FFFA );
c.copy( c2 );
assert.ok( c.getHex() == c2.getHex(), 'Hex c: ' + c.getHex() + ' Hex c2: ' + c2.getHex() );

} );

QUnit.test( 'copyColorString', ( assert ) => {

var c = new Color();
var c2 = new Color( 'ivory' );
c.copy( c2 );
assert.ok( c.getHex() == c2.getHex(), 'Hex c: ' + c.getHex() + ' Hex c2: ' + c2.getHex() );

} );

QUnit.test( 'setWithNum', ( assert ) => {

var c = new Color();
Expand Down
59 changes: 59 additions & 0 deletions test/unit/src/math/ColorManagement.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* global QUnit */

import { ColorManagement } from '../../../../src/math/ColorManagement.js';

export default QUnit.module( 'Maths', () => {

QUnit.module( 'ColorManagement', () => {

// PROPERTIES
QUnit.test( 'legacyMode', ( assert ) => {

assert.ok(
ColorManagement.legacyMode == true,
'ColorManagement.legacyMode is true by default.'
);

} );

QUnit.todo( 'workingColorSpace', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

// PUBLIC
QUnit.todo( 'convert', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'fromWorkingColorSpace', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'toWorkingColorSpace', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

// EXPORTED FUNCTIONS
QUnit.todo( 'SRGBToLinear', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'LinearToSRGB', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

} );

} );
11 changes: 9 additions & 2 deletions test/unit/src/math/Cylindrical.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Cylindrical } from '../../../../src/math/Cylindrical.js';
import { Vector3 } from '../../../../src/math/Vector3.js';
import { eps } from './Constants.tests.js';
import { eps } from '../../utils/math-constants.js';

export default QUnit.module( 'Maths', () => {

Expand All @@ -27,7 +27,7 @@ export default QUnit.module( 'Maths', () => {

} );

// PUBLIC STUFF
// PUBLIC
QUnit.test( 'set', ( assert ) => {

var a = new Cylindrical();
Expand Down Expand Up @@ -91,6 +91,13 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.todo( 'setFromCartesianCoords', ( assert ) => {

// setFromCartesianCoords( x, y, z )
assert.ok( false, 'everything\'s gonna be alright' );

} );

} );

} );
13 changes: 10 additions & 3 deletions test/unit/src/math/Euler.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Euler } from '../../../../src/math/Euler.js';
import { Matrix4 } from '../../../../src/math/Matrix4.js';
import { Quaternion } from '../../../../src/math/Quaternion.js';
import { Vector3 } from '../../../../src/math/Vector3.js';
import { x, y, z } from './Constants.tests.js';
import { x, y, z } from '../../utils/math-constants.js';

const eulerZero = new Euler( 0, 0, 0, 'XYZ' );
const eulerAxyz = new Euler( 1, 0, 0, 'XYZ' );
Expand Down Expand Up @@ -208,7 +208,7 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.test( 'Quaternion.setFromEuler/Euler.fromQuaternion', ( assert ) => {
QUnit.test( 'Quaternion.setFromEuler/Euler.setFromQuaternion', ( assert ) => {

var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
for ( var i = 0; i < testValues.length; i ++ ) {
Expand All @@ -224,7 +224,7 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.test( 'Matrix4.setFromEuler/Euler.fromRotationMatrix', ( assert ) => {
QUnit.test( 'Matrix4.makeRotationFromEuler/Euler.setFromRotationMatrix', ( assert ) => {

var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
for ( var i = 0; i < testValues.length; i ++ ) {
Expand All @@ -240,6 +240,13 @@ export default QUnit.module( 'Maths', () => {

} );

QUnit.todo( 'Euler.setFromVector3', ( assert ) => {

// setFromVector3( v, order = this._order )
assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.test( 'reorder', ( assert ) => {

var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
Expand Down
7 changes: 4 additions & 3 deletions test/unit/src/math/Frustum.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Matrix4 } from '../../../../src/math/Matrix4.js';
import { Box3 } from '../../../../src/math/Box3.js';
import { Mesh } from '../../../../src/objects/Mesh.js';
import { BoxGeometry } from '../../../../src/geometries/BoxGeometry.js';
import { zero3, one3, eps } from './Constants.tests.js';
import { zero3, one3, eps } from '../../utils/math-constants.js';

const unit3 = new Vector3( 1, 0, 0 );

Expand Down Expand Up @@ -49,7 +49,7 @@ export default QUnit.module( 'Maths', () => {

} );

// PUBLIC STUFF
// PUBLIC
QUnit.test( 'set', ( assert ) => {

var a = new Frustum();
Expand Down Expand Up @@ -247,7 +247,8 @@ export default QUnit.module( 'Maths', () => {
intersects = a.intersectsBox( box );
assert.notOk( intersects, 'No intersection' );

// add eps so that we prevent box touching the frustum, which might intersect depending on floating point numerics
// add eps so that we prevent box touching the frustum,
// which might intersect depending on floating point numerics
box.translate( new Vector3( - 1 - eps, - 1 - eps, - 1 - eps ) );

intersects = a.intersectsBox( box );
Expand Down
Loading