p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

Adding test for envelope class

Open iRohitSingh opened this issue 4 years ago • 5 comments

@therewasaguy can you please! review this :)

iRohitSingh avatar Mar 24 '21 21:03 iRohitSingh

This doesn't need to happen as part of this PR, but I would love to see us take testing of this class to the next level.

Under the hood, an Envelope changes the value of a Web Audio API AudioParam) over time, using methods described here that schedule the changes on the Web AudioContext clock https://developer.mozilla.org/en-US/docs/Web/API/AudioParam#methods .

How can we truly test that we are producing this behavior?

One option: use a method like getValueAtTime to get the value of the audio param at some point in the future. Unfortunately there isn't a native way to do this in the Web Audio API. but Tone.JS has implemented this method and we already have a dependency on it, and/or we could introduce a dependency on this library (which I haven't tried)

Another option: we could use a p5.Recorder to record audio output snippets and then compare the values of the resulting audio buffers to make sure they are what we expect. This might be prone to flakiness, I haven't tried it recently but I believe that Tone.JS took this approach for unit tests at some point at least (perhaps before coming up with the getValueAtTime method which is really useful!)

therewasaguy avatar Mar 28 '21 18:03 therewasaguy

@therewasaguy thank you for the guidance :) will try to resolve all the issues as soon as possible and make this pr mergable :)

iRohitSingh avatar Mar 30 '21 17:03 iRohitSingh

@therewasaguy I fixed everything you mention. I will try to use the tone.js library for testing the class as you mentioned. is there anything left in this pr?

iRohitSingh avatar Apr 17 '21 21:04 iRohitSingh

@iRohitSingh you can use beforeEach() and afterEach() hook to initiate and dispoe the envelope instance

endurance21 avatar Apr 26 '21 05:04 endurance21

@therewasaguy i think we should merge this one before #608 it can be used to test that pr

endurance21 avatar Apr 26 '21 05:04 endurance21

Thanks @Abhijay007! Agreed, looks like this class is pretty well-tested on the main branch right now. I'm going to close this PR, but feel free to open another if you feel like there's something current test suite can benefit from adding!

davepagurek avatar Jan 04 '23 00:01 davepagurek