Skip to content

Commit 2191ef7

Browse files
committed
Auto merge of #219 - vyaslav:master, r=fmoko
Added exercise for struct update syntax Added one exercise for struct update syntax `struct2.rs`
2 parents 4c2cf6d + 1c4c876 commit 2191ef7

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

exercises/structs/structs2.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// structs2.rs
2+
// Address all the TODOs to make the tests pass!
3+
// No hints, just do it!
4+
5+
#[derive(Debug)]
6+
struct Order {
7+
name: String,
8+
year: u32,
9+
made_by_phone: bool,
10+
made_by_mobile: bool,
11+
made_by_email: bool,
12+
item_number: u32,
13+
count: u32,
14+
}
15+
16+
fn create_order_template() -> Order {
17+
Order {
18+
name: String::from("Bob"),
19+
year: 2019,
20+
made_by_phone: false,
21+
made_by_mobile: false,
22+
made_by_email: true,
23+
item_number: 123,
24+
count: 0,
25+
}
26+
}
27+
28+
#[cfg(test)]
29+
mod tests {
30+
use super::*;
31+
32+
#[test]
33+
fn your_order() {
34+
let order_template = create_order_template();
35+
// TODO: Create your own order using the update syntax and template above!
36+
// let your_order =
37+
assert_eq!(your_order.name, "Hacker in Rust");
38+
assert_eq!(your_order.year, order_template.year);
39+
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
40+
assert_eq!(your_order.made_by_mobile, order_template.made_by_mobile);
41+
assert_eq!(your_order.made_by_email, order_template.made_by_email);
42+
assert_eq!(your_order.item_number, order_template.item_number);
43+
assert_eq!(your_order.count, 1);
44+
}
45+
}

info.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ mode = "compile"
8282
path = "exercises/structs/structs1.rs"
8383
mode = "test"
8484

85+
[[exercises]]
86+
path = "exercises/structs/structs2.rs"
87+
mode = "test"
88+
8589
# TESTS
8690

8791
[[exercises]]

src/verify.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ fn compile_only(exercise: &Exercise) -> Result<(), ()> {
1919
let compile_output = exercise.compile();
2020
progress_bar.finish_and_clear();
2121
if compile_output.status.success() {
22-
let formatstr = format!(
23-
"{} Successfully compiled {}!",
24-
Emoji("✅", "✓"),
25-
exercise
26-
);
22+
let formatstr = format!("{} Successfully compiled {}!", Emoji("✅", "✓"), exercise);
2723
println!("{}", style(formatstr).green());
2824
exercise.clean();
2925
Ok(())

0 commit comments

Comments
 (0)