Back to index

python-biopython  1.60
test_HotRand.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """Tests HotRand.
00003 """
00004 # standard library
00005 import sys
00006 import unittest
00007 
00008 # local stuff
00009 import requires_internet
00010 requires_internet.check()
00011 
00012 from Bio.HotRand import HotRandom
00013 
00014 
00015 # --- helper classes and functions
00016 
00017 def are_items_in_range( a, high, low ):
00018     for j in range( 0, len( a ) ):
00019         if( a[ j ] > high ):
00020             print 'a[ %d ] is %d' % ( j , a[ j ] )
00021             return 0
00022         if( a[ j ] < low ):
00023             print 'a[ %d ] is %d' % ( j , a[ j ] )
00024             return 0
00025     return 1
00026 
00027 # --- the actual test classes
00028 
00029 class RandomSequenceTest(unittest.TestCase):
00030     """Test sequence of random numbers.
00031     """
00032 
00033     def test_get_random_range(self):
00034         """Get a sequence of random numbers.
00035         """
00036         return
00037         rand_seq = []
00038         hot_random = HotRandom()
00039         for j in range( 0, 200 ):
00040             rand_num = hot_random.hot_rand( 91, 37 )
00041             rand_seq.append( rand_num )
00042         assert are_items_in_range( rand_seq, 91, 37 ) , "Got an out of range number"
00043         rand_seq = []
00044         for j in range( 0, 200 ):
00045             rand_num = hot_random.hot_rand( 19, 0 )
00046             rand_seq.append( rand_num )
00047         assert are_items_in_range( rand_seq, 19, 0 ) , "Got an out of range number"
00048         rand_seq = []
00049         for j in range( 0, 200 ):
00050             rand_num = hot_random.hot_rand( 61, 4 )
00051             rand_seq.append( rand_num )
00052         assert are_items_in_range( rand_seq, 61, 4 ) , "Got an out of range number"
00053 
00054 if __name__ == "__main__":
00055     runner = unittest.TextTestRunner(verbosity = 2)
00056     unittest.main(testRunner=runner)