So... what do you do when you're testing functions that should return random things?
You test...
ambs on 2004-11-08T11:07:49
- return type (integers, strings,...)
- type domain (integers bellow a number, strings with a specific size, etc)
Re:You test...
cog on 2004-11-08T11:23:47
Those are good ideas.
I am already testing if the output is undefined or not, depending on the input parameters.
Anything else? :-)
Tie::Hash::Cannabinol
Beatnik on 2004-11-08T11:39:56
If I'm not mistaking, Dave won a bid at an auction to have tests written for
Tie::Hash::Cannabinol by Schwern. The results were mentioned during one of the last YAPCs. Maybe you can convince Schwern to do it for one of your modules?
:)
Re:Tie::Hash::Cannabinol
cog on 2004-11-08T12:00:08
Well... he *is* coming to Portugal...
However, I think I'd like to see those tests before that conference, so I guess I'll have to think something up :-)
Re:Tie::Hash::Cannabinol
davorg on 2004-11-08T13:36:46
Schwern's tests for THC are here.
He also wrote a comment somewhere on use.perl which explained how he came up with them - but I can't find that now.
re: Random Testing
hctif on 2004-11-08T11:42:27
Test it lots of times, gather the results, and see if they are likely to be random:
http://search.cpan.org/user/dcantrell/Statistics-ChiSquare-0.5/lib/Statistics/ChiSqu are.pm
Re: Random Testing
cog on 2004-11-08T12:00:46
This is an interesting idea too :-)
Anyone else? :-) (this is getting interesting)
Whitebox testing
jplindstrom on 2004-11-08T12:31:58
You could whitebox test the function to see that it behaves correctly internally.
I wrote a
journal entry about Test::MockObject that touches this.
srand(1)
domm on 2004-11-08T12:57:54
This will only work if you're generating random results yourself, obvisouly. But it's such a nice idea... (I use it for filling DBs with test-data thats random, but still allways the same)
From perldoc -f srand:
You can call srand($seed) with the same $seed to reproduce the same sequence from rand(), but this is usually reserved for generating predictable results for testing or debugging