diff --git a/exercises/enums/enums1.rs b/exercises/enums/enums1.rs index a2223d3..becf001 100644 --- a/exercises/enums/enums1.rs +++ b/exercises/enums/enums1.rs @@ -1,11 +1,13 @@ // enums1.rs // Make me compile! Execute `rustlings hint enums1` for hints! -// I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define a few types of messages as used below + Quit, + Echo, + Move, + ChangeColor, } fn main() { diff --git a/exercises/enums/enums2.rs b/exercises/enums/enums2.rs index 52ccb22..5afa984 100644 --- a/exercises/enums/enums2.rs +++ b/exercises/enums/enums2.rs @@ -1,11 +1,13 @@ // enums2.rs // Make me compile! Execute `rustlings hint enums2` for hints! -// I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define the different variants used below + Quit, + Echo(String),// a tuple with one elem + Move{x: i32, y: i32}, + ChangeColor(u8, u8, u8), } impl Message { diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index bb7dfb4..fe35d9c 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -1,10 +1,13 @@ // enums3.rs // Address all the TODOs to make the tests pass! -// I AM NOT DONE +#[derive(Debug)] enum Message { - // TODO: implement the message variant types based on their usage below + Quit, + Echo(String),// a tuple with one elem + Move{x: u8, y: u8}, + ChangeColor(u8, u8, u8), } struct Point { @@ -37,6 +40,12 @@ impl State { fn process(&mut self, message: Message) { // TODO: create a match expression to process the different message variants + match message { + Message::Quit => {self.quit()} + Message::Move{x, y} => {self.move_position(Point{x: x, y : y})} + Message::Echo(string) => {self.echo(string)} + Message::ChangeColor(r,g,b) => {self.change_color((r,g,b))} + } } } diff --git a/exercises/test3.rs b/exercises/test3.rs index f94c36f..27d21a8 100644 --- a/exercises/test3.rs +++ b/exercises/test3.rs @@ -7,7 +7,6 @@ // we expect to get when we call `times_two` with a negative number. // No hints, you can do this :) -// I AM NOT DONE pub fn times_two(num: i32) -> i32 { num * 2 @@ -19,11 +18,11 @@ mod tests { #[test] fn returns_twice_of_positive_numbers() { - assert_eq!(times_two(4), ???); + assert_eq!(times_two(4), 8); } #[test] fn returns_twice_of_negative_numbers() { - // TODO write an assert for `times_two(-4)` + assert_eq!(times_two(-4), -8); } } diff --git a/exercises/tests/tests1.rs b/exercises/tests/tests1.rs index 50586a1..ca50ce9 100644 --- a/exercises/tests/tests1.rs +++ b/exercises/tests/tests1.rs @@ -6,12 +6,11 @@ // This test has a problem with it -- make the test compile! Make the test // pass! Make the test fail! Execute `rustlings hint tests1` for hints :) -// I AM NOT DONE #[cfg(test)] mod tests { #[test] fn you_can_assert() { - assert!(); + assert!(!(1==9)); } } diff --git a/exercises/tests/tests2.rs b/exercises/tests/tests2.rs index 0d981ad..4a50b63 100644 --- a/exercises/tests/tests2.rs +++ b/exercises/tests/tests2.rs @@ -2,12 +2,11 @@ // This test has a problem with it -- make the test compile! Make the test // pass! Make the test fail! Execute `rustlings hint tests2` for hints :) -// I AM NOT DONE #[cfg(test)] mod tests { #[test] fn you_can_assert_eq() { - assert_eq!(); + assert_eq!(1,1); } } diff --git a/exercises/tests/tests3.rs b/exercises/tests/tests3.rs index 693b8aa..8aeaa43 100644 --- a/exercises/tests/tests3.rs +++ b/exercises/tests/tests3.rs @@ -4,7 +4,6 @@ // we expect to get when we call `is_even(5)`. // Execute `rustlings hint tests3` for hints :) -// I AM NOT DONE pub fn is_even(num: i32) -> bool { num % 2 == 0 @@ -16,6 +15,14 @@ mod tests { #[test] fn is_true_when_even() { - assert!(); + assert!(!is_even(5)); + } + #[test] + fn is_even_works() ->Result<(), String> { + if !is_even(1<<10) { + Err(String::from("1<<10")) + } else { + Ok(()) + } } }