1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
mod bitwise;
pub use bitwise::*;
mod bytewise;
pub use bytewise::*;
mod wordwise;
pub use wordwise::*;
mod combining;
pub use combining::*;
#[cfg(test)]
mod test {
use super::*;
use crate::crc::Computer;
use crate::spec::Spec;
fn kermit() -> Spec {
Spec {
width: 16,
poly: 0x1021,
init: 0,
refin: true,
refout: true,
xorout: 0,
check: 0x2189,
residue: 0,
name: "KERMIT".into(),
}
}
#[test]
fn kermit_bitwise() {
let model = BitwiseModel::from_spec(kermit());
let input = b"123456789";
let output = Computer::crc(model, &input[..]);
assert_eq!(0x2189, output);
}
#[test]
fn kermit_bytewise() {
let model = BytewiseModel::from_spec(kermit());
let input = b"123456789";
let output = Computer::crc(model, &input[..]);
assert_eq!(0x2189, output);
}
#[test]
fn kermit_wordwise_nativeendian() {
let model =
WordwiseModel::<byteorder::NativeEndian, { usize::BITS as _ }>::from_spec(kermit());
let input = b"123456789";
let output = Computer::crc(model, &input[..]);
assert_eq!(0x2189, output);
}
}