FastCRC16 { public static byte[] calculate(final byte b) { final int crc = table[b & 0xff]; return new byte[]{(byte) (crc & 0xff), (byte) ((crc >> 8) & 0xff)}; }  static byte[] calculate(final byte b); static byte[] calculate(final byte[] bytes, int end); static byte[] calculate(final byte[] bytes);  }
@Test public void calculateTest() { for (int i = 0; i < 256; i++) { assertWithMessage("domain test: " + i).that(calculate((byte) i)).isEqualTo(toTwoBytes(TEST_DOMAIN[i])); } assertWithMessage("test domain 2 full").that(calculate(TEST_DOMAIN_2)).isEqualTo(toTwoBytes(0xC056)); assertWithMessage("test domain 2 full indexed").that(calculate(TEST_DOMAIN_2, TEST_DOMAIN_2.length)).isEqualTo(toTwoBytes(0xC056)); for (int i = 0; i <= TEST_DOMAIN_2.length; i++) { assertWithMessage("reference test: " + i).that(calculate(TEST_DOMAIN_2, i)).isEqualTo(toTwoBytes(TEST_DOMAIN_3[i])); } }