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

Add tests for input methods. #42

Merged
merged 4 commits into from
Mar 4, 2016
Merged

Conversation

toolness
Copy link
Contributor

This adds tests for the input methods in p5.play. I actually used it to ensure that #28 didn't cause regressions. 😁

However, I think I might have also uncovered a bug. The documentation for keyDown states:

Like p5 keyIsDown but accepts strings and codes

However, the implementation is checking to see if the internal key state is specifically equal to KEY_IS_DOWN. The problem is that the internal keystate might actually be KEY_WENT_DOWN, in which case the method will retrun false but keyIsDown() will be true!

It's understandable that no one has noticed this, because it just means that the result of keyDown will be inconsistent with keyIsDown for only the frame in which the key went from up to down.

A parallel problem exists with mouseDown/mouseIsDown.

@islemaster is this something you think we should change? And does the test suite look OK overall?


function mouseup(which) {
myp5._setProperty('mouseButton', which);
myp5._setProperty('mouseIsPressed', false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is using internal p5 methods, it may break when we upgrade the version of p5.js in the repository. Same goes for the use of _onkeydown and _onkeyup a few lines down.

@islemaster
Copy link
Contributor

I knew about this. I definitely want to fix it so keyDown and keyWentDown
are not mutually exclusive states. I figured it wouldn't happen soon
though, since it's technically a breaking change. I also want to check
whether @molleindustria did this on purpose, to circumvent a certain set of
beginner mistakes.

If we had a release process and semver I would bundle this with other
breaking changes in a major version. Since things are still pretty fast and
loose (and I don't think anyone auto-updates this library?) maybe we can
just fix it.

mousedown(LEFT);
nextFrame();

expect(myp5.mouseWentDown(LEFT)).to.be.true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like for this test to cover the behavior of mouseWentDown properly it needs to run a third frame (as the mouseDown test does above) and show that mouseWentDown goes back to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, just added that in d5cc6fb.

@toolness
Copy link
Contributor Author

Ok, it looks like there are enough concerns about the fix for the bug that I'm just spinning it off into #43 and we can deal with it later!

expect(myp5.mouseWentDown(LEFT)).to.be.true;

mouseup(LEFT);
nextFrame();
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't quite what I meant. With the expected behavior of mouseWentDown the mouseUp(LEFT) call here shouldn't be necessary for mouseWentDown(LEFT) to be false on the next frame. I was hoping the tests would illustrate this behavior:

Frame Event mouseWentDown mouseDown
1 up false false
2 down true false
3 -- false true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes, of course! Sorry about that, I think I just fixed this.

@islemaster
Copy link
Contributor

Looks good!

@toolness
Copy link
Contributor Author

toolness commented Mar 4, 2016

Woot thanks!

toolness added a commit that referenced this pull request Mar 4, 2016
Add tests for input methods.
@toolness toolness merged commit 0906223 into quinton-ashley:master Mar 4, 2016
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.

2 participants