Where did you learn to unit test? How did you learn?

Andrew Dalke adalke at mindspring.com
Fri May 2 19:38:45 EDT 2003


Steven Taschuk
> Dijkstra, incidentally, advocated a correctness-by-construction
> approach which has some interesting analogies to test-driven
> development.  For example, he even advocated writing the proof
> first, then writing the program to satisfy the assumptions of the
> proof.  (Obviously this would be done incrementally in practice.)

I was implementing a graph algorithm once.  I wrote out the
proof (one upon a time I got a math degree) over several days,
to make sure I understood how it was supposed to work.

I then translated the proof to Python.  I recall a couple
issues:

   - it took several days to track down a bug where I used
       a "continue" instead of a "break".  Or maybe it was the
       other way around.  In any case, it was an optimization
       not included in the proof.

  - I needed some instrumentation via callbacks to watch
      was was going on and allow a controller to say "it's
      been 10 seconds, so give be the best answer to date"
      Again, not in the proof because I didn't include time.

  - We needed to chain the algorithm so that a solution of
      one graph comparison was used at the basis for the
      next graph comparison.  (We wanted the maximum
      common substructure of a set of graphs built on top
      of our pairwise algorithm.)  Python didn't have generators
      so we emulated it on threads.  Whereas the proof was
      simple since we could just say "use the solution for the
      next pairwise comparison."

The way we validated the algorithm was to compare it
against a genetic algorithm and ensure that we always found
solutions at least as good as the GA.  Though sometimes
it took a lot longer.

I suppose it is possible to have the proof include these
factors, but it's beyond my abilities.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list