-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #219 - vyaslav:master, r=fmoko
Added exercise for struct update syntax Added one exercise for struct update syntax `struct2.rs`
- Loading branch information
Showing
3 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// structs2.rs | ||
// Address all the TODOs to make the tests pass! | ||
// No hints, just do it! | ||
|
||
#[derive(Debug)] | ||
struct Order { | ||
name: String, | ||
year: u32, | ||
made_by_phone: bool, | ||
made_by_mobile: bool, | ||
made_by_email: bool, | ||
item_number: u32, | ||
count: u32, | ||
} | ||
|
||
fn create_order_template() -> Order { | ||
Order { | ||
name: String::from("Bob"), | ||
year: 2019, | ||
made_by_phone: false, | ||
made_by_mobile: false, | ||
made_by_email: true, | ||
item_number: 123, | ||
count: 0, | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn your_order() { | ||
let order_template = create_order_template(); | ||
// TODO: Create your own order using the update syntax and template above! | ||
// let your_order = | ||
assert_eq!(your_order.name, "Hacker in Rust"); | ||
assert_eq!(your_order.year, order_template.year); | ||
assert_eq!(your_order.made_by_phone, order_template.made_by_phone); | ||
assert_eq!(your_order.made_by_mobile, order_template.made_by_mobile); | ||
assert_eq!(your_order.made_by_email, order_template.made_by_email); | ||
assert_eq!(your_order.item_number, order_template.item_number); | ||
assert_eq!(your_order.count, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters