]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | pub struct Guess { |
2 | value: i32, | |
3 | } | |
4 | ||
5 | impl Guess { | |
6 | pub fn new(value: i32) -> Guess { | |
7 | // ANCHOR: here | |
8 | if value < 1 { | |
9 | panic!( | |
10 | "Guess value must be less than or equal to 100, got {}.", | |
11 | value | |
12 | ); | |
13 | } else if value > 100 { | |
14 | panic!( | |
15 | "Guess value must be greater than or equal to 1, got {}.", | |
16 | value | |
17 | ); | |
18 | } | |
19 | // ANCHOR_END: here | |
20 | ||
21 | Guess { value } | |
22 | } | |
23 | } | |
24 | ||
25 | #[cfg(test)] | |
26 | mod tests { | |
27 | use super::*; | |
28 | ||
29 | #[test] | |
923072b8 | 30 | #[should_panic(expected = "less than or equal to 100")] |
74b04a01 XL |
31 | fn greater_than_100() { |
32 | Guess::new(200); | |
33 | } | |
34 | } |