From 64bdc59234c9c0c310485937f3b07b04ec73a2fe Mon Sep 17 00:00:00 2001 From: Yotoko <44945530+vhgcuong@users.noreply.github.com> Date: Tue, 3 Oct 2023 15:41:01 +0700 Subject: [PATCH] Base spiral matrix --- src/lib.rs | 1 + src/spiral_matrix.rs | 3 ++ tests/libtest.rs | 1 + tests/spiral_matrix/mod.rs | 62 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 src/spiral_matrix.rs create mode 100644 tests/spiral_matrix/mod.rs diff --git a/src/lib.rs b/src/lib.rs index c50fcf3..a15ee92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,7 @@ pub mod minesweeper; pub mod alphametics; pub mod binary_search; pub mod all_your_base; +pub mod spiral_matrix; pub mod perfect_numbers; pub mod rna_transcription; pub mod largest_series_product; diff --git a/src/spiral_matrix.rs b/src/spiral_matrix.rs new file mode 100644 index 0000000..16d2d2c --- /dev/null +++ b/src/spiral_matrix.rs @@ -0,0 +1,3 @@ +pub fn spiral_matrix(size: u32) -> Vec> { + todo!("Function that returns the spiral matrix of square size {size}"); +} diff --git a/tests/libtest.rs b/tests/libtest.rs index 539bd8d..d27b3b0 100644 --- a/tests/libtest.rs +++ b/tests/libtest.rs @@ -34,3 +34,4 @@ mod largest_series_product; mod parallel_letter_frequency; mod rna_transcription; mod binary_search; +mod spiral_matrix; diff --git a/tests/spiral_matrix/mod.rs b/tests/spiral_matrix/mod.rs new file mode 100644 index 0000000..7410cba --- /dev/null +++ b/tests/spiral_matrix/mod.rs @@ -0,0 +1,62 @@ +use exercism::spiral_matrix::spiral_matrix; +#[test] +fn empty_spiral() { + let expected: Vec> = Vec::new(); + assert_eq!(spiral_matrix(0), expected); +} + +#[test] +#[ignore] +fn size_one_spiral() { + let expected: Vec> = vec![vec![1]]; + assert_eq!(spiral_matrix(1), expected); +} + +#[test] +#[ignore] +fn size_two_spiral() { + let expected: Vec> = vec![vec![1, 2], vec![4, 3]]; + assert_eq!(spiral_matrix(2), expected); + +} + +#[test] +#[ignore] +fn size_three_spiral() { + #[rustfmt::skip] + let expected: Vec> = vec![ + vec![1, 2, 3], + vec![8, 9, 4], + vec![7, 6, 5], + + ]; + assert_eq!(spiral_matrix(3), expected); +} + +#[test] +#[ignore] +fn size_four_spiral() { + let expected: Vec> = vec![ + vec![1, 2, 3, 4], + vec![12, 13, 14, 5], + vec![11, 16, 15, 6], + vec![10, 9, 8, 7], + ]; + + assert_eq!(spiral_matrix(4), expected); +} + +#[test] +#[ignore] +fn size_five_spiral() { + + let expected: Vec> = vec![ + vec![1, 2, 3, 4, 5], + vec![16, 17, 18, 19, 6], + vec![15, 24, 25, 20, 7], + vec![14, 23, 22, 21, 8], + vec![13, 12, 11, 10, 9], + ]; + assert_eq!(spiral_matrix(5), expected); + +}