Skip to content

Commit e1c098c

Browse files
committed
Seed() displacement to insure test reproducibility
1 parent 74a2a37 commit e1c098c

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

commpy/channelcoding/tests/test_convcode.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
99

1010

11+
def setup():
12+
seed(17121996)
13+
14+
1115
class TestConvCode(object):
1216

1317
@classmethod
@@ -136,6 +140,7 @@ def test_conv_encode_viterbi_decode(self):
136140

137141
for n in range(niters):
138142
msg = randint(0, 2, blocklength)
143+
print(msg)
139144

140145
# Previous tests
141146
for i in range(len(self.trellis)):
@@ -176,6 +181,5 @@ def test_conv_encode_viterbi_decode(self):
176181

177182

178183
if __name__ == "__main__":
179-
seed(17121996)
180184
run_module_suite()
181185

commpy/tests/test_channels.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def check(chan):
4848
err_msg='SISO channel as more than 1 Tx')
4949

5050
def test_fading(self):
51+
# Set seed
52+
seed(17121996)
53+
5154
def check_chan_gain(mod, chan):
5255
msg = choice(mod, self.msg_length)
5356
chan.propagate(msg)
@@ -121,6 +124,9 @@ def check_chan_gain(mod, chan):
121124
err_msg='Wrong channel variance with real channel')
122125

123126
def test_noise_generation(self):
127+
# Set seed
128+
seed(17121996)
129+
124130
def check_noise(mod, chan, corrected_SNR_lin):
125131
msg = choice(mod, self.msg_length)
126132
chan.propagate(msg)
@@ -267,6 +273,9 @@ def __init__(self):
267273
super(TestMIMOFading, self).__init__()
268274

269275
def do(self, nb_tx, nb_rx):
276+
# Set seed
277+
seed(17121996)
278+
270279
def check_chan_gain(mod, chan):
271280
msg = choice(mod, self.msg_length)
272281
chan.propagate(msg)
@@ -408,7 +417,7 @@ def __init__(self):
408417
def do(self, nb_tx, nb_rx):
409418
chan = MIMOFlatChannel(nb_tx, nb_rx, 0)
410419

411-
# Text raising of ValueError
420+
# Test raising of ValueError
412421
with assert_raises(ValueError):
413422
chan.specular_compo(0, -1, 0, 1)
414423
with assert_raises(ValueError):
@@ -429,6 +438,9 @@ def __init__(self):
429438
super(TestMIMONoiseGeneration, self).__init__()
430439

431440
def do(self, nb_tx, nb_rx):
441+
# Set seed
442+
seed(17121996)
443+
432444
def check_noise(mod, chan, corrected_SNR_lin):
433445
msg = choice(mod, self.msg_length)
434446
chan.propagate(msg)
@@ -505,6 +517,9 @@ def __init__(self):
505517
super(TestMIMOkFactor, self).__init__()
506518

507519
def do(self, nb_tx, nb_rx):
520+
# Set seed
521+
seed(17121996)
522+
508523
prod_nb = nb_tx * nb_rx
509524

510525
# Real channel
@@ -533,5 +548,4 @@ def do(self, nb_tx, nb_rx):
533548

534549

535550
if __name__ == "__main__":
536-
seed(17121996)
537551
run_module_suite()

commpy/tests/test_links.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
@dec.slow
1717
def test_link_performance():
18+
# Set seed
19+
seed(17121996)
20+
1821
# Apply link_performance to SISO QPSK and AWGN channel
1922
QPSK = QAMModem(4)
2023

@@ -46,5 +49,4 @@ def receiver(y, h, constellation, noise_var):
4649

4750

4851
if __name__ == "__main__":
49-
seed(17121996)
5052
run_module_suite()

commpy/tests/test_modulation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
@dec.slow
1717
def test_bit_lvl_repr():
18-
# Test the BLR by comparing the performance of a receiver with and without it.
18+
# Set seed
19+
seed(17121996)
1920

21+
# Test the BLR by comparing the performance of a receiver with and without it.
2022
qam = QAMModem(4)
2123

2224
nb_rx = 2
@@ -143,5 +145,4 @@ def do_custom(self, modem):
143145

144146

145147
if __name__ == "__main__":
146-
seed(17121996)
147148
run_module_suite()

commpy/tests/test_sequences.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License: BSD 3-Clause
33

44
from numpy import array
5-
from numpy.random import seed
65
from numpy.testing import run_module_suite, assert_raises, assert_equal
76

87
from commpy.sequences import pnsequence
@@ -20,6 +19,6 @@ def test_pnsequence():
2019
assert_equal(pnsequence(4, (0, 0, 1, 1), array((1, 1, 0, 1)), 7), array((1, 1, 0, 0, 1, 0, 1), int),
2120
err_msg='Pseudo-noise sequence is not the one expected.')
2221

22+
2323
if __name__ == "__main__":
24-
seed(17121996)
2524
run_module_suite()

commpy/tests/test_utilities.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License: BSD 3-Clause
33

44
from numpy import array
5-
from numpy.random import seed
65
from numpy.testing import run_module_suite, assert_array_equal
76

87
from commpy.utilities import dec2bitarray
@@ -15,5 +14,4 @@ def test_dec2bitarray():
1514

1615

1716
if __name__ == "__main__":
18-
seed(17121996)
1917
run_module_suite()

0 commit comments

Comments
 (0)