use crate::statistical_tests::utils::convert_string;
pub fn get_binary_random(text: &str) -> String {
let data = convert_string(text);
if data.len() < 2 {
return "N".to_string();
}
let mut transitions = 0;
for i in 1..data.len() {
if data[i] != data[i-1] {
transitions += 1;
}
}
let possible_transitions = data.len() - 1;
let ratio = transitions as f64 / possible_transitions as f64;
if ratio > 0.45 {
"Y".to_string()
} else {
"N".to_string()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_binary_random_alternating() {
let text = "ABABABABABABABABAB";
let result = get_binary_random(text);
assert_eq!(result, "Y");
}
#[test]
fn test_binary_random_repeated() {
let text = "AAAAAAAAAAAAAAAAA";
let result = get_binary_random(text);
assert_eq!(result, "N");
}
}