Home > Archive > Extreme Programming > January 2005 > Newbie question : how to test random functionnalities...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newbie question : how to test random functionnalities...
|
|
| Emmanuel Champommier 2005-01-02, 3:56 pm |
| 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).
| |
| Laurent Bossavit 2005-01-02, 8:56 pm |
| Emmanuel,
> 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
| |
|
| Emmanuel 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
| |
|
|
| Mark Jeffcoat 2005-01-07, 3:57 am |
| "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
|
|
|
|
|