From f4381cffb8757d3ffba9f5710bcc6268c3d2601a Mon Sep 17 00:00:00 2001 From: ju6ge Date: Sun, 22 Mar 2026 15:54:53 +0100 Subject: [PATCH] test detection of dual bit errors with hemming --- lib-bms-protocol/src/types.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib-bms-protocol/src/types.rs b/lib-bms-protocol/src/types.rs index df944a9..c9c325e 100644 --- a/lib-bms-protocol/src/types.rs +++ b/lib-bms-protocol/src/types.rs @@ -343,4 +343,14 @@ mod base_type_tests { assert_eq!(invalid_hemming^hc, hemming); } } + + #[test] + fn hemming_dual_bit_error_detection() { + let data = 0x123456; + let hemming = calc_hemming(data); + let bit_error = 0x101; + let correction = check_hemming(data ^ bit_error, hemming).unwrap_err(); + let (dc, hc) = correction.calc_correction_data(); + assert!(check_hemming(data ^ dc, hemming ^ hc).is_err()) + } }