mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
Compare commits
7 commits
a534101f9b
...
4f90511b90
Author | SHA1 | Date | |
---|---|---|---|
4f90511b90 | |||
8d0aa11a35 | |||
e2674498c6 | |||
3200581d4d | |||
6afc4840b4 | |||
93aef73eb5 | |||
40e2330e8d |
|
@ -2550,6 +2550,15 @@
|
|||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "gerases",
|
||||
"name": "gerases",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/8953623?v=4",
|
||||
"profile": "https://github.com/gerases",
|
||||
"contributions": [
|
||||
"content"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 8,
|
||||
|
|
|
@ -360,6 +360,9 @@ authors.
|
|||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/neuschaefer"><img src="https://avatars.githubusercontent.com/u/1021512?v=4?s=100" width="100px;" alt="J. Neuschäfer"/><br /><sub><b>J. Neuschäfer</b></sub></a><br /><a href="https://github.com/rust-lang/rustlings/commits?author=neuschaefer" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://scooterhacking.org"><img src="https://avatars.githubusercontent.com/u/58905488?v=4?s=100" width="100px;" alt="Bastian Pedersen"/><br /><sub><b>Bastian Pedersen</b></sub></a><br /><a href="#content-bastianpedersen" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="12.5%"><a href="https://github.com/gerases"><img src="https://avatars.githubusercontent.com/u/8953623?v=4?s=100" width="100px;" alt="gerases"/><br /><sub><b>gerases</b></sub></a><br /><a href="#content-gerases" title="Content">🖋</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ fn build_scores_table(results: String) -> HashMap<String, Team> {
|
|||
let team_2_score: u8 = v[3].parse().unwrap();
|
||||
// TODO: Populate the scores table with details extracted from the
|
||||
// current line. Keep in mind that goals scored by team_1
|
||||
// will be the number of goals conceded from team_2, and similarly
|
||||
// will be the number of goals conceded by team_2, and similarly
|
||||
// goals scored by team_2 will be the number of goals conceded by
|
||||
// team_1.
|
||||
}
|
||||
|
|
62
exercises/structs/structs4.rs
Normal file
62
exercises/structs/structs4.rs
Normal file
|
@ -0,0 +1,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);
|
||||
}
|
||||
}
|
10
info.toml
10
info.toml
|
@ -454,6 +454,16 @@ the `Package` struct that this relates to?
|
|||
Have a look in The Book, to find out more about method implementations:
|
||||
https://doc.rust-lang.org/book/ch05-03-method-syntax.html"""
|
||||
|
||||
[[exercises]]
|
||||
name = "structs4"
|
||||
path = "exercises/structs/structs4.rs"
|
||||
mode = "test"
|
||||
hint = """
|
||||
The signature of methods must be different depending on the fact that attributes of an instance are
|
||||
read or written. How do we do that in Rust?
|
||||
|
||||
Have a look in The Book, to find out more about method implementations: https://doc.rust-lang.org/book/ch05-03-method-syntax.html"""
|
||||
|
||||
# ENUMS
|
||||
|
||||
[[exercises]]
|
||||
|
|
Loading…
Reference in a new issue