pub fn compute_sig(index: u32, block_id: u32) -> u16 {
let value = index ^ block_id;
(value >> 16) as u16 ^ (value as u16)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compute_sig() {
assert_eq!(compute_sig(0x00000000, 0x00000000), 0x0000);
assert_eq!(compute_sig(0x00000000, 0x00000001), 0x0001);
assert_eq!(compute_sig(0x00000001, 0x00000000), 0x0001);
assert_eq!(compute_sig(0x00000001, 0x00000001), 0x0000);
assert_eq!(compute_sig(0x00000000, 0x00000002), 0x0002);
assert_eq!(compute_sig(0x00000002, 0x00000000), 0x0002);
assert_eq!(compute_sig(0x00000002, 0x00000002), 0x0000);
}
#[test]
fn test_overflow() {
assert_eq!(compute_sig(0x00000000, 0x00010000), 0x0001);
assert_eq!(compute_sig(0x00010000, 0x00000000), 0x0001);
assert_eq!(compute_sig(0x00010000, 0x00010000), 0x0000);
}
}