mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-12 10:28:04 +08:00
25 lines
385 B
Rust
Executable File
25 lines
385 B
Rust
Executable File
pub struct Guess {
|
|
value: i32,
|
|
}
|
|
|
|
impl Guess {
|
|
pub fn new(value: i32) -> Guess {
|
|
if value < 1 || value > 100 {
|
|
panic!("Guess value must be between 1 and 100, got {}.", value);
|
|
}
|
|
|
|
Guess { value }
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
#[should_panic]
|
|
fn greater_than_100() {
|
|
Guess::new(200);
|
|
}
|
|
}
|