From 26fa7918722113617803111dc81030e0ac734b00 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Mon, 7 Nov 2022 11:26:34 +0100 Subject: [PATCH] Added unit tests for soft decision decoder --- sw/test/test_soft_decision.py | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sw/test/test_soft_decision.py diff --git a/sw/test/test_soft_decision.py b/sw/test/test_soft_decision.py new file mode 100644 index 0000000..f77240b --- /dev/null +++ b/sw/test/test_soft_decision.py @@ -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)