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

Fix some unit tests not testing properly #12778

Merged
merged 8 commits into from
Dec 5, 2017
Merged

Conversation

OndrejSpanel
Copy link
Contributor

Several unit tests contained mistakes which made them not testing properly what they should, mostly because they were passing wrong arguments to the tested function. They were all passing and are still passing now, the tests were fixed as needed.

I have also added argument checks into the called functions to detect such parameter/argument mismatches.

The case of Frustum.intersectsBox is most confusing to me, I am not sure how the code could be passing before:

box.translate( - 1, - 1, - 1 );

It definitely was not passing when changed to box.translate( new Vector3( - 1, - 1, - 1 ) );, epsilon had to be added.

The case of Euler order seems quite clear.

The Face3 fix is most debatable - the tests were not wrong, but I am convinced they are more robust now.

@OndrejSpanel
Copy link
Contributor Author

OndrejSpanel commented Nov 29, 2017

Please check #12778, too.

@Mugen87 I have already reworked the commits meanwhile. Do you see any issues still left?

src/math/Box3.js Outdated
@@ -467,6 +467,9 @@ Object.assign( Box3.prototype, {
}(),

translate: function ( offset ) {
if ( ! offset.isVector3 ) {
throw new Error( 'THREE.Box3: .translate() expects a Vector3.' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentations not correct here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope to have cleaned all of them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. You can use an ESLint plugin in your editor or IDE for better code style. three.js uses an ESLint preset that is configured in the package JSON. Linter plugins like the ESLint plugin for Atom automatically detect this present and show appropriate feedback in the editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. ESLint plugin installed, this will definitely make things easier for me in the future.

I think code style in this PR is good already (ESList also does not show any issues to me). Or are there still some issues left?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thinks it's okay now.

if ( order ) {

throw new Error( 'THREE.Matrix4: .makeRotationFromEuler() no longer accepts order as the second parameter.' );
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here...

if ( typeof update === 'string' || update instanceof String ) {

throw new Error( 'THREE.Quaternion: .setFromEuler() no longer accepts order as the second parameter.' );
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here...

var m3 = new Matrix4().makeRotationFromEuler( angles[ 2 ], "XYZ" );
var m1 = new Matrix4().makeRotationFromEuler( changeEulerOrder( angles[ 0 ], "XYZ" ) );
var m2 = new Matrix4().makeRotationFromEuler( changeEulerOrder( angles[ 1 ], "XYZ" ) );
var m3 = new Matrix4().makeRotationFromEuler( changeEulerOrder( angles[ 2 ], "XYZ" ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

@@ -160,6 +160,10 @@ function slerpTestSkeleton( doSlerp, maxError, assert ) {

}

function changeEulerOrder(euler, order) {
return new Euler( euler.x, euler.y, euler.z, order );
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this:

function changeEulerOrder( euler, order ) {

   return new Euler( euler.x, euler.y, euler.z, order );

}


if ( ! ( euler && euler.isEuler ) ) {

console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );

}
if ( order ) {

throw new Error( 'THREE.Matrix4: .makeRotationFromEuler() no longer accepts order as the second parameter.' );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here. I would prefer to add these checks in the tests instead.

Copy link
Contributor Author

@OndrejSpanel OndrejSpanel Dec 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not needed at all. If you prefer, I can remove them completely, test do not test for them. I just added them thinking that if the test code made this mistake, real client code might make it as well.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but yeah, I would prefer not to modify src for now.

src/math/Box3.js Outdated
@@ -468,6 +468,12 @@ Object.assign( Box3.prototype, {

translate: function ( offset ) {

if ( ! offset.isVector3 ) {

throw new Error( 'THREE.Box3: .translate() expects a Vector3.' );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here 😇

Copy link
Owner

@mrdoob mrdoob Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind removing this check?
Please, don't modify files in src/ for test PRs.

@@ -150,7 +150,7 @@ Object.assign( Matrix4.prototype, {

}(),

makeRotationFromEuler: function ( euler ) {
makeRotationFromEuler: function ( euler, order ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit ammended - parameter removed.

@OndrejSpanel
Copy link
Contributor Author

As requested - src unmodified again.

I think some static analysis checking for parameter mismatches would be handy, I will be posting more fixes with silly mistakes (tests again), where wrong number of parameters or wrong types are involved. I am not experienced in JS, therefore I have no idea what tooling is available, but I think it is too easy now to make simple mistakes which go undetected.

@mrdoob mrdoob merged commit 17452bb into mrdoob:dev Dec 5, 2017
@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

Thanks!

@OndrejSpanel OndrejSpanel deleted the unitTestFixes branch October 11, 2018 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants