Re: Testing a class which utilizes randomness
"Tim Ottinger [email protected] [testdrivendevelopment]" <[email protected]> Wed, 4 Jun 2014 14:28:25 -0500
| Newsgroups | gmane.comp.programming.test-driven-development |
|---|---|
| Message-ID | <CAN2NSt=RUNAjqSTUEhHEynAcj_sDs1u2VcW_q7=BDT--CGtgaA@mail.gmail.com> |
> > no two strings are ever the same. >> > > Ever? Is that even possible? > What does close enough mean? Can they be UUIDs and GUIDs and be "close enough"? Or do they need to be *random* and non-repeating? > What I want to test is exactly this behavior - the code which discards the >> duplicate and forces the string to be regenerated. To test that, I need to >> force the random string generator to return a duplicate at least once (but >> finite number of times). To create the test which would generate strings >> until there's at least one duplicate is unrealistic, because such a test >> could take a very long time to complete. >> >> How would I write such a test? >> > by separating concerns. You have string generation. You have duplicate rejection. You can test duplicate rejection with a mock string generator. You can test randomness of string generations.... aw, heck, looks like you need stats and algo gurus. Math, not a billion unit tests for the algorithm. -- Tim Ottinger, Sr. Consultant, Industrial Logic ------------------------------------- http://www.industriallogic.com/ http://agileinaflash.com/ http://agileotter.blogspot.com/