summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python
diff options
context:
space:
mode:
authorJohnathan Corgan <johnathan@corganlabs.com>2015-10-07 13:39:08 -0700
committerJohnathan Corgan <johnathan@corganlabs.com>2015-10-07 13:39:08 -0700
commitac409c6b114680d8569141178cfe60b41d68d976 (patch)
tree4877972f4ecc240d77bbf012ecd77bdd3506411a /gnuradio-runtime/python
parentc8342fd9aed8ed1bcf0062dc02637ad11269642e (diff)
parentb1883cb00cdb7c9d9d24cd48bf3127ff4aa547ae (diff)
Merge branch 'master' into next
Diffstat (limited to 'gnuradio-runtime/python')
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/qa_random.py44
1 files changed, 29 insertions, 15 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_random.py b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
index 83fee56181..d3e5410454 100644
--- a/gnuradio-runtime/python/gnuradio/gr/qa_random.py
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
@@ -23,8 +23,8 @@
from gnuradio import gr, gr_unittest
import numpy as np
-class test_random(gr_unittest.TestCase):
+class test_random(gr_unittest.TestCase):
# NOTE: For tests on the output distribution of the random numbers, see gnuradio-runtime/apps/evaluation_random_numbers.py.
# Check for range [0,1) of uniform distributed random numbers
@@ -38,27 +38,41 @@ class test_random(gr_unittest.TestCase):
self.assertLess(value, 1)
self.assertGreaterEqual(value, 0)
- # Check reseed method (init with time and seed as fix number)
- def test_2(self):
+ # Same seed should yield same random values.
+ def test_2_same_seed(self):
num = 5
-
- rndm0 = gr.random(42); # init with time
- rndm1 = gr.random(42); # init with fix seed
+ # Init with fixed seed.
+ rndm0 = gr.random(42)
+ rndm1 = gr.random(42)
for k in range(num):
- x = rndm0.ran1();
- y = rndm1.ran1();
- self.assertEqual(x,y)
+ x = rndm0.ran1()
+ y = rndm1.ran1()
+ self.assertEqual(x, y)
+ # reseed should yield same numbers.
+ def test_003_reseed(self):
+ num = 5
x = np.zeros(num)
y = np.zeros(num)
- rndm0 = gr.random(42); # init with fix seed 1
+ rndm = gr.random(43) # init with fix seed 1
for k in range(num):
- x[k] = rndm0.ran1();
- rndm1.reseed(43); # init with fix seed 2
+ x[k] = rndm.ran1()
+ rndm.reseed(43) # init with fix seed 2
for k in range(num):
- y[k] = rndm0.ran1();
- for k in range(num):
- self.assertNotEqual(x[k],y[k])
+ y[k] = rndm.ran1()
+ self.assertFloatTuplesAlmostEqual(x, y)
+
+ def test_004_integer(self):
+ nitems = 100000
+ minimum = 2
+ maximum = 42
+ rng = gr.random(1, minimum, maximum)
+ rnd_vals = np.zeros(nitems, dtype=int)
+ for i in range(nitems):
+ rnd_vals[i] = rng.ran_int()
+ self.assertGreaterEqual(minimum, np.min(rnd_vals))
+ self.assertLess(np.max(rnd_vals), maximum)
+
if __name__ == '__main__':
gr_unittest.run(test_random, "test_random.xml")