summaryrefslogtreecommitdiff
path: root/exercises/structs
diff options
context:
space:
mode:
authorViacheslav Avramenko <vyaslav@gmail.com>2019-10-21 14:23:06 +0200
committerViacheslav Avramenko <vyaslav@gmail.com>2019-10-21 14:50:59 +0200
commit1c4c8764ed118740cd4cee73272ddc6cceb9d959 (patch)
treefde486eea55d2ec110fd5a2ebd4c65b11e95a9cf /exercises/structs
parente6161a6f5819483fe5cdc0e0e9daf1487152fd7e (diff)
feat: Added exercise for struct update syntax
Diffstat (limited to 'exercises/structs')
-rw-r--r--exercises/structs/structs2.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/exercises/structs/structs2.rs b/exercises/structs/structs2.rs
new file mode 100644
index 0000000..db381e7
--- /dev/null
+++ b/exercises/structs/structs2.rs
@@ -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);
+ }
+}