Pages: 1
Hi,
I used the "test driven development" method to implement a sudoku solver in Scratch. It is a variant of the "test first" approach from extreme programming, which is one of the popular agile software development methods currently en vogue.
With this method one uses so called "unit tests", which are so-called "white box test", as one knows the internals of the actual code when writing them. "Test first" means that one writes the test *before* writing the actual target code itself. Of course this is done in small steps, with lots of refactoring in between. And each time the tested code works, one saves a version so that it is always possible to come back to a working version. That's why the program is named sudoku_53 ;-)
There are also functional test (grey or black box test) also written before implementing the actual code, and even some interactive tests for issues that are difficult to test automatically, such as correct behavior of the user interface.
All tests are run if one presses "t" instead of the green flag after loading the program in Scratch.
As there are a lot of computations, it is worthwhile to run the code in Turbo mode. How to enter turbo mode is explained in case it is not set when starting the test suite or the program itself. The usage of the program should be self-explanatory.
All these tests serve several functions that of course also include checking for correctness with respect to the specification, but additionally serve as an explanation to what the actual code does. I tried hard to write all the code, both the test code as well as the actual target code, as readably as possible so that it is easy to understand, to refactor, and also to extend. There are also many comments that explain how the code could be enhanced and some of the reasons for doing certain things in a certain way, but no comments explain what the actual code does. The reason for the latter is that descriptions of code behavior written in prose tend to become obsolete, whereas the code itself is the ultimate reference to what it actually does.
Here's a link to the classic book about the test driven development method:
http://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530/
And to the wikipedia page:
http://en.wikipedia.org/wiki/Test-driven_development
And here is the link to sudoku_53:
http://scratch.mit.edu/projects/hej_wickie_hej/1001809
Regards,
Wolfgang
Last edited by hej_wickie_hej (2010-05-09 20:26:30)
Offline
Pages: 1