How does one unit test an algorithm

Posted by Asa Baylus on Programmers See other posts from Programmers or by Asa Baylus
Published on 2012-06-09T11:35:35Z Indexed on 2012/06/09 16:46 UTC
Read the original article Hit count: 272

I was recently working on a JS slideshow which rotates images using a weighted average algorithm. Thankfully, timgilbert has written a weighted list script which implements the exact algorithm I needed. However in his documentation he's noted under todos: "unit tests!".

I'd like to know is how one goes about unit testing an algorithm. In the case of a weighted average how would you create a proof that the averages are accurate when there is the element of randomness?

Code samples of similar would be very helpful to my understanding.

© Programmers or respective owner

Related posts about JavaScript

Related posts about algorithms