pub struct NewAlgorithm {
pub key: Vec<u8>,
}
impl NewAlgorithm {
pub fn new() -> Self {
NewAlgorithm {
key: vec![0; 32], }
}
pub fn process_data(&self, input_data: &[u8]) -> Vec<u8> {
self.simple_transform(input_data, |x| x.wrapping_add(1))
}
fn simple_transform<F>(&self, data: &[u8], f: F) -> Vec<u8>
where
F: Fn(u8) -> u8,
{
data.iter().map(|&x| f(x)).collect()
}
}
impl Default for NewAlgorithm {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_algorithm_process_data() {
let algorithm = NewAlgorithm::new();
let input_data = vec![1, 2, 3, 4];
let output_data = algorithm.process_data(&input_data);
assert_eq!(output_data.len(), input_data.len());
}
#[test]
fn test_new_algorithm_consistency() {
let algorithm = NewAlgorithm::new();
let input_data = vec![5, 10, 15, 20];
let output_data = algorithm.process_data(&input_data);
let expected_output: Vec<u8> = input_data.iter().map(|&x| x.wrapping_add(1)).collect();
assert_eq!(output_data, expected_output);
}
#[test]
fn test_new_algorithm_empty_input() {
let algorithm = NewAlgorithm::new();
let input_data: Vec<u8> = vec![];
let output_data = algorithm.process_data(&input_data);
assert!(output_data.is_empty());
}
}