Added unit tests for soft decision decoder
This commit is contained in:
parent
c90cddf30b
commit
26fa791872
55
sw/test/test_soft_decision.py
Normal file
55
sw/test/test_soft_decision.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import unittest
|
||||||
|
import numpy as np
|
||||||
|
from decoders import naive_soft_decision
|
||||||
|
|
||||||
|
|
||||||
|
class CodewordGenerationTestCase(unittest.TestCase):
|
||||||
|
def test_codeword_generation(self):
|
||||||
|
"""Test case for data word and code word generation."""
|
||||||
|
# Hamming(7,4) code
|
||||||
|
G = np.array([[1, 1, 1, 0, 0, 0, 0],
|
||||||
|
[1, 0, 0, 1, 1, 0, 0],
|
||||||
|
[0, 1, 0, 1, 0, 1, 0],
|
||||||
|
[1, 1, 0, 1, 0, 0, 1]])
|
||||||
|
H = np.array([[1, 0, 1, 0, 1, 0, 1],
|
||||||
|
[0, 1, 1, 0, 0, 1, 1],
|
||||||
|
[0, 0, 0, 1, 1, 1, 1]])
|
||||||
|
|
||||||
|
decoder = naive_soft_decision.SoftDecisionDecoder(G, H)
|
||||||
|
|
||||||
|
expected_datawords = np.array([[0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 1],
|
||||||
|
[0, 0, 1, 0],
|
||||||
|
[0, 0, 1, 1],
|
||||||
|
[0, 1, 0, 0],
|
||||||
|
[0, 1, 0, 1],
|
||||||
|
[0, 1, 1, 0],
|
||||||
|
[0, 1, 1, 1],
|
||||||
|
[1, 0, 0, 0],
|
||||||
|
[1, 0, 0, 1],
|
||||||
|
[1, 0, 1, 0],
|
||||||
|
[1, 0, 1, 1],
|
||||||
|
[1, 1, 0, 0],
|
||||||
|
[1, 1, 0, 1],
|
||||||
|
[1, 1, 1, 0],
|
||||||
|
[1, 1, 1, 1]])
|
||||||
|
|
||||||
|
expected_codewords = np.array([[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[1, 1, 0, 1, 0, 0, 1],
|
||||||
|
[0, 1, 0, 1, 0, 1, 0],
|
||||||
|
[1, 0, 0, 0, 0, 1, 1],
|
||||||
|
[1, 0, 0, 1, 1, 0, 0],
|
||||||
|
[0, 1, 0, 0, 1, 0, 1],
|
||||||
|
[1, 1, 0, 0, 1, 1, 0],
|
||||||
|
[0, 0, 0, 1, 1, 1, 1],
|
||||||
|
[1, 1, 1, 0, 0, 0, 0],
|
||||||
|
[0, 0, 1, 1, 0, 0, 1],
|
||||||
|
[1, 0, 1, 1, 0, 1, 0],
|
||||||
|
[0, 1, 1, 0, 0, 1, 1],
|
||||||
|
[0, 1, 1, 1, 1, 0, 0],
|
||||||
|
[1, 0, 1, 0, 1, 0, 1],
|
||||||
|
[0, 0, 1, 0, 1, 1, 0],
|
||||||
|
[1, 1, 1, 1, 1, 1, 1]])
|
||||||
|
|
||||||
|
self.assertEqual(np.array_equal(decoder._datawords, expected_datawords), True)
|
||||||
|
self.assertEqual(np.array_equal(decoder._codewords, expected_codewords), True)
|
||||||
Loading…
Reference in New Issue
Block a user