mod builder;
pub use builder::Builder;
pub static DIGITS: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
pub static UC_LETTERS: [char; 26] = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
pub static LC_LETTERS: [char; 26] = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z',
];
pub static UC_UMLAUTS: [char; 3] = ['Ä', 'Ö', 'Ü'];
pub static LC_UMLAUTS: [char; 3] = ['ä', 'ö', 'ü'];
pub static COMMON_SPECIAL_CHARS: [char; 16] = [
' ', '!', '$', '%', '&', '/', '(', ')', '=', '?', '+', '#', '-', '.', ',', 'ß',
];
pub static ALL_OTHER_SPECIAL_CHARS: [char; 23] = [
'_', ':', ';', '<', '>', '|', '\'', '*', '~', '`', '´', '\\', '^', '°', '{', '}', '[', ']',
'€', '@', '"', '§', 'µ',
];
pub fn combination_count(alphabet: &[char], max_length: u32, min_length: u32) -> usize {
if min_length > max_length {
panic!("max_length must be >= min_length")
}
let mut sum = 0;
for i in min_length..=max_length {
sum += alphabet.len().pow(i);
}
sum
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_combinations_count() {
let alphabet1: Box<[char]> = Box::from(['a']);
let alphabet2: Box<[char]> = Box::from(['a', 'b', 'c']);
let alphabet3: Box<[char]> = Box::from(['a', 'b']);
let alphabet4: Box<[char]> = Box::from([]);
let alphabet5: Box<[char]> = Box::from(DIGITS);
assert_eq!(
combination_count(&alphabet1, 3, 0),
4,
"1 symbol and a maximum length of 3"
);
assert_eq!(
combination_count(&alphabet1, 3, 3),
1,
"1 symbol, min=2, max=3 => 2 combination"
);
assert_eq!(
combination_count(&alphabet1, 3, 3),
1,
"1 symbol, min=3, max=3 => 1 combination"
);
assert_eq!(
combination_count(&alphabet2, 1, 0),
4,
"3 symbols and a maximum length of 1"
);
assert_eq!(
combination_count(&alphabet2, 2, 1),
12,
"3 symbols, min=1, max=2 => 9 combination"
);
assert_eq!(
combination_count(&alphabet3, 3, 0),
15,
"3 symbols and a maximum length of 3"
);
assert_eq!(combination_count(&alphabet4, 0, 0), 1, "0 symbols");
assert_eq!(combination_count(&alphabet4, 0, 0), 1, "0 symbols");
assert_eq!(combination_count(&alphabet5, 4, 4), 10_000);
}
#[test]
#[should_panic]
fn test_combinations_count_panic() {
let alphabet: Box<[char]> = Box::from(['a']);
assert_eq!(
combination_count(&alphabet, 0, 1),
0,
"min length must be <= max length"
);
}
}