Skip to content

Commit

Permalink
Base spiral matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
vhgcuong committed Oct 3, 2023
1 parent d84afb8 commit 64bdc59
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/spiral_matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn spiral_matrix(size: u32) -> Vec<Vec<u32>> {
todo!("Function that returns the spiral matrix of square size {size}");
}
1 change: 1 addition & 0 deletions tests/libtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ mod largest_series_product;
mod parallel_letter_frequency;
mod rna_transcription;
mod binary_search;
mod spiral_matrix;
62 changes: 62 additions & 0 deletions tests/spiral_matrix/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use exercism::spiral_matrix::spiral_matrix;
#[test]
fn empty_spiral() {
let expected: Vec<Vec<u32>> = Vec::new();
assert_eq!(spiral_matrix(0), expected);
}

#[test]
#[ignore]
fn size_one_spiral() {
let expected: Vec<Vec<u32>> = vec![vec![1]];
assert_eq!(spiral_matrix(1), expected);
}

#[test]
#[ignore]
fn size_two_spiral() {
let expected: Vec<Vec<u32>> = 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<u32>> = 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<u32>> = 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<u32>> = 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);

}

0 comments on commit 64bdc59

Please sign in to comment.