class ManchesterEncodeTests(unittest.TestCase): def setUp(self): self.codec = Manchester() def test_encode(self): self.assertEqual(self.codec.encode(bits), symbols) def test_invert_encode(self): self.codec.invert() self.assertEqual(self.codec.encode(bits), invert_symbols)
class DifferentialManchesterEncodeTests(unittest.TestCase): def setUp(self): self.codec = Manchester(differential=True) def test_encode(self): self.assertIn(self.codec.encode(bits), diff_symbols) for symbols in diff_symbols: init_level = symbols[0] == '1' and '0' or '1' self.assertEqual(self.codec.encode(bits, init_level=init_level), symbols) def test_invert_encode(self): self.assertIn(self.codec.encode(invert_bits), invert_diff_symbols) for symbols in invert_diff_symbols: init_level = symbols[0] == '1' and '0' or '1' self.assertEqual( self.codec.encode(invert_bits, init_level=init_level), symbols)
from nrzi import NRZI from hdb3 import HDB3 from manchester import Manchester from multilevel import Multilevel bits = Manchester("10110010") bits.encode() print("Bits:", bits.get_bits()) print("Code:", bits.get_code()) bits.plot()