You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/test/groovy/com/github/snksoft/crc/CrcSpec.groovy
+51-21Lines changed: 51 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -4,34 +4,64 @@ import spock.lang.Specification
4
4
5
5
classCrcSpecextendsSpecification{
6
6
7
-
def "CRC3 to CRC7 Tests (onlynon-table-drivencalculationissupported)"() {
7
+
privatestaticfinal longText ="Whenever digital data is stored or interfaced, data corruption might occur. Since the beginning of computer science, people have been thinking of ways to deal with this type of problem. For serial data they came up with the solution to attach a parity bit to each sent byte. This simple detection mechanism works if an odd number of bits in a byte changes, but an even number of false bits in one byte will not be detected by the parity check. To overcome this problem people have searched for mathematical sound mechanisms to detect multiple false bits."
8
8
9
-
when:
10
-
byte[] dataBytes = data.getBytes()
11
-
long calculated1 = CRC.calculateCRC(crcParams, dataBytes)
9
+
privatestaticbyte[] testArray =null
12
10
13
-
then:
14
-
calculated1 == crc
11
+
static {
12
+
testArray =newbyte[256];
13
+
for (int i=0; i<testArray.length; i++)
14
+
{
15
+
testArray[i] = (byte)(i&0x0FF)
16
+
}
17
+
}
15
18
19
+
def"Test CRC polynomials of various widths"() {
16
20
when:
17
-
new CRC(crcParams)
18
-
21
+
byte[] dataBytes = data instanceofbyte[] ? data : data.getBytes()
22
+
long calculated1 =CRC.calculateCRC(crcParams, dataBytes)
23
+
then:
24
+
calculated1 == crc
25
+
when:
26
+
CRC table =new CRC(crcParams)
27
+
long tableBasedCrc = table.calculateCRC(dataBytes)
19
28
then:
20
-
RuntimeException e = thrown(RuntimeException)
21
-
e.message == "Table based CRC calculation not supported forCRC sum width of ${crcParams.width}"
0 commit comments