in reply to Re: Object functionality?
in thread Object functionality?

Seriously, it sounds strange, but it really works well. Try it.

matts++

Better advice rarely given. I did this too and it paid off big time.

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.

Replies are listed 'Best First'.
Re: Re: Re: Object functionality?
by theguvnor (Chaplain) on May 10, 2002 at 17:00 UTC

    Anyone have any links to good tutorials on how one goes about using this approach? I mean it sounds like a fine idea, but (not being a CS type myself) I wouldn't know where to begin....

    ..Jon

    Update: OK, so I guess the answer (thanks to demerphq++) is to look up the Test::More module. THanks!

      Well I dont have links but I can make some suggestions.

      If you're writing a module you must have some idea of what you want it to do and how you are going to call its functions/methods/procedures. From that point its just a matter of painting a picture as it were. So for instance I knew for Data::BFDump that I was going to implement the Data::Dumper interface, but with different output. So I sat down and wrote a bunch of tests. Something like this:

      use Test::More qw(noplan); use Data::BFDump; is(Data::BFDump->Dump([1..10]),"( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )","Ba +sic list"); is(Data::BFDump->Dump([\1]),"\do{ my $t=1 }","Scalar Ref");
      And so on. Thus you put down what and how you'd like to call a routine and what youd like it to return. If you dont actually have the functionality then you wrap it in a TODO like so:
      TODO:{ local $TODO="Not implemented yet"; is(Data::BFDump->Dump([1..10]),"( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )"," +Basic list"); is(Data::BFDump->Dump([\1]),"\do{ my $t=1 }","Scalar Ref"); }
      As you build up more an more tests you also build up more and more functionality.

      Oh, a little note: Some changes you make will break every test that you came up with. Thats ok. Just go through and make sure the results are what you want and change the expected results. But keep the tests. The more the better.

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

      A not so bad idea is to simply do a Google search for unit tests, and browse around there for a while. Also, check up on any stuff by Martin Fowler (especially Refactoring) and Kent Beck. Furthermore, http://www.junit.org/ is a veritable gold mine for unit testing, although most things there are exemplified in Java, it shouldn't be hard to follow. It probably would if it was the other way around though. :)
      You have moved into a dark place.
      It is pitch black. You are likely to be eaten by a grue.
      Mike Schwern of P5P testing fame has a Wiki site which contains quite a good intro to the testing modules.