]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | #[derive(PartialEq, Debug)] |
2 | struct Shoe { | |
3 | size: u32, | |
4 | style: String, | |
5 | } | |
6 | ||
6a06907d | 7 | fn shoes_in_size(shoes: Vec<Shoe>, shoe_size: u32) -> Vec<Shoe> { |
74b04a01 XL |
8 | shoes.into_iter().filter(|s| s.size == shoe_size).collect() |
9 | } | |
10 | ||
11 | #[cfg(test)] | |
12 | mod tests { | |
13 | use super::*; | |
14 | ||
15 | #[test] | |
16 | fn filters_by_size() { | |
17 | let shoes = vec![ | |
18 | Shoe { | |
19 | size: 10, | |
20 | style: String::from("sneaker"), | |
21 | }, | |
22 | Shoe { | |
23 | size: 13, | |
24 | style: String::from("sandal"), | |
25 | }, | |
26 | Shoe { | |
27 | size: 10, | |
28 | style: String::from("boot"), | |
29 | }, | |
30 | ]; | |
31 | ||
6a06907d | 32 | let in_my_size = shoes_in_size(shoes, 10); |
74b04a01 XL |
33 | |
34 | assert_eq!( | |
35 | in_my_size, | |
36 | vec![ | |
37 | Shoe { | |
38 | size: 10, | |
39 | style: String::from("sneaker") | |
40 | }, | |
41 | Shoe { | |
42 | size: 10, | |
43 | style: String::from("boot") | |
44 | }, | |
45 | ] | |
46 | ); | |
47 | } | |
48 | } |