Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to test CRC logic?

How can I verify two CRC implementations will generate the same checksums?

I'm looking for an exhaustive implementation evaluating methodology specific to CRC.

like image 629
Joseph Weissman Avatar asked Aug 30 '10 17:08

Joseph Weissman


2 Answers

You can separate the problem into edge cases and random samples.

Edge cases. There are two variables to the CRC input, number of bytes, and value of each byte. So create arrays of 0, 1, and MAX_BYTES, with values ranging from 0 to MAX_BYTE_VALUE. The edge case suite will be something you'll most likely want to keep within a JUnit suite.

Random samples. Using the ranges above, run CRC on randomly generated arrays of bytes in a loop. The longer you let the loop run, the more you exhaust the inputs. If you are low on computing power, consider deploying the test to EC2.

like image 53
Robert Christian Avatar answered Sep 28 '22 15:09

Robert Christian


Create several unit tests with the same input that will compare the output of both implementations against each other.

like image 34
Bernard Avatar answered Sep 28 '22 14:09

Bernard