4 ms·
I find this kind of testing incredibly useless. All he did was take the implementation of update-all and do the same thing again for the test! Basically all he
by grogers 16y ago
I find this kind of testing incredibly useless. All he did was take the implementation of update-all and do the same thing again for the test! Basically all he is doing is checking that clojure's map function works. When your unit test says the same thing as the thing you are testing, I think it's pretty obvious you've failed somewhere.
The most important thing to test here is that the accumulate-forces (and by extension calculate-forces-on-all) function gives the right values, that is what you need to be testing. There are even several ways to do that without just plugging in magic numbers - for example you can generate random inputs and verify that the vector sum of all forces is 0 (I think this would be correct because gravity acts on two objects equal and opposite). You can verify the higher level functions by checking that momentum and energy are conserved.
- technomancy 16y agoYeah, I think this attitude is just a side-effect of being new to FP and wanting to cling to familiar techniques. I certainly felt the same way getting started. Then once you read the Out of the Tarpit paper you get over it and start to trust referential transparency.
- DanielBMarkham 16y agoGreat paper -- I hadn't heard of it. I read the abstract and a lot of feelings I've had about testing in FP coalesced: I knew this intuitively but wasn't able to put it into words. Codd can be your pair-testing buddy for a LOT of FP testing.