GMTROM/Python_Tests/Main.py

87 lines
2.6 KiB
Python
Raw Permalink Normal View History

2023-05-16 13:46:08 +02:00
from TotOnline import TotOnline
from StartUpTest import StartUPTest
class Main:
def __init__(self):
print("Main class instantiated")
2023-05-22 11:15:05 +02:00
def process_data_in_chunks(data, chunk_size=1000000):
chunks = [data[i:i+chunk_size] for i in range(0, len(data), chunk_size)]
return chunks
2023-05-16 13:46:08 +02:00
if __name__ == "__main__":
2023-05-22 11:15:05 +02:00
filename = "resources/SmallTest.txt"
2023-05-16 13:46:08 +02:00
with open(filename, "rb") as f:
binary_data = f.read().strip()
with open(filename, "rb") as f:
byte_data = f.read().strip()
2023-05-22 11:15:05 +02:00
print("Run all StartUPTests")
binary_chunks = process_data_in_chunks(byte_data)
first_chunk = binary_chunks[0]
result = StartUPTest.run_all_tests(first_chunk)
print(result)
print("Run all TotOnline tests")
binary_chunks = process_data_in_chunks(byte_data)
first_chunk = binary_chunks[0]
result = TotOnline.run_all_tests(first_chunk)
print(result)
# Call the StartUpTest
2023-05-16 13:46:08 +02:00
print("StartUp:")
2023-05-22 11:15:05 +02:00
binary_chunks = process_data_in_chunks(byte_data)
first_chunk = binary_chunks[0]
result = StartUPTest.monobit_test(first_chunk)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])
2023-05-22 11:15:05 +02:00
result = StartUPTest.chi_square(first_chunk)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])
print("Chi2_statistic", result[2])
2023-05-22 11:15:05 +02:00
# Call the TotalFailure-Test
2023-05-16 13:46:08 +02:00
print("Total Failure:")
2023-05-22 11:15:05 +02:00
byte_chunks = process_data_in_chunks(byte_data)
first_chunk = byte_chunks[0]
result = TotOnline.total_failure_test(first_chunk, pattern_length=10)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])
2023-05-22 11:15:05 +02:00
# Call the Online Test
2023-05-16 13:46:08 +02:00
print("Monobit:")
2023-05-22 11:15:05 +02:00
byte_chunks = process_data_in_chunks(byte_data)
first_chunk = byte_chunks[0]
result = TotOnline.monobit_test(first_chunk)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])
print("Block Frequency:")
2023-05-22 11:15:05 +02:00
byte_chunks = process_data_in_chunks(byte_data)
first_chunk = byte_chunks[0]
result = TotOnline.block_frequency_test(first_chunk)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])
print("Run:")
2023-05-22 11:15:05 +02:00
byte_chunks = process_data_in_chunks(byte_data)
first_chunk = byte_chunks[0]
result = TotOnline.run_test(first_chunk)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])
print("Longest Run:")
2023-05-22 11:15:05 +02:00
byte_chunks = process_data_in_chunks(byte_data)
first_chunk = byte_chunks[0]
result = TotOnline.longest_one_block_test(first_chunk)
2023-05-16 13:46:08 +02:00
print("p_value:", result[0])
print("test passed (p_value >= 0.01):", result[1])