Removed Codes enum; Added functions for H and R matrix generation and unit tests

This commit is contained in:
2022-11-08 12:57:08 +01:00
parent 70c99d2475
commit b4623580af
2 changed files with 251 additions and 180 deletions

View File

@@ -1,12 +1,12 @@
import unittest
import numpy as np
from utility import simulations
from utility import noise
from utility import simulations, noise, codes
class CountBitErrorsTestCase(unittest.TestCase):
"""Test case for bit error counting."""
def test_count_bit_errors(self):
d1 = np.array([0, 0, 0, 0])
y_hat1 = np.array([0, 1, 0, 1])
@@ -25,6 +25,7 @@ class CountBitErrorsTestCase(unittest.TestCase):
# TODO: Is this correct?
class NoiseAmpFromSNRTestCase(unittest.TestCase):
"""Test case for noise amplitude calculation."""
def test_get_noise_amp_from_SNR(self):
SNR1 = 0
SNR2 = 6
@@ -39,5 +40,41 @@ class NoiseAmpFromSNRTestCase(unittest.TestCase):
self.assertEqual(noise.get_noise_amp_from_SNR(SNR5, signal_amp=2), 0.002)
class CodesTestCase(unittest.TestCase):
"""Tests relating to the 'codes' utilities."""
def test_get_systematic_H(self):
# Hamming(7,4) code
G = np.array([[1, 0, 0, 0, 0, 1, 1],
[0, 1, 0, 0, 1, 0, 1],
[0, 0, 1, 0, 1, 1, 0],
[0, 0, 0, 1, 1, 1, 1]])
expected_H = np.array([[0, 1, 1, 1, 1, 0, 0],
[1, 0, 1, 1, 0, 1, 0],
[1, 1, 0, 1, 0, 0, 1]])
H = codes.get_systematic_H(G)
self.assertEqual(np.array_equal(expected_H, H), True)
def test_get_systematic_R(self):
# Hamming(7,4) code
G = np.array([[1, 0, 0, 0, 0, 1, 1],
[0, 1, 0, 0, 1, 0, 1],
[0, 0, 1, 0, 1, 1, 0],
[0, 0, 0, 1, 1, 1, 1]])
expected_R = G = np.array([[1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0]])
R = codes.get_systematic_R(G)
self.assertEqual(np.array_equal(expected_R, R), True)
if __name__ == '__main__':
unittest.main()