Python: binary string error simulation

2019-08-12 19:55发布

I am currently writing a test for validating some error-correcting code:

inputData1  = "1001011011"
inputData2  = "1001111011"
fingerPrint1 = parityCheck.getParityFingerprint(inputData1)
                                      # Expected: fingerPrint1=0

fingerPrint2 = parityCheck.getParityFingerprint(inputData2)
                                      # Expected: fingerPrint2=1

if fingerPrint1 == fingerPrint2:
    print "Test failed: errorCorrectingAlgo1 failed to detect error"
else:
    print "Test success: errorCorrectingAlgo1 successfully detected error"

Is there a python class I can use to automatically generate error(burst error, single event, reordering, etc) on a binary string? Eg:

inputData1 = "1001011011"
inputData1BurstError = applyBurstError(inputData1)  # Eg: inputData1BurstError =
                                         ("1011111011", or "1001000000", or etc.)

inputData1RandomError = applyRandomError(inputData1)# Eg: inputData1RandomError =
                                         ("0001101011", or "0111101101", or etc.)

inputData1Reordering = applyReordering(inputData1)  # Eg: inputData1Reordering =
                                         ("0101110011", or "1101101001", or etc.)

inputData1SingleEvent = applySingleEvent(inputData1)# Eg: inputData1SingleEvent =
                                         ("1001011011", or "1000011011", or etc.)

I know that such a class could be easily implementable for binary check validation. However, I need a more complete class to test more complex error detecting code such as CRC. I have already used Netem (http://www.linuxfoundation.org/collaborate/workgroups/networking/netem) in the past to modify packets entering and leaving interfaces in a telecom lab. However, I doubt Netem would be a good solution to my problem this time as my whole test is planned to be run on my desktop computer only. Also, I am working on Windows 7 this time. Moreover, Netem does not provide a complete/complex enough set of functions for my test implementation.

Any help/suggestion would be greatly appreciated.

Thanks!

Related question: How to shuffle a list with Gaussian distribution

0条回答
登录 后发表回答