extern crate alloc;
use alloc::vec::Vec;
use crate::metis::{DotSet, HaveSetDecodeError};
#[test]
fn test_have_set_from_bytes_rejects_empty_station() {
let mut frame = Vec::new();
frame.push(0x01u8);
frame.extend_from_slice(&1u32.to_be_bytes());
frame.extend_from_slice(&9u32.to_be_bytes()); frame.extend_from_slice(&0u64.to_be_bytes()); frame.extend_from_slice(&0u32.to_be_bytes()); assert_eq!(
DotSet::from_bytes(&frame),
Err(HaveSetDecodeError::EmptyStation { station: 9 })
);
}
#[test]
fn test_have_set_from_bytes_rejects_non_ascending_stations() {
let mut frame = Vec::new();
frame.push(0x01u8);
frame.extend_from_slice(&2u32.to_be_bytes());
for station in [5u32, 3u32] {
frame.extend_from_slice(&station.to_be_bytes());
frame.extend_from_slice(&1u64.to_be_bytes()); frame.extend_from_slice(&0u32.to_be_bytes()); }
assert_eq!(
DotSet::from_bytes(&frame),
Err(HaveSetDecodeError::NonAscendingStations {
previous: 5,
found: 3,
})
);
let mut duplicate = Vec::new();
duplicate.push(0x01u8);
duplicate.extend_from_slice(&2u32.to_be_bytes());
for _ in 0..2 {
duplicate.extend_from_slice(&4u32.to_be_bytes()); duplicate.extend_from_slice(&1u64.to_be_bytes());
duplicate.extend_from_slice(&0u32.to_be_bytes());
}
assert_eq!(
DotSet::from_bytes(&duplicate),
Err(HaveSetDecodeError::NonAscendingStations {
previous: 4,
found: 4,
})
);
}