aoc_rs/
string.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub fn contains_characters(s: String, chars: String, check_len: bool) -> bool {
    if check_len && (s.len() != chars.len()) {
        return false;
    }
    for char in chars.chars() {
        if !s.contains(char) {
            return false;
        }
    }
    true
}

#[cfg(test)]
mod tests {
    use super::contains_characters;

    #[test]
    fn test_contains_characters() {
        let sentence = String::from("the quick brown fox jumps over the lazy dog");
        let characters = String::from("xyz");
        let result = contains_characters(sentence, characters, false);
        assert!(result);
    }

    #[test]
    fn test_contains_characters_len() {
        let sentence = String::from("thequickbrownfxjmpsvlazydg");
        let characters = String::from("abcdefghijklmnopqrstuvwxyz");
        let result = contains_characters(sentence, characters, true);
        assert!(result);
    }
}