-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
Conversation
30e5ccf
to
9641290
Compare
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.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentations not correct here...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/math/Matrix4.js
Outdated
if ( order ) { | ||
|
||
throw new Error( 'THREE.Matrix4: .makeRotationFromEuler() no longer accepts order as the second parameter.' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here...
src/math/Quaternion.js
Outdated
if ( typeof update === 'string' || update instanceof String ) { | ||
|
||
throw new Error( 'THREE.Quaternion: .setFromEuler() no longer accepts order as the second parameter.' ); | ||
} |
There was a problem hiding this comment.
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" ) ); |
There was a problem hiding this comment.
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 ); | |||
} |
There was a problem hiding this comment.
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 );
}
…mEuler, throw on old parameters use.
…ed copy (some fields missing) would pass.
9641290
to
5a6acb6
Compare
src/math/Matrix4.js
Outdated
|
||
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.' ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here 😇
There was a problem hiding this comment.
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.
src/math/Matrix4.js
Outdated
@@ -150,7 +150,7 @@ Object.assign( Matrix4.prototype, { | |||
|
|||
}(), | |||
|
|||
makeRotationFromEuler: function ( euler ) { | |||
makeRotationFromEuler: function ( euler, order ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit ammended - parameter removed.
b594ec6
to
9a0de32
Compare
As requested - 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. |
Thanks! |
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.