473,326 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Unit testing something which is supposed to be random?

Hi,
I have a method which produces a random DNA sequence. I would like to
write a unit test for it, but can't quite figure out what makes sense. It is
easy to test that a DNA sequence is produced. What I can't figure is
randomness. By it's very nature random is random. I have written a simple
test that generates 500 sequences and checks that none of them are the same.
That works, but seems very weak besides, if the sequences are truly random,
the same one should be generated occasionally. I can imagine that I could
create thousands of sequences and then do statistics on them to see if they
are random, but I don't want to go there. Any other thoughts about what to
do?
Thanks!
Ethan

Jan 14 '08 #1
3 2719
Ethan Strauss wrote:
I have a method which produces a random DNA sequence. I would like to
write a unit test for it, but can't quite figure out what makes sense. It is
easy to test that a DNA sequence is produced. What I can't figure is
randomness. By it's very nature random is random. I have written a simple
test that generates 500 sequences and checks that none of them are the same.
That works, but seems very weak besides, if the sequences are truly random,
the same one should be generated occasionally. I can imagine that I could
create thousands of sequences and then do statistics on them to see if they
are random, but I don't want to go there. Any other thoughts about what to
do?
I think you can only do two things:
- verify that it given a specific initialization of the RNG
produces the correct result
- do a simulation with millions of runs and check the statistics

Arne
Jan 14 '08 #2
Ethan,

Well, it seems like you want a random distribution which is even as
well.

Statistics here don't really test how random a generator is, it tests to
see that the distribution is even (which is different from random).

Rather, I think if you truly want to test to see if something is random,
you need to try and predict what the sequence generator will develop given
the current conditions. If your code can do that, then it is not random.

How are you generating the random number sequences? To be honest, I
don't know if you have to test for this if you are using a cryptographically
secure number generator. That's not to say that they are not predictable at
all, but they are MUCH less predictable than the Random implementation.

You want to make sure you are using the RNGCryptoServiceProvider class.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ethan Strauss" <Et**********@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
Hi,
I have a method which produces a random DNA sequence. I would like to
write a unit test for it, but can't quite figure out what makes sense. It
is
easy to test that a DNA sequence is produced. What I can't figure is
randomness. By it's very nature random is random. I have written a simple
test that generates 500 sequences and checks that none of them are the
same.
That works, but seems very weak besides, if the sequences are truly
random,
the same one should be generated occasionally. I can imagine that I could
create thousands of sequences and then do statistics on them to see if
they
are random, but I don't want to go there. Any other thoughts about what to
do?
Thanks!
Ethan

Jan 14 '08 #3
Thanks,
For what I need it sounds like I should just test for the appearance of
randomness and not even try to validate that they really truely are random.
This question was more for curiosity than it was for a critical need. If I do
need to test the randomness at a deeper level, I will probably try to
generate enough random sequences to be able to do appropriate statistics and
then I'll also have to figure out the stats involved.

Ethan
Jan 15 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than...
3
by: Water Cooler v2 | last post by:
Here's my understanding as of now. If I were writing a function bool IsValidContact(Offerer objOfferer, Accepter objAccepter, TermsAndConditions objTermsAndConditions); Before writing the...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
0
by: porko | last post by:
Does anyone know if there is some way to specify a RELATIVE path to an .MDF file for testing with the Team Unit Testing stuff in Visual Studio 2005? The whole point of including a database with a...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.