473,769 Members | 6,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2735
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 cryptographical ly
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 RNGCryptoServic eProvider class.

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

"Ethan Strauss" <Et**********@d iscussions.micr osoft.comwrote in message
news:4E******** *************** ***********@mic rosoft.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
3689
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 writing the real functional code. My application manipulates graphs. I first write the skeleton in Python, then convert it to C++ for high performance (some graphs can have millions of nodes.)
3
2083
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 function, I'd enlist all the conditions that must be met for a contract to be valid. Something along the lines of:
72
5276
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: http://geosoft.no/development/unittesting.html Thanks.
0
1501
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 Unit Test is to provide testing data, so it can travel WITH the Unit test. As such, I don't want to have to hard code a path to an MDF file. i.e., I want to be able to do something like with the AttachDbFilename -
176
8458
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 their own unit test framework, and then in a lab session see if I can get them to write their own. To give them an example I've created the following UTF class (with a simple test program following). I would welcome and suggestions on how anybody...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.