Code Comments
Programming Forum and web based access to our favorite programming groups.In order to try "test-driven programming", I wanted to implement some statistical functions. Normal law, Binomial law... First of all, I should write tests for this function and then... How can I test functions which are aimed to send random results ? May I send to test functions "pseudo-random" numbers and see if the result is conform to what I expected ? Thks for your answers and happy new year, Emmanuel C. France (thousands of 'scuse for my frenglish).
Post Follow-up to this messageEmmanuel, > Emmanuel C. > France (thousands of 'scuse for my frenglish). Try asking the same question on the French XP mailing list as well: http://fr.groups.yahoo.com/group/xp-france/ Laurent
Post Follow-up to this messageEmmanuel Champommier wrote: > In order to try "test-driven programming", I wanted to implement some > statistical functions. Normal law, Binomial law... > First of all, I should write tests for this function and then... How can I > test functions which are aimed to send random results ? May I send to test > functions "pseudo-random" numbers and see if the result is conform to what I > expected ? > > Thks for your answers and happy new year, Mock Object-a test fixture passed into the tested code as a placeholder for a Production Code object. Mock methods log what the calling code does to them, and return prefabricated values. Use a Mock to test. * what time is it * releasing resources * pseudo-random numbers * without excessive side effects (such as MessageBox()) * expensive or slow hardware * modules that depend on modules that don't exist yet, which you can't start * 3rd party modules that can't Get everything they Set * threads, semaphores, and other asynchronicities * responses to failing system calls. -- Phlip http://industrialxp.org/community/b...tUserInterfaces
Post Follow-up to this messageLaurent Bossavit wrote: > Emmanuel, > > > Try asking the same question on the French XP mailing list as well: > http://fr.groups.yahoo.com/group/xp-france/ /No! Il ne marche pas! Les Francais sont plus resistant de ... logique!/ (Sorry, LB, but you could go hold Americans up as a paragon of rationality...;) -- Phlip http://industrialxp.org/community/b...tUserInterfaces
Post Follow-up to this message"Emmanuel Champommier" <champommier@noos.fr> writes:
> In order to try "test-driven programming", I wanted to implement some
> statistical functions. Normal law, Binomial law...
> First of all, I should write tests for this function and then... How can I
> test functions which are aimed to send random results ? May I send to test
> functions "pseudo-random" numbers and see if the result is conform to what
I
> expected ?
This may not be the best place to start.
It's not clear to me how the "baby-steps" aspect of TDD
comes into play when your just implementing a well-known
algorithm. The tests I'd write for something like this
are a lot closer to acceptance tests than unit tests. A
simple example:
public class RandomTest extends junit.framework.TestCase {
int trials = 10000;
float acceptableError = .01;
public void testBernoulli() {
float p = 0.5;
RandomGenerator bg = new BernoulliGenerator(p);
int counter = 0;
for (int i=0;i<trials;++i) {
counter += bg.next();
}
assertEquals(0,(counter/trials)-p, acceptableError);
}
}
(Is it obvious to everyone that this code was only
written, and not compiled? Good.)
Actually, though, now that I write down this example,
I want factor out the p variable, and start writing
tests for a couple of different values of p...closer
to unit tests after all.
I'm not sure whether I've cleared anything up or not.
You tell me.
--
Mark Jeffcoat
Austin, TX
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.