From b492b359b30dd45d2eac4c2d6e76c6222cf47e1c Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Sat, 12 Jun 2021 23:34:53 -0600 Subject: [PATCH] Add 'idiomatic' exercise --- Cargo.toml | 1 + exercises/idiomatic/Cargo.toml | 9 +++++++++ exercises/idiomatic/src/main.rs | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 exercises/idiomatic/Cargo.toml create mode 100644 exercises/idiomatic/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index fe6ee06..4397534 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ members = [ "examples/kitchen", "examples/puzzle_game", "examples/puzzles", + "exercises/idiomatic" ] diff --git a/exercises/idiomatic/Cargo.toml b/exercises/idiomatic/Cargo.toml new file mode 100644 index 0000000..f6a870f --- /dev/null +++ b/exercises/idiomatic/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "idiomatic" +version = "0.1.0" +authors = ["Nathan Stocks "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/exercises/idiomatic/src/main.rs b/exercises/idiomatic/src/main.rs new file mode 100644 index 0000000..a57989c --- /dev/null +++ b/exercises/idiomatic/src/main.rs @@ -0,0 +1,22 @@ +// 1. Wow. Just...wow. Let's start cleaning this up by running `cargo fmt`. + +// 2. `cargo fmt` is great, but it doesn't add blank lines where there are none. Go ahead and add +// some blank lines in places you think it would make sense. + +// 3. Time to clean up! Run `cargo clippy`. Fix up all the warnings so `cargo clippy` is silent. + +// Challenge: Clippy doesn't find *everything*. What else would you change to make this code better? + +const pi:f32=3.14159265358979323846; +fn count_to_5()->i32{let mut foo =(0);loop{if{foo>pi as i32}{if(foo > 5){break;}}foo=foo+1;}return 5;} +fn main() { +println!("I can count to {}", count_to_5()); +} +#[cfg(test)] +mod test { +use super::*; +#[test] +fn test_counting() { +assert_eq!(count_to_5() == 5, true); +} +}