Skip to content

Commit 597ab21

Browse files
Refactor code for gen_rand_signal_uniform_distributn()
1 parent 47d9438 commit 597ab21

File tree

2 files changed

+383
-3
lines changed

2 files changed

+383
-3
lines changed

source/random_process_models/random_process_generator_tester.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_gen_rand_signal_uniform_distributn():
116116
either -1 or 1 exclusively, and not any other
117117
value (e.g., 0, 1234, or 3.14).
118118
"""
119-
if (k == len(temp_rand_signal)) and (-1 in temp_rand_signal) and (1 in temp_rand_signal) and (not (0 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
119+
if (k == len(temp_rand_signal)) and ((-1 in temp_rand_signal) or (1 in temp_rand_signal)) and (not (0 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
120120
print(prompt .format("OK"))
121121
statistical_analysis.increment_number_test_cases_passed()
122122
else:
@@ -125,13 +125,33 @@ def test_gen_rand_signal_uniform_distributn():
125125
Generated bit vector signal of length k must have k
126126
values/digits.
127127
Each value/digit in the bit vector should also be
128-
either -1 or 1 exclusively, and not any other
128+
either 0 or 1 exclusively, and not any other
129129
value (e.g., 0, 1234, or 3.14).
130130
"""
131131
prompt = " ... Test: type of signal = bit vector. {}"
132132
statistical_analysis.increment_number_test_cases_used()
133133
temp_rand_signal = rand_signal_generator.gen_rand_signal_uniform_distributn(rand_signal_generator.bv_signal,k)
134-
if (k == len(temp_rand_signal)) and (0 in temp_rand_signal) and (1 in temp_rand_signal) and (not (-1 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
134+
if (k == len(temp_rand_signal)) and ((0 in temp_rand_signal) or (1 in temp_rand_signal)) and (not (-1 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
135+
print(prompt .format("OK"))
136+
statistical_analysis.increment_number_test_cases_passed()
137+
else:
138+
print(prompt .format("FAIL!!!"))
139+
## =========================================================
140+
# Method to test the method that generates a bit-vector
141+
# -based discrete-time random signal/process for "n"
142+
# values.
143+
# @param - Nothing
144+
# @return - Nothing.
145+
# O(1) method.
146+
@staticmethod
147+
def test_gen_bit_vector_getrandbits():
148+
# Number of discrete values representing a random signal/"process".
149+
k = 8
150+
print(" Testing gen_rand_signal_uniform_distributn().")
151+
prompt = " ... Test: type of signal = bit vector. {}"
152+
statistical_analysis.increment_number_test_cases_used()
153+
temp_rand_signal = rand_signal_generator.gen_bit_vector_getrandbits(k)
154+
if (k == len(temp_rand_signal)) and ((0 in temp_rand_signal) or (1 in temp_rand_signal)) and (not (-1 in temp_rand_signal)) and (not (3.14 in temp_rand_signal)):
135155
print(prompt .format("OK"))
136156
statistical_analysis.increment_number_test_cases_passed()
137157
else:
@@ -147,3 +167,4 @@ def test_random_signal_generation_methods():
147167
print("")
148168
print("== Testing class: rand_signal_generator.")
149169
rand_signal_generator_tester.test_gen_rand_signal_uniform_distributn()
170+
rand_signal_generator_tester.test_gen_bit_vector_getrandbits()

0 commit comments

Comments
 (0)