-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathstructs4.rs
62 lines (46 loc) · 1.22 KB
/
structs4.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
56
57
58
59
60
61
62
// structs4.rs
// Structs can have methods and the first parameter is always self. In this exercise
// we have defined the Planet struct and we want to test some logic attached to it,
// make the code compile and the tests pass! If you have issues execute `rustlings hint structs4`
// I AM NOT DONE
#[derive(Debug)]
struct Planet {
has_life: bool,
radius : u32
}
impl Planet {
fn new(radius: u32) -> Planet {
// Something goes here...
}
fn has_life(???) -> bool {
// Something goes here...
}
fn change_radius(???) {
// Something goes here...
}
fn create_life(???) {
// Something goes here...
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn create_planet() {
let planet = Planet::new(1000);
assert_eq!(planet.radius, 1000);
assert_eq!(planet.has_life(), false);
}
#[test]
fn add_life_to_planet() {
let planet = Planet::new(1000);
planet.create_life();
assert_eq!(planet.has_life(), true);
}
#[test]
fn change_radius_of_planet() {
let mut planet = Planet::new(1000);
planet.change_radius(2000);
assert_eq!(planet.radius, 2000);
}
}