100 Days of Code Day 35
Today’s exercise was list ops which was to implement list functions without using the higher order operations or built in functions of similar use. I started off on this one all wrong. I think this example shows why encapsulation is good. If the tests didn’t have access to internals they would have had to be written different. Then they would not have failed me when my implementation had the desired interface but different internals.
For my implementation I started off wanting to dust of the double-linked list class I did recently. I started adding all kinds of support function to go along with it, but everything was failing in the tests.
The equality test was failing. I tried making an operator= override but apparently Javascript doesn’t support that.
I got to where it was checking .values. I tried adding a function called values() but no, that isn’t right. Looking closer, values is a property not a method. I puzzled a bit more and realized the test was demanding that I put the values in an array called values.
I had to tear the whole thing down and basically start over because my implementation didn’t match the one expected by the test cases. The test cases should not be peeking at implementation specific data. If you do that, all the tests break when the implementation changes. It also shows that your documentation matters, if the problem specified how the data should be stored I could have at least saved a lot of time.
For the sound chapter I did the envelope, sweep, and continuous examples. There is one more channel 1 demo called ch1_full_test I will work on tomorrow. I also refactored my makefile and it is much better now.
