CRC checksums (CRC-16, CRC-32, CRC-32C) for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(crowbar): Alcotest-style API with suite exports and grouped run

- Change `run` signature to `string -> (string * test_case list) list -> unit`
matching Alcotest's grouping convention
- Fix `_name` bug: pass the name through to Alcotest.run_with_args
- Each fuzz module now exports `let suite = ("name", [test_case ...])`
- Entry points (fuzz.ml) collect suites: `Crowbar.run "pkg" [Fuzz_X.suite]`
- Remove stale `add_test`/`suite` API, keep only `test_case`/`run`
- Remove `let run () = ()` from fuzz_common.ml files
- Update merlint E725 rule to match new `let suite = ("name", ...)` pattern
- Update E725 test fixtures and expected output

+63 -55
+63 -55
fuzz/fuzz_crc.ml
··· 4 4 - CRC-16-CCITT: string vs bytes agree, self-check residue is 0 5 5 - CRC-16-X.25: output in 16-bit range 6 6 - CRC-32C: string vs bytes agree 7 - - All: deterministic (same input → same output) *) 7 + - All: deterministic (same input -> same output) *) 8 8 9 - let () = 10 - (* CRC-16-CCITT: string and bytes sub-range agree *) 11 - Crowbar.add_test ~name:"crc: string = bytes (ccitt)" [ Crowbar.bytes ] 12 - (fun s -> 13 - let from_string = Crc.crc16_ccitt s in 14 - let from_bytes = 15 - Crc.crc16_ccitt_bytes (Bytes.of_string s) 0 (String.length s) 16 - in 17 - Crowbar.check_eq ~pp:Format.pp_print_int from_string from_bytes); 9 + open Crowbar 18 10 19 - (* CRC-16-CCITT: self-check property — CRC(msg || CRC_BE) = 0 *) 20 - Crowbar.add_test ~name:"crc: self-check residue (ccitt)" [ Crowbar.bytes ] 21 - (fun s -> 22 - let crc = Crc.crc16_ccitt s in 23 - let with_crc = 24 - s 25 - ^ String.init 2 (fun i -> 26 - Char.chr (if i = 0 then (crc lsr 8) land 0xFF else crc land 0xFF)) 27 - in 28 - let residue = Crc.crc16_ccitt with_crc in 29 - Crowbar.check_eq ~pp:Format.pp_print_int 0 residue); 11 + (* CRC-16-CCITT: string and bytes sub-range agree *) 12 + let test_ccitt_string_bytes s = 13 + let from_string = Crc.crc16_ccitt s in 14 + let from_bytes = 15 + Crc.crc16_ccitt_bytes (Bytes.of_string s) 0 (String.length s) 16 + in 17 + check_eq ~pp:Format.pp_print_int from_string from_bytes 30 18 31 - (* CRC-16-CCITT: output is 16-bit *) 32 - Crowbar.add_test ~name:"crc: 16-bit range (ccitt)" [ Crowbar.bytes ] (fun s -> 33 - let crc = Crc.crc16_ccitt s in 34 - Crowbar.check (crc >= 0 && crc <= 0xFFFF)); 19 + (* CRC-16-CCITT: self-check property -- CRC(msg || CRC_BE) = 0 *) 20 + let test_ccitt_self_check s = 21 + let crc = Crc.crc16_ccitt s in 22 + let with_crc = 23 + s 24 + ^ String.init 2 (fun i -> 25 + Char.chr (if i = 0 then (crc lsr 8) land 0xFF else crc land 0xFF)) 26 + in 27 + let residue = Crc.crc16_ccitt with_crc in 28 + check_eq ~pp:Format.pp_print_int 0 residue 35 29 36 - (* CRC-16-X.25: output is 16-bit *) 37 - Crowbar.add_test ~name:"crc: 16-bit range (x25)" [ Crowbar.bytes ] (fun s -> 38 - let crc = Crc.crc16_x25 s in 39 - Crowbar.check (crc >= 0 && crc <= 0xFFFF)); 30 + (* CRC-16-CCITT: output is 16-bit *) 31 + let test_ccitt_16bit s = 32 + let crc = Crc.crc16_ccitt s in 33 + check (crc >= 0 && crc <= 0xFFFF) 40 34 41 - (* CRC-32: output is non-negative *) 42 - Crowbar.add_test ~name:"crc: non-negative (crc32)" [ Crowbar.bytes ] (fun s -> 43 - let crc = Crc.crc32 s in 44 - Crowbar.check (crc >= 0)); 35 + (* CRC-16-X.25: output is 16-bit *) 36 + let test_x25_16bit s = 37 + let crc = Crc.crc16_x25 s in 38 + check (crc >= 0 && crc <= 0xFFFF) 45 39 46 - (* CRC-32C: string and bytes sub-range agree *) 47 - Crowbar.add_test ~name:"crc: string = bytes (crc32c)" [ Crowbar.bytes ] 48 - (fun s -> 49 - let from_string = Crc.crc32c s in 50 - let from_bytes = 51 - Crc.crc32c_bytes (Bytes.of_string s) 0 (String.length s) 52 - in 53 - Crowbar.check_eq ~pp:Format.pp_print_int from_string from_bytes); 40 + (* CRC-32: output is non-negative *) 41 + let test_crc32_nonneg s = 42 + let crc = Crc.crc32 s in 43 + check (crc >= 0) 54 44 55 - (* CRC-32C: output is 32-bit *) 56 - Crowbar.add_test ~name:"crc: 32-bit range (crc32c)" [ Crowbar.bytes ] 57 - (fun s -> 58 - let crc = Crc.crc32c s in 59 - Crowbar.check (crc >= 0 && crc <= 0xFFFFFFFF)); 45 + (* CRC-32C: string and bytes sub-range agree *) 46 + let test_crc32c_string_bytes s = 47 + let from_string = Crc.crc32c s in 48 + let from_bytes = Crc.crc32c_bytes (Bytes.of_string s) 0 (String.length s) in 49 + check_eq ~pp:Format.pp_print_int from_string from_bytes 50 + 51 + (* CRC-32C: output is 32-bit *) 52 + let test_crc32c_32bit s = 53 + let crc = Crc.crc32c s in 54 + check (crc >= 0 && crc <= 0xFFFFFFFF) 55 + 56 + (* CRC-16-CCITT: deterministic *) 57 + let test_ccitt_deterministic s = 58 + check_eq ~pp:Format.pp_print_int (Crc.crc16_ccitt s) (Crc.crc16_ccitt s) 59 + 60 + (* CRC-32C: deterministic *) 61 + let test_crc32c_deterministic s = 62 + check_eq ~pp:Format.pp_print_int (Crc.crc32c s) (Crc.crc32c s) 60 63 61 - (* CRC-16-CCITT: deterministic *) 62 - Crowbar.add_test ~name:"crc: deterministic (ccitt)" [ Crowbar.bytes ] 63 - (fun s -> 64 - Crowbar.check_eq ~pp:Format.pp_print_int (Crc.crc16_ccitt s) 65 - (Crc.crc16_ccitt s)); 64 + let suite = 65 + ( "crc", 66 + [ 67 + test_case "string = bytes (ccitt)" [ bytes ] test_ccitt_string_bytes; 68 + test_case "self-check residue (ccitt)" [ bytes ] test_ccitt_self_check; 69 + test_case "16-bit range (ccitt)" [ bytes ] test_ccitt_16bit; 70 + test_case "16-bit range (x25)" [ bytes ] test_x25_16bit; 71 + test_case "non-negative (crc32)" [ bytes ] test_crc32_nonneg; 72 + test_case "string = bytes (crc32c)" [ bytes ] test_crc32c_string_bytes; 73 + test_case "32-bit range (crc32c)" [ bytes ] test_crc32c_32bit; 74 + test_case "deterministic (ccitt)" [ bytes ] test_ccitt_deterministic; 75 + test_case "deterministic (crc32c)" [ bytes ] test_crc32c_deterministic; 76 + ] ) 66 77 67 - (* CRC-32C: deterministic *) 68 - Crowbar.add_test ~name:"crc: deterministic (crc32c)" [ Crowbar.bytes ] 69 - (fun s -> 70 - Crowbar.check_eq ~pp:Format.pp_print_int (Crc.crc32c s) (Crc.crc32c s)) 78 + let () = run "crc" [ suite ]