feat: Demo-Examples (Python/Rust/Go/C) mit Protokoll-Templates und Restore-Skript
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fb4e96919a
commit
64c2b7f0fd
21 changed files with 614 additions and 0 deletions
36
examples/rust-wordcount/src/main.rs
Normal file
36
examples/rust-wordcount/src/main.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use std::io::{self, Read};
|
||||
|
||||
fn count_words(text: &str) -> usize {
|
||||
text.split_whitespace().count()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
io::stdin().read_to_string(&mut input).unwrap();
|
||||
println!("{} words", count_words(&input));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_empty_input() {
|
||||
assert_eq!(count_words(""), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_word() {
|
||||
assert_eq!(count_words("hallo"), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_words() {
|
||||
assert_eq!(count_words("eins zwei drei"), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extra_whitespace() {
|
||||
assert_eq!(count_words(" a b "), 2);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue