From e04e3c04aadd5adfce688d51713efbfd7805450f Mon Sep 17 00:00:00 2001 From: hekrause Date: Tue, 17 Oct 2017 18:51:19 +0200 Subject: [PATCH 01/19] Added tests an more README info. --- exercises/pascals-triangle/README.md | 11 +-- .../tests/pascals-triangle.rs | 83 +++++++++++++++++++ 2 files changed, 89 insertions(+), 5 deletions(-) diff --git a/exercises/pascals-triangle/README.md b/exercises/pascals-triangle/README.md index 1e9c530e5..a89c92a10 100644 --- a/exercises/pascals-triangle/README.md +++ b/exercises/pascals-triangle/README.md @@ -6,11 +6,12 @@ In Pascal's Triangle each number is computed by adding the numbers to the right and left of the current position in the previous row. ```plain - 1 - 1 1 - 1 2 1 - 1 3 3 1 -1 4 6 4 1 + 1 + 1 1 + 1 2 1 + 1 3 3 1 + 1 4 6 4 1 +1 5 10 10 5 1 # ... etc ``` diff --git a/exercises/pascals-triangle/tests/pascals-triangle.rs b/exercises/pascals-triangle/tests/pascals-triangle.rs index 5c46c83ac..d924cabbc 100644 --- a/exercises/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/pascals-triangle/tests/pascals-triangle.rs @@ -40,3 +40,86 @@ fn last_of_four_rows() { let expected: Vec = vec![1, 3, 3, 1]; assert_eq!(expected, pt.rows().pop().unwrap()); } + +#[test] +#[ignore] +fn five_rows() { + let pt = PascalsTriangle::new(5); + let expected: Vec> = vec![vec![1], + vec![1, 1], + vec![1, 2, 1], + vec![1, 3, 3, 1], + vec![1, 4, 6, 4, 1]]; + assert_eq!(expected, pt.rows()); +} + +#[test] +#[ignore] +fn six_rows() { + let pt = PascalsTriangle::new(6); + let expected: Vec> = vec![vec![1], + vec![1, 1], + vec![1, 2, 1], + vec![1, 3, 3, 1], + vec![1, 4, 6, 4, 1], + vec![1, 5, 10, 10, 5, 1]]; + assert_eq!(expected, pt.rows()); +} + +#[test] +#[ignore] +fn seven_rows() { + let pt = PascalsTriangle::new(7); + let expected: Vec> = vec![vec![1], + vec![1, 1], + vec![1, 2, 1], + vec![1, 3, 3, 1], + vec![1, 4, 6, 4, 1], + vec![1, 5, 10, 10, 5, 1], + vec![1, 6, 15, 20, 15, 6, 1]]; + assert_eq!(expected, pt.rows()); +} + +#[test] +#[ignore] +fn ten_rows() { + let pt = PascalsTriangle::new(10); + let expected: Vec> = vec![vec![1], + vec![1, 1], + vec![1, 2, 1], + vec![1, 3, 3, 1], + vec![1, 4, 6, 4, 1], + vec![1, 5, 10, 10, 5, 1], + vec![1, 6, 15, 20, 15, 6, 1], + vec![1, 7, 21, 35, 35, 21, 7, 1], + vec![1, 8, 28, 56, 70, 56, 28, 8, 1], + vec![1, 9, 36, 84, 126, 126, 84, 36, 9, 1]]; + assert_eq!(expected, pt.rows()); +} + +#[test] +#[ignore] +#[should_panic] +fn middle_numbers_getting_to_big_for_u32() { + PascalsTriangle::new(36); +} + +#[test] +#[ignore] +fn last_of_35_rows() { + let pt = PascalsTriangle::new(35); + let expected: Vec = + vec![1, 34, 561, 5984, 46376, 278256, 1344904, 5379616, 18156204, 52451256, 131128140, + 286097760, 548354040, 927983760, 1391975640, 1855967520, 2203961430, 2333606220, + 2203961430, 1855967520, 1391975640, 927983760, 548354040, 286097760, 131128140, + 52451256, 18156204, 5379616, 1344904, 278256, 46376, 5984, 561, 34, 1]; + assert_eq!(expected, pt.rows().pop().unwrap()); +} + +#[test] +#[ignore] +fn last_of_four_rows() { + let pt = PascalsTriangle::new(4); + let expected: Vec = vec![1, 3, 3, 1]; + assert_eq!(expected, pt.rows().pop().unwrap()); +} From cd20bcf15fc6cafa3e9b865729163fe963380d6c Mon Sep 17 00:00:00 2001 From: hekrause Date: Tue, 17 Oct 2017 19:42:46 +0200 Subject: [PATCH 02/19] Duplicate test let CI fail. --- exercises/pascals-triangle/tests/pascals-triangle.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/exercises/pascals-triangle/tests/pascals-triangle.rs b/exercises/pascals-triangle/tests/pascals-triangle.rs index d924cabbc..6cdf18eeb 100644 --- a/exercises/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/pascals-triangle/tests/pascals-triangle.rs @@ -33,14 +33,6 @@ fn three_rows() { assert_eq!(expected, pt.rows()); } -#[test] -#[ignore] -fn last_of_four_rows() { - let pt = PascalsTriangle::new(4); - let expected: Vec = vec![1, 3, 3, 1]; - assert_eq!(expected, pt.rows().pop().unwrap()); -} - #[test] #[ignore] fn five_rows() { From d9c2e9de17d71b275b7af2a3e0ea771a277b4fcd Mon Sep 17 00:00:00 2001 From: hekrause Date: Tue, 17 Oct 2017 20:49:47 +0200 Subject: [PATCH 03/19] Don't know why warnings are only displayed on CI. --- exercises/pascals-triangle/tests/pascals-triangle.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/pascals-triangle/tests/pascals-triangle.rs b/exercises/pascals-triangle/tests/pascals-triangle.rs index 6cdf18eeb..4b13de887 100644 --- a/exercises/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/pascals-triangle/tests/pascals-triangle.rs @@ -92,6 +92,7 @@ fn ten_rows() { #[test] #[ignore] #[should_panic] +#![deny(warnings)] fn middle_numbers_getting_to_big_for_u32() { PascalsTriangle::new(36); } From 6998c3ebee0199a2d6f905523dd932f302a380fc Mon Sep 17 00:00:00 2001 From: hekrause Date: Tue, 17 Oct 2017 20:55:27 +0200 Subject: [PATCH 04/19] Deny warnings on wrong place. --- exercises/pascals-triangle/tests/pascals-triangle.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/pascals-triangle/tests/pascals-triangle.rs b/exercises/pascals-triangle/tests/pascals-triangle.rs index 4b13de887..836482d24 100644 --- a/exercises/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/pascals-triangle/tests/pascals-triangle.rs @@ -2,6 +2,8 @@ extern crate pascals_triangle; use pascals_triangle::*; +#![deny(warnings)] + #[test] fn no_rows() { let pt = PascalsTriangle::new(0); @@ -92,7 +94,6 @@ fn ten_rows() { #[test] #[ignore] #[should_panic] -#![deny(warnings)] fn middle_numbers_getting_to_big_for_u32() { PascalsTriangle::new(36); } From 14413174fa5c68ab118a3cee92bda62f229476bc Mon Sep 17 00:00:00 2001 From: hekrause Date: Tue, 17 Oct 2017 22:18:10 +0200 Subject: [PATCH 05/19] Removed tests which failed only on CI. --- .../tests/pascals-triangle.rs | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/exercises/pascals-triangle/tests/pascals-triangle.rs b/exercises/pascals-triangle/tests/pascals-triangle.rs index 836482d24..1926694f3 100644 --- a/exercises/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/pascals-triangle/tests/pascals-triangle.rs @@ -2,8 +2,6 @@ extern crate pascals_triangle; use pascals_triangle::*; -#![deny(warnings)] - #[test] fn no_rows() { let pt = PascalsTriangle::new(0); @@ -91,25 +89,6 @@ fn ten_rows() { assert_eq!(expected, pt.rows()); } -#[test] -#[ignore] -#[should_panic] -fn middle_numbers_getting_to_big_for_u32() { - PascalsTriangle::new(36); -} - -#[test] -#[ignore] -fn last_of_35_rows() { - let pt = PascalsTriangle::new(35); - let expected: Vec = - vec![1, 34, 561, 5984, 46376, 278256, 1344904, 5379616, 18156204, 52451256, 131128140, - 286097760, 548354040, 927983760, 1391975640, 1855967520, 2203961430, 2333606220, - 2203961430, 1855967520, 1391975640, 927983760, 548354040, 286097760, 131128140, - 52451256, 18156204, 5379616, 1344904, 278256, 46376, 5984, 561, 34, 1]; - assert_eq!(expected, pt.rows().pop().unwrap()); -} - #[test] #[ignore] fn last_of_four_rows() { From fce89156f466a9f92325f12cef411c309684a342 Mon Sep 17 00:00:00 2001 From: hekrause Date: Sun, 5 Nov 2017 23:15:25 +0100 Subject: [PATCH 06/19] Remove changes. --- exercises/pascals-triangle/README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/exercises/pascals-triangle/README.md b/exercises/pascals-triangle/README.md index a89c92a10..8ac54bccf 100644 --- a/exercises/pascals-triangle/README.md +++ b/exercises/pascals-triangle/README.md @@ -5,13 +5,12 @@ Compute Pascal's triangle up to a given number of rows. In Pascal's Triangle each number is computed by adding the numbers to the right and left of the current position in the previous row. -```plain - 1 - 1 1 - 1 2 1 - 1 3 3 1 - 1 4 6 4 1 -1 5 10 10 5 1 +```text + 1 + 1 1 + 1 2 1 + 1 3 3 1 +1 4 6 4 1 # ... etc ``` From 20c0ab0e171f66f33bbaf5fe74cb17ea603fd0a4 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Mon, 6 Nov 2017 01:19:41 -0800 Subject: [PATCH 07/19] pascals-triangle: 1.2.0 --- exercises/pascals-triangle/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/pascals-triangle/Cargo.toml b/exercises/pascals-triangle/Cargo.toml index d989d0c71..2db67b8f1 100644 --- a/exercises/pascals-triangle/Cargo.toml +++ b/exercises/pascals-triangle/Cargo.toml @@ -1,3 +1,3 @@ [package] name = "pascals-triangle" -version = "1.0.0" +version = "1.2.0" From 834b7432446deecc027114ec352e92ea27da8e3a Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Mon, 6 Nov 2017 01:19:49 -0800 Subject: [PATCH 08/19] pascals-triangle: move four between three and five --- .../pascals-triangle/tests/pascals-triangle.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/pascals-triangle/tests/pascals-triangle.rs b/exercises/pascals-triangle/tests/pascals-triangle.rs index d72535fb1..cccbb4092 100644 --- a/exercises/pascals-triangle/tests/pascals-triangle.rs +++ b/exercises/pascals-triangle/tests/pascals-triangle.rs @@ -33,6 +33,14 @@ fn three_rows() { assert_eq!(expected, pt.rows()); } +#[test] +#[ignore] +fn last_of_four_rows() { + let pt = PascalsTriangle::new(4); + let expected: Vec = vec![1, 3, 3, 1]; + assert_eq!(Some(expected), pt.rows().pop()); +} + #[test] #[ignore] fn five_rows() { @@ -88,11 +96,3 @@ fn ten_rows() { vec![1, 9, 36, 84, 126, 126, 84, 36, 9, 1]]; assert_eq!(expected, pt.rows()); } - -#[test] -#[ignore] -fn last_of_four_rows() { - let pt = PascalsTriangle::new(4); - let expected: Vec = vec![1, 3, 3, 1]; - assert_eq!(Some(expected), pt.rows().pop()); -} From c784f9d7ad4836bbbc3af2f7e3445b9d792d5995 Mon Sep 17 00:00:00 2001 From: hekrause Date: Sat, 25 Nov 2017 17:28:20 +0100 Subject: [PATCH 09/19] Remove diffie-hellman --- exercises/diffie-hellman/Cargo.lock | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 exercises/diffie-hellman/Cargo.lock diff --git a/exercises/diffie-hellman/Cargo.lock b/exercises/diffie-hellman/Cargo.lock new file mode 100644 index 000000000..666773601 --- /dev/null +++ b/exercises/diffie-hellman/Cargo.lock @@ -0,0 +1,48 @@ +[[package]] +name = "bitflags" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "diffie-hellman" +version = "0.1.0" +dependencies = [ + "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" +"checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" +"checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" +"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" +"checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" From 1d04e9aee893f8267c86563e48fddabd84b4b7df Mon Sep 17 00:00:00 2001 From: hekrause Date: Sat, 25 Nov 2017 22:12:29 +0100 Subject: [PATCH 10/19] Initial saddle-points commit. --- config.json | 11 +++ exercises/saddle-points/.gitignore | 8 +++ exercises/saddle-points/Cargo.toml | 5 ++ exercises/saddle-points/README.md | 66 ++++++++++++++++++ exercises/saddle-points/example.rs | 23 +++++++ exercises/saddle-points/src/lib.rs | 4 ++ .../saddle-points/tests/saddle-points.rs | 68 +++++++++++++++++++ 7 files changed, 185 insertions(+) create mode 100644 exercises/saddle-points/.gitignore create mode 100644 exercises/saddle-points/Cargo.toml create mode 100644 exercises/saddle-points/README.md create mode 100644 exercises/saddle-points/example.rs create mode 100644 exercises/saddle-points/src/lib.rs create mode 100644 exercises/saddle-points/tests/saddle-points.rs diff --git a/config.json b/config.json index a4bb6dca9..3c3a886d3 100644 --- a/config.json +++ b/config.json @@ -164,6 +164,17 @@ "error handling with Result" ] }, + { + "uuid": "ccebfa12-d224-11e7-8941-cec278b6b50a", + "slug": "saddle-points", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "vectors", + "iterators" + ] + }, { "uuid": "79613fd8-b7da-11e7-abc4-cec278b6b50a", "slug": "isogram", diff --git a/exercises/saddle-points/.gitignore b/exercises/saddle-points/.gitignore new file mode 100644 index 000000000..db7f315c0 --- /dev/null +++ b/exercises/saddle-points/.gitignore @@ -0,0 +1,8 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ +**/*.rs.bk + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock diff --git a/exercises/saddle-points/Cargo.toml b/exercises/saddle-points/Cargo.toml new file mode 100644 index 000000000..28569f5bf --- /dev/null +++ b/exercises/saddle-points/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "saddle-points" +version = "1.1.0" + +[dependencies] diff --git a/exercises/saddle-points/README.md b/exercises/saddle-points/README.md new file mode 100644 index 000000000..da1cd46b3 --- /dev/null +++ b/exercises/saddle-points/README.md @@ -0,0 +1,66 @@ +# Saddle Points + +Detect saddle points in a matrix. + +So say you have a matrix like so: + +```text + 0 1 2 + |--------- +0 | 9 8 7 +1 | 5 3 2 <--- saddle point at (1,0) +2 | 6 6 7 +``` + +It has a saddle point at (1, 0). + +It's called a "saddle point" because it is greater than or equal to +every element in its row and the less than or equal to every element in +its column. + +A matrix may have zero or more saddle points. + +Your code should be able to provide the (possibly empty) list of all the +saddle points for any given matrix. + +Note that you may find other definitions of matrix saddle points online, +but the tests for this exercise follow the above unambiguous definition. + +## Rust Installation + +Refer to the [exercism help page][help-page] for Rust installation and learning +resources. + +## Writing the Code + +Execute the tests with: + +```bash +$ cargo test +``` + +All but the first test have been ignored. After you get the first test to +pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests +to pass again. The test file is located in the `tests` directory. You can +also remove the ignore flag from all the tests to get them to run all at once +if you wish. + +Make sure to read the [Modules](https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html) chapter if you +haven't already, it will help you with organizing your files. + +## Feedback, Issues, Pull Requests + +The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the [rust track team](https://github.com/orgs/exercism/teams/rust) are happy to help! + +If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md). + +[help-page]: http://exercism.io/languages/rust +[modules]: https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html +[cargo]: https://doc.rust-lang.org/book/second-edition/ch14-00-more-about-cargo.html + +## Source + +J Dalbey's Programming Practice problems [http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html](http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/saddle-points/example.rs b/exercises/saddle-points/example.rs new file mode 100644 index 000000000..1d9e68721 --- /dev/null +++ b/exercises/saddle-points/example.rs @@ -0,0 +1,23 @@ + +pub fn find_saddle_points(input: Vec>) -> Vec<(u64, u64)>{ + let mut saddle_points: Vec<(u64, u64)> = Vec::new(); + + let row_index = input.len(); + let column_index = input[0].len(); + + for i in 0..row_index { + for j in 0..column_index { + let row = &input[i]; + let column = input.iter().map(|x| x[j]).collect::>(); + + let max = row.iter().max().unwrap(); + let min = column.iter().min().unwrap(); + let value = input[i][j]; + + if value >= *max && value <= *min { + saddle_points.push((i as u64, j as u64)); + } + } + } + return saddle_points; +} \ No newline at end of file diff --git a/exercises/saddle-points/src/lib.rs b/exercises/saddle-points/src/lib.rs new file mode 100644 index 000000000..963a26730 --- /dev/null +++ b/exercises/saddle-points/src/lib.rs @@ -0,0 +1,4 @@ + +pub fn find_saddle_points(input: Vec>) -> Vec<(u64, u64)>{ + unimplemented!() +} \ No newline at end of file diff --git a/exercises/saddle-points/tests/saddle-points.rs b/exercises/saddle-points/tests/saddle-points.rs new file mode 100644 index 000000000..c4e485906 --- /dev/null +++ b/exercises/saddle-points/tests/saddle-points.rs @@ -0,0 +1,68 @@ +extern crate saddle_points; + +use saddle_points::*; + +#[test] +fn identify_single_saddle_point() { + let input: Vec> = vec![vec![9, 8, 7], + vec![5, 3, 2], + vec![6, 6, 7]]; + assert_eq!(vec![(1,0)], find_saddle_points(input)); +} + + +#[test] +#[ignore] +fn identify_empty_matrix() { + let input: Vec> = vec![vec![]]; + let expected: Vec<(u64, u64)> = Vec::new(); + + assert_eq!(expected, find_saddle_points(input)); +} + +#[test] +#[ignore] +fn identify_missing_saddle_point() { + let input: Vec> = vec![vec![1, 2, 3], + vec![3, 2, 1], + vec![2, 3, 1]]; + let expected: Vec<(u64, u64)> = Vec::new(); + assert_eq!(expected, find_saddle_points(input)); +} + +#[test] +#[ignore] +fn identify_bottom_right_saddle_point() { + let input: Vec> = vec![vec![8, 7, 9], + vec![6, 7, 6], + vec![3, 2, 5]]; + assert_eq!(vec![(2,2)], find_saddle_points(input)); +} + +#[test] +#[ignore] +fn non_quadratic_matrix_high() { + let input: Vec> = vec![vec![1, 5], + vec![3, 6], + vec![2, 7], + vec![3, 8]]; + assert_eq!(vec![(0, 1)], find_saddle_points(input)); +} + +#[test] +#[ignore] +fn non_quadratic_matrix_wide() { + let input: Vec> = vec![vec![8, 7, 10, 7, 9], + vec![8, 7, 13, 7, 9]]; + assert_eq!(vec![(0, 2)], find_saddle_points(input)); +} + +#[test] +#[ignore] +fn vector_matrix() { + let input: Vec> = vec![vec![1], + vec![3], + vec![2], + vec![3]]; + assert_eq!(vec![(0, 0)], find_saddle_points(input)); +} \ No newline at end of file From f2c139d357a706d6ea4a9bf619964039ac01c398 Mon Sep 17 00:00:00 2001 From: hekrause Date: Sat, 25 Nov 2017 22:24:17 +0100 Subject: [PATCH 11/19] Remove diffie-hellman left-overs. --- exercises/diffie-hellman/Cargo.lock | 48 ----------------------------- 1 file changed, 48 deletions(-) delete mode 100644 exercises/diffie-hellman/Cargo.lock diff --git a/exercises/diffie-hellman/Cargo.lock b/exercises/diffie-hellman/Cargo.lock deleted file mode 100644 index 666773601..000000000 --- a/exercises/diffie-hellman/Cargo.lock +++ /dev/null @@ -1,48 +0,0 @@ -[[package]] -name = "bitflags" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "diffie-hellman" -version = "0.1.0" -dependencies = [ - "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fuchsia-zircon" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rand" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" -"checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" -"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" -"checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" From c5e0144a56949194b931151023abaec01c95b815 Mon Sep 17 00:00:00 2001 From: hekrause Date: Sat, 25 Nov 2017 23:04:18 +0100 Subject: [PATCH 12/19] Remove old README.md --- exercises/saddle-points/README.md | 66 ------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 exercises/saddle-points/README.md diff --git a/exercises/saddle-points/README.md b/exercises/saddle-points/README.md deleted file mode 100644 index da1cd46b3..000000000 --- a/exercises/saddle-points/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# Saddle Points - -Detect saddle points in a matrix. - -So say you have a matrix like so: - -```text - 0 1 2 - |--------- -0 | 9 8 7 -1 | 5 3 2 <--- saddle point at (1,0) -2 | 6 6 7 -``` - -It has a saddle point at (1, 0). - -It's called a "saddle point" because it is greater than or equal to -every element in its row and the less than or equal to every element in -its column. - -A matrix may have zero or more saddle points. - -Your code should be able to provide the (possibly empty) list of all the -saddle points for any given matrix. - -Note that you may find other definitions of matrix saddle points online, -but the tests for this exercise follow the above unambiguous definition. - -## Rust Installation - -Refer to the [exercism help page][help-page] for Rust installation and learning -resources. - -## Writing the Code - -Execute the tests with: - -```bash -$ cargo test -``` - -All but the first test have been ignored. After you get the first test to -pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests -to pass again. The test file is located in the `tests` directory. You can -also remove the ignore flag from all the tests to get them to run all at once -if you wish. - -Make sure to read the [Modules](https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html) chapter if you -haven't already, it will help you with organizing your files. - -## Feedback, Issues, Pull Requests - -The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the [rust track team](https://github.com/orgs/exercism/teams/rust) are happy to help! - -If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md). - -[help-page]: http://exercism.io/languages/rust -[modules]: https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html -[cargo]: https://doc.rust-lang.org/book/second-edition/ch14-00-more-about-cargo.html - -## Source - -J Dalbey's Programming Practice problems [http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html](http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html) - -## Submitting Incomplete Solutions -It's possible to submit an incomplete solution so you can see how others have completed the exercise. From c6fa7ff1b9e0a6d5f7283c4dc3f63ad5f87a212a Mon Sep 17 00:00:00 2001 From: hekrause Date: Sat, 25 Nov 2017 23:05:11 +0100 Subject: [PATCH 13/19] Generate new README.md --- exercises/saddle-points/README.md | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 exercises/saddle-points/README.md diff --git a/exercises/saddle-points/README.md b/exercises/saddle-points/README.md new file mode 100644 index 000000000..da1cd46b3 --- /dev/null +++ b/exercises/saddle-points/README.md @@ -0,0 +1,66 @@ +# Saddle Points + +Detect saddle points in a matrix. + +So say you have a matrix like so: + +```text + 0 1 2 + |--------- +0 | 9 8 7 +1 | 5 3 2 <--- saddle point at (1,0) +2 | 6 6 7 +``` + +It has a saddle point at (1, 0). + +It's called a "saddle point" because it is greater than or equal to +every element in its row and the less than or equal to every element in +its column. + +A matrix may have zero or more saddle points. + +Your code should be able to provide the (possibly empty) list of all the +saddle points for any given matrix. + +Note that you may find other definitions of matrix saddle points online, +but the tests for this exercise follow the above unambiguous definition. + +## Rust Installation + +Refer to the [exercism help page][help-page] for Rust installation and learning +resources. + +## Writing the Code + +Execute the tests with: + +```bash +$ cargo test +``` + +All but the first test have been ignored. After you get the first test to +pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests +to pass again. The test file is located in the `tests` directory. You can +also remove the ignore flag from all the tests to get them to run all at once +if you wish. + +Make sure to read the [Modules](https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html) chapter if you +haven't already, it will help you with organizing your files. + +## Feedback, Issues, Pull Requests + +The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the [rust track team](https://github.com/orgs/exercism/teams/rust) are happy to help! + +If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md). + +[help-page]: http://exercism.io/languages/rust +[modules]: https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html +[cargo]: https://doc.rust-lang.org/book/second-edition/ch14-00-more-about-cargo.html + +## Source + +J Dalbey's Programming Practice problems [http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html](http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. From bb710fc8b93f345703115ba6bf9e8915438d14f9 Mon Sep 17 00:00:00 2001 From: hekrause Date: Sun, 26 Nov 2017 12:18:27 +0100 Subject: [PATCH 14/19] Try only to change README.md --- exercises/saddle-points/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/saddle-points/README.md b/exercises/saddle-points/README.md index da1cd46b3..2fa2c18ec 100644 --- a/exercises/saddle-points/README.md +++ b/exercises/saddle-points/README.md @@ -15,7 +15,7 @@ So say you have a matrix like so: It has a saddle point at (1, 0). It's called a "saddle point" because it is greater than or equal to -every element in its row and the less than or equal to every element in +every element in its row and less than or equal to every element in its column. A matrix may have zero or more saddle points. From fb0f63b5fac9613c113d7d4c898cae80a650be8a Mon Sep 17 00:00:00 2001 From: hekrause Date: Wed, 29 Nov 2017 11:27:50 +0100 Subject: [PATCH 15/19] Made requested changes. --- exercises/saddle-points/Cargo.toml | 2 +- exercises/saddle-points/example.rs | 17 +++--- exercises/saddle-points/src/lib.rs | 2 +- .../saddle-points/tests/saddle-points.rs | 57 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/exercises/saddle-points/Cargo.toml b/exercises/saddle-points/Cargo.toml index 28569f5bf..f6f20014b 100644 --- a/exercises/saddle-points/Cargo.toml +++ b/exercises/saddle-points/Cargo.toml @@ -1,5 +1,5 @@ [package] name = "saddle-points" -version = "1.1.0" +version = "1.0.0" [dependencies] diff --git a/exercises/saddle-points/example.rs b/exercises/saddle-points/example.rs index 1d9e68721..d793b50c0 100644 --- a/exercises/saddle-points/example.rs +++ b/exercises/saddle-points/example.rs @@ -1,17 +1,18 @@ -pub fn find_saddle_points(input: Vec>) -> Vec<(u64, u64)>{ +pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ let mut saddle_points: Vec<(u64, u64)> = Vec::new(); - let row_index = input.len(); - let column_index = input[0].len(); + let width = input.len(); + let height = input[0].len(); - for i in 0..row_index { - for j in 0..column_index { - let row = &input[i]; - let column = input.iter().map(|x| x[j]).collect::>(); + for i in 0..width { + for j in 0..height { + let column = input.iter().map(|x| x[j]).collect::>(); + let row = &input[i]; let max = row.iter().max().unwrap(); let min = column.iter().min().unwrap(); + let value = input[i][j]; if value >= *max && value <= *min { @@ -19,5 +20,5 @@ pub fn find_saddle_points(input: Vec>) -> Vec<(u64, u64)>{ } } } - return saddle_points; + saddle_points } \ No newline at end of file diff --git a/exercises/saddle-points/src/lib.rs b/exercises/saddle-points/src/lib.rs index 963a26730..b98bea07e 100644 --- a/exercises/saddle-points/src/lib.rs +++ b/exercises/saddle-points/src/lib.rs @@ -1,4 +1,4 @@ -pub fn find_saddle_points(input: Vec>) -> Vec<(u64, u64)>{ +pub fn find_saddle_points(_input: &[&[u64]]) -> Vec<(u64, u64)>{ unimplemented!() } \ No newline at end of file diff --git a/exercises/saddle-points/tests/saddle-points.rs b/exercises/saddle-points/tests/saddle-points.rs index c4e485906..57d199a99 100644 --- a/exercises/saddle-points/tests/saddle-points.rs +++ b/exercises/saddle-points/tests/saddle-points.rs @@ -3,18 +3,17 @@ extern crate saddle_points; use saddle_points::*; #[test] -fn identify_single_saddle_point() { - let input: Vec> = vec![vec![9, 8, 7], - vec![5, 3, 2], - vec![6, 6, 7]]; +fn test_identify_single_saddle_point() { + let input: &[&[u64]] = &[&[9, 8, 7], + &[5, 3, 2], + &[6, 6, 7]]; assert_eq!(vec![(1,0)], find_saddle_points(input)); } - #[test] #[ignore] -fn identify_empty_matrix() { - let input: Vec> = vec![vec![]]; +fn test_identify_empty_matrix() { + let input: &[&[u64]] = &[&[]]; let expected: Vec<(u64, u64)> = Vec::new(); assert_eq!(expected, find_saddle_points(input)); @@ -22,47 +21,47 @@ fn identify_empty_matrix() { #[test] #[ignore] -fn identify_missing_saddle_point() { - let input: Vec> = vec![vec![1, 2, 3], - vec![3, 2, 1], - vec![2, 3, 1]]; +fn test_identify_lack_of_saddle_point() { + let input: &[&[u64]] = &[&[1, 2, 3], + &[3, 1, 2], + &[2, 3, 1]]; let expected: Vec<(u64, u64)> = Vec::new(); assert_eq!(expected, find_saddle_points(input)); } #[test] #[ignore] -fn identify_bottom_right_saddle_point() { - let input: Vec> = vec![vec![8, 7, 9], - vec![6, 7, 6], - vec![3, 2, 5]]; +fn test_identify_bottom_right_saddle_point() { + let input: &[&[u64]] = &[&[8, 7, 9], + &[6, 7, 6], + &[3, 2, 5]]; assert_eq!(vec![(2,2)], find_saddle_points(input)); } #[test] #[ignore] -fn non_quadratic_matrix_high() { - let input: Vec> = vec![vec![1, 5], - vec![3, 6], - vec![2, 7], - vec![3, 8]]; +fn test_non_square_matrix_high() { + let input: &[&[u64]] = &[&[1, 5], + &[3, 6], + &[2, 7], + &[3, 8]]; assert_eq!(vec![(0, 1)], find_saddle_points(input)); } #[test] #[ignore] -fn non_quadratic_matrix_wide() { - let input: Vec> = vec![vec![8, 7, 10, 7, 9], - vec![8, 7, 13, 7, 9]]; +fn test_non_quadratic_matrix_wide() { + let input: &[&[u64]] = &[&[8, 7, 10, 7, 9], + &[8, 7, 13, 7, 9]]; assert_eq!(vec![(0, 2)], find_saddle_points(input)); } #[test] #[ignore] -fn vector_matrix() { - let input: Vec> = vec![vec![1], - vec![3], - vec![2], - vec![3]]; +fn test_vector_matrix() { + let input: &[&[u64]] = &[&[1], + &[3], + &[2], + &[3]]; assert_eq!(vec![(0, 0)], find_saddle_points(input)); -} \ No newline at end of file +} From 45c002dd18db696408637b628ce20fa2a00d455c Mon Sep 17 00:00:00 2001 From: hekrause Date: Thu, 30 Nov 2017 12:11:38 +0100 Subject: [PATCH 16/19] Change tests again. --- exercises/saddle-points/example.rs | 4 +- exercises/saddle-points/src/lib.rs | 5 +- .../saddle-points/tests/saddle-points.rs | 78 ++++++++++++++----- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/exercises/saddle-points/example.rs b/exercises/saddle-points/example.rs index d793b50c0..f646286ba 100644 --- a/exercises/saddle-points/example.rs +++ b/exercises/saddle-points/example.rs @@ -1,4 +1,3 @@ - pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ let mut saddle_points: Vec<(u64, u64)> = Vec::new(); @@ -10,6 +9,7 @@ pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ let column = input.iter().map(|x| x[j]).collect::>(); let row = &input[i]; + let max = row.iter().max().unwrap(); let min = column.iter().min().unwrap(); @@ -21,4 +21,4 @@ pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ } } saddle_points -} \ No newline at end of file +} diff --git a/exercises/saddle-points/src/lib.rs b/exercises/saddle-points/src/lib.rs index b98bea07e..175a0b24f 100644 --- a/exercises/saddle-points/src/lib.rs +++ b/exercises/saddle-points/src/lib.rs @@ -1,4 +1 @@ - -pub fn find_saddle_points(_input: &[&[u64]]) -> Vec<(u64, u64)>{ - unimplemented!() -} \ No newline at end of file +pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ unimplemented!() } diff --git a/exercises/saddle-points/tests/saddle-points.rs b/exercises/saddle-points/tests/saddle-points.rs index 57d199a99..84b6f25de 100644 --- a/exercises/saddle-points/tests/saddle-points.rs +++ b/exercises/saddle-points/tests/saddle-points.rs @@ -4,16 +4,24 @@ use saddle_points::*; #[test] fn test_identify_single_saddle_point() { - let input: &[&[u64]] = &[&[9, 8, 7], - &[5, 3, 2], - &[6, 6, 7]]; + let vector: Vec> = vec![vec![9, 8, 7], + vec![5, 3, 2], + vec![6, 6, 7]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..]]; assert_eq!(vec![(1,0)], find_saddle_points(input)); } #[test] #[ignore] fn test_identify_empty_matrix() { - let input: &[&[u64]] = &[&[]]; + let vector: Vec> = vec![vec![], + vec![], + vec![]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..]]; let expected: Vec<(u64, u64)> = Vec::new(); assert_eq!(expected, find_saddle_points(input)); @@ -22,46 +30,74 @@ fn test_identify_empty_matrix() { #[test] #[ignore] fn test_identify_lack_of_saddle_point() { - let input: &[&[u64]] = &[&[1, 2, 3], - &[3, 1, 2], - &[2, 3, 1]]; + let vector: Vec> = vec![vec![1, 2, 3], + vec![3, 1, 2], + vec![2, 3, 1]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..]]; let expected: Vec<(u64, u64)> = Vec::new(); assert_eq!(expected, find_saddle_points(input)); } +#[test] +#[ignore] +fn test_multiple_saddle_point() { + let vector: Vec> = vec![vec![4, 5, 4], + vec![3, 5, 5], + vec![1, 5, 4]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..]]; + assert_eq!(vec![(0,1), (1,1), (2,1)], find_saddle_points(input)); +} + #[test] #[ignore] fn test_identify_bottom_right_saddle_point() { - let input: &[&[u64]] = &[&[8, 7, 9], - &[6, 7, 6], - &[3, 2, 5]]; + let vector: Vec> = vec![vec![8, 7, 9], + vec![6, 7, 6], + vec![3, 2, 5]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..]]; assert_eq!(vec![(2,2)], find_saddle_points(input)); } #[test] #[ignore] fn test_non_square_matrix_high() { - let input: &[&[u64]] = &[&[1, 5], - &[3, 6], - &[2, 7], - &[3, 8]]; + let vector: Vec> = vec![vec![1, 5], + vec![3, 6], + vec![2, 7], + vec![3, 8]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..], + &vector[3][..]]; assert_eq!(vec![(0, 1)], find_saddle_points(input)); } #[test] #[ignore] fn test_non_quadratic_matrix_wide() { - let input: &[&[u64]] = &[&[8, 7, 10, 7, 9], - &[8, 7, 13, 7, 9]]; + let vector: Vec> = vec![vec![8, 7, 10, 7, 9], + vec![8, 7, 13, 7, 9]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..]]; assert_eq!(vec![(0, 2)], find_saddle_points(input)); } #[test] #[ignore] fn test_vector_matrix() { - let input: &[&[u64]] = &[&[1], - &[3], - &[2], - &[3]]; + let vector: Vec> = vec![vec![1], + vec![3], + vec![2], + vec![3]]; + let input: &[&[u64]] = &[&vector[0][..], + &vector[1][..], + &vector[2][..], + &vector[3][..]]; assert_eq!(vec![(0, 0)], find_saddle_points(input)); -} +} \ No newline at end of file From b64d368f8dbb91b688a571e1095bffd6a2de4961 Mon Sep 17 00:00:00 2001 From: Peter Goodspeed-Niklaus Date: Thu, 14 Dec 2017 12:56:38 +0100 Subject: [PATCH 17/19] Fix merge conflict with master --- config.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/config.json b/config.json index 3c3a886d3..2fed82b22 100644 --- a/config.json +++ b/config.json @@ -154,6 +154,17 @@ "mathematics" ] }, + { + "uuid": "9de405e1-3a05-43cb-8eb3-00b81a2968e9", + "slug": "series", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "vectors", + "strings" + ] + }, { "uuid": "f9afd650-8103-4373-a284-fa4ecfee7207", "slug": "collatz-conjecture", @@ -164,6 +175,16 @@ "error handling with Result" ] }, + { + "uuid": "23d82e48-d074-11e7-8fab-cec278b6b50a", + "slug": "diffie-hellman", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "mathematics" + ] + }, { "uuid": "ccebfa12-d224-11e7-8941-cec278b6b50a", "slug": "saddle-points", From ab95998944edef739e84635eb6577ea012c12b6e Mon Sep 17 00:00:00 2001 From: Peter Goodspeed-Niklaus Date: Thu, 14 Dec 2017 13:01:16 +0100 Subject: [PATCH 18/19] Update find_saddle_points signature I asked for some updates to the signature two weeks ago, but there's been no movement. In the interest of getting this exercise into a mergeable state, I went ahead and performed the requested updates myself: - https://github.com/exercism/rust/pull/400#pullrequestreview-80452568 - https://github.com/exercism/rust/pull/400#pullrequestreview-80521059 --- exercises/saddle-points/example.rs | 6 +- exercises/saddle-points/src/lib.rs | 4 +- .../saddle-points/tests/saddle-points.rs | 81 +++++-------------- 3 files changed, 25 insertions(+), 66 deletions(-) diff --git a/exercises/saddle-points/example.rs b/exercises/saddle-points/example.rs index f646286ba..e3d9c7a7c 100644 --- a/exercises/saddle-points/example.rs +++ b/exercises/saddle-points/example.rs @@ -1,5 +1,5 @@ -pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ - let mut saddle_points: Vec<(u64, u64)> = Vec::new(); +pub fn find_saddle_points(input: &[Vec]) -> Vec<(usize, usize)> { + let mut saddle_points = Vec::new(); let width = input.len(); let height = input[0].len(); @@ -16,7 +16,7 @@ pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ let value = input[i][j]; if value >= *max && value <= *min { - saddle_points.push((i as u64, j as u64)); + saddle_points.push((i, j)); } } } diff --git a/exercises/saddle-points/src/lib.rs b/exercises/saddle-points/src/lib.rs index 175a0b24f..7c3aee704 100644 --- a/exercises/saddle-points/src/lib.rs +++ b/exercises/saddle-points/src/lib.rs @@ -1 +1,3 @@ -pub fn find_saddle_points(input: &[&[u64]]) -> Vec<(u64, u64)>{ unimplemented!() } +pub fn find_saddle_points(input: &[Vec]) -> Vec<(usize, usize)> { + unimplemented!() +} diff --git a/exercises/saddle-points/tests/saddle-points.rs b/exercises/saddle-points/tests/saddle-points.rs index 84b6f25de..7bd23a36e 100644 --- a/exercises/saddle-points/tests/saddle-points.rs +++ b/exercises/saddle-points/tests/saddle-points.rs @@ -4,100 +4,57 @@ use saddle_points::*; #[test] fn test_identify_single_saddle_point() { - let vector: Vec> = vec![vec![9, 8, 7], - vec![5, 3, 2], - vec![6, 6, 7]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..]]; - assert_eq!(vec![(1,0)], find_saddle_points(input)); + let input = vec![vec![9, 8, 7], vec![5, 3, 2], vec![6, 6, 7]]; + assert_eq!(vec![(1, 0)], find_saddle_points(&input)); } #[test] #[ignore] fn test_identify_empty_matrix() { - let vector: Vec> = vec![vec![], - vec![], - vec![]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..]]; - let expected: Vec<(u64, u64)> = Vec::new(); - - assert_eq!(expected, find_saddle_points(input)); + let input = vec![vec![], vec![], vec![]]; + let expected: Vec<(usize, usize)> = Vec::new(); + assert_eq!(expected, find_saddle_points(&input)); } #[test] #[ignore] fn test_identify_lack_of_saddle_point() { - let vector: Vec> = vec![vec![1, 2, 3], - vec![3, 1, 2], - vec![2, 3, 1]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..]]; - let expected: Vec<(u64, u64)> = Vec::new(); - assert_eq!(expected, find_saddle_points(input)); + let input = vec![vec![1, 2, 3], vec![3, 1, 2], vec![2, 3, 1]]; + let expected: Vec<(usize, usize)> = Vec::new(); + assert_eq!(expected, find_saddle_points(&input)); } #[test] #[ignore] fn test_multiple_saddle_point() { - let vector: Vec> = vec![vec![4, 5, 4], - vec![3, 5, 5], - vec![1, 5, 4]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..]]; - assert_eq!(vec![(0,1), (1,1), (2,1)], find_saddle_points(input)); + let input = vec![vec![4, 5, 4], vec![3, 5, 5], vec![1, 5, 4]]; + assert_eq!(vec![(0, 1), (1, 1), (2, 1)], find_saddle_points(&input)); } #[test] #[ignore] fn test_identify_bottom_right_saddle_point() { - let vector: Vec> = vec![vec![8, 7, 9], - vec![6, 7, 6], - vec![3, 2, 5]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..]]; - assert_eq!(vec![(2,2)], find_saddle_points(input)); + let input = vec![vec![8, 7, 9], vec![6, 7, 6], vec![3, 2, 5]]; + assert_eq!(vec![(2, 2)], find_saddle_points(&input)); } #[test] #[ignore] fn test_non_square_matrix_high() { - let vector: Vec> = vec![vec![1, 5], - vec![3, 6], - vec![2, 7], - vec![3, 8]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..], - &vector[3][..]]; - assert_eq!(vec![(0, 1)], find_saddle_points(input)); + let input = vec![vec![1, 5], vec![3, 6], vec![2, 7], vec![3, 8]]; + assert_eq!(vec![(0, 1)], find_saddle_points(&input)); } #[test] #[ignore] fn test_non_quadratic_matrix_wide() { - let vector: Vec> = vec![vec![8, 7, 10, 7, 9], - vec![8, 7, 13, 7, 9]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..]]; - assert_eq!(vec![(0, 2)], find_saddle_points(input)); + let input = vec![vec![8, 7, 10, 7, 9], vec![8, 7, 13, 7, 9]]; + assert_eq!(vec![(0, 2)], find_saddle_points(&input)); } #[test] #[ignore] fn test_vector_matrix() { - let vector: Vec> = vec![vec![1], - vec![3], - vec![2], - vec![3]]; - let input: &[&[u64]] = &[&vector[0][..], - &vector[1][..], - &vector[2][..], - &vector[3][..]]; - assert_eq!(vec![(0, 0)], find_saddle_points(input)); -} \ No newline at end of file + let input = vec![vec![1], vec![3], vec![2], vec![3]]; + assert_eq!(vec![(0, 0)], find_saddle_points(&input)); +} From badcc30d8550d8f07ff6ee07cde4177a0bb14c3b Mon Sep 17 00:00:00 2001 From: coriolinus Date: Thu, 14 Dec 2017 13:14:57 +0100 Subject: [PATCH 19/19] Rename test `*quadratic*` -> `*square*` --- exercises/saddle-points/tests/saddle-points.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/saddle-points/tests/saddle-points.rs b/exercises/saddle-points/tests/saddle-points.rs index 7bd23a36e..8021b79dc 100644 --- a/exercises/saddle-points/tests/saddle-points.rs +++ b/exercises/saddle-points/tests/saddle-points.rs @@ -47,7 +47,7 @@ fn test_non_square_matrix_high() { #[test] #[ignore] -fn test_non_quadratic_matrix_wide() { +fn test_non_square_matrix_wide() { let input = vec![vec![8, 7, 10, 7, 9], vec![8, 7, 13, 7, 9]]; assert_eq!(vec![(0, 2)], find_saddle_points(&input)); }