Re: Testing a class which utilizes randomness
Nikola Novak <[email protected]> Sat, 5 Apr 2014 00:53:54 +0200
| Newsgroups | gmane.comp.programming.test-driven-development |
|---|---|
| Message-ID | <CA+AeE3bEooR_BdWztfauzCcVJgfvu6ogzb5VKvHU_JZ60ja8qA@mail.gmail.com> |
Hello! Thanks everyone for your replies. Like I said, I'm not testing the RNG (or RSG in this case), but rather the algorithm which deals with duplicates. I'll go with what David and John suggested, writing a class to generate unique random strings and injecting a random string generator. Interesting how a TDD approach resulted in code being organized properly. If I hadn't used it, I'd probably have written a method that used an embedded random string generator and would never have given the problem a second thought. Thanks for the help, Nikola On Fri, Apr 4, 2014 at 8:52 PM, Steven Gordon <[email protected]> wrote: > > > Agreed. > > Already suggested that the" history" object is what needs to be TDD-ed. > > The fact that randomness is not a good candidate for TDD-ing is just an > interesting side-note. > > > On Fri, Apr 4, 2014 at 11:50 AM, Ron Jeffries <[email protected]> wrote: > >> >> >> I'm pretty sure OP is trying to learn how to TDD, not how to create >> really great random strings. >> :) >> R >> >> On Apr 4, 2014, at 2:48 PM, Steven Gordon <[email protected]> wrote: >> >> This project is presumably using an RNG rather than coding one. >> >> The criteria that matters would be whether the strings being generated >> (using an RNG) is sufficiently random, not whether the sequence of numbers >> that are being used to generate those strings are sufficiently random. >> >> It is quite possible for the RNG to be random enough, but the strings to >> not be. For example, the long term behavior of the random number generator >> could always create a nice random distribution on bins, but that >> subsequences are not as random. If each string would be created by a >> subsequence rather than individual number, then they would not be random >> enough. >> >> It could make a difference whether or not the size of the character set >> is prime. >> >> >> >> Ron Jeffries >> www.XProgramming.com <http://www.xprogramming.com> >> I know we always like to say it'll be easier to do it now than it >> will be to do it later. Not likely. I plan to be smarter later than >> I am now, so I think it'll be just as easy later, maybe even easier. >> Why pay now when we can pay later? >> >> > >