use super::{sig, InputGenerator};
use crate::spec::types::OpSignature;
pub struct Pathological;
impl InputGenerator for Pathological {
fn name(&self) -> &'static str {
"pathological"
}
fn handles(&self, signature: &OpSignature) -> bool {
sig::is_byte_input(signature)
}
fn generate(&self, signature: &OpSignature, _seed: u64) -> Vec<(String, Vec<u8>)> {
if sig::is_byte_input(signature) {
cases()
} else {
Vec::new()
}
}
}
fn cases() -> Vec<(String, Vec<u8>)> {
let mut out = Vec::new();
for len in [0_usize, 1, 4, 16, 64, 255, 1024] {
out.push((format!("zeros:len{len}"), vec![0; len]));
out.push((format!("ones:len{len}"), vec![0xFF; len]));
out.push((format!("ascending:len{len}"), pattern(len, |idx| idx as u8)));
out.push((
format!("descending:len{len}"),
pattern(len, |idx| 255 - idx as u8),
));
out.push((format!("alternating:len{len}"), pattern(len, alt_byte)));
out.push((format!("repeat4:len{len}"), pattern(len, repeat4)));
}
out
}
fn pattern(len: usize, mut f: impl FnMut(usize) -> u8) -> Vec<u8> {
(0..len).map(&mut f).collect()
}
fn alt_byte(idx: usize) -> u8 {
if idx % 2 == 0 {
0
} else {
0xFF
}
}
fn repeat4(idx: usize) -> u8 {
[0xDE, 0xAD, 0xBE, 0xEF][idx % 4]
}