forked from rust-lang-ua/rustcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
55 lines (47 loc) · 1.17 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
fn main() {
println!("Implement me!");
}
const NOW: &str = "2019-06-26";
struct User;
impl User {
fn with_birthdate(year: i32, month: u32, day: u32) -> Self {
unimplemented!()
}
/// Returns current age of [`User`] in years.
fn age(&self) -> u16 {
unimplemented!()
}
/// Checks if [`User`] is 18 years old at the moment.
fn is_adult(&self) -> bool {
unimplemented!()
}
}
#[cfg(test)]
mod age_spec {
use super::*;
#[test]
fn counts_age() {
for ((y, m, d), expected) in vec![
((1990, 6, 4), 29),
((1990, 7, 4), 28),
((0, 1, 1), 2019),
((1970, 1, 1), 49),
((2019, 6, 25), 0),
] {
let user = User::with_birthdate(y, m, d);
assert_eq!(user.age(), expected);
}
}
#[test]
fn zero_if_birthdate_in_future() {
for ((y, m, d), expected) in vec![
((2032, 6, 25), 0),
((2016, 6, 27), 0),
((3000, 6, 27), 0),
((9999, 6, 27), 0),
] {
let user = User::with_birthdate(y, m, d);
assert_eq!(user.age(), expected);
}
}
}