Skip to content

Commit

Permalink
saddle-points: remove util function in tests (#1984)
Browse files Browse the repository at this point in the history
[no important files changed]

part of #1824
  • Loading branch information
senekor authored Aug 16, 2024
1 parent 9617af2 commit d47d407
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
11 changes: 4 additions & 7 deletions exercises/practice/saddle-points/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// We don't care about order
fn find_sorted_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> {
let mut result = saddle_points::find_saddle_points(input);
result.sort_unstable();
result
}
use saddle_points::*;

{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | make_ident }}() {
let input = &[{% for row in test.input.matrix %}
vec!{{ row }},
{% endfor %}];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[
{% for p in test.expected | sort(attribute = "column") | sort(attribute = "row") %}
({{ p.row - 1 }}, {{ p.column - 1 }}),
Expand Down
34 changes: 19 additions & 15 deletions exercises/practice/saddle-points/tests/saddle-points.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// We don't care about order
fn find_sorted_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> {
let mut result = saddle_points::find_saddle_points(input);
result.sort_unstable();
result
}
use saddle_points::*;

#[test]
fn can_identify_single_saddle_point() {
let input = &[vec![9, 8, 7], vec![5, 3, 2], vec![6, 6, 7]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(1, 0)];
assert_eq!(output, expected);
}
Expand All @@ -17,7 +13,8 @@ fn can_identify_single_saddle_point() {
#[ignore]
fn can_identify_that_empty_matrix_has_no_saddle_points() {
let input = &[vec![]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[];
assert_eq!(output, expected);
}
Expand All @@ -26,7 +23,8 @@ fn can_identify_that_empty_matrix_has_no_saddle_points() {
#[ignore]
fn can_identify_lack_of_saddle_points_when_there_are_none() {
let input = &[vec![1, 2, 3], vec![3, 1, 2], vec![2, 3, 1]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[];
assert_eq!(output, expected);
}
Expand All @@ -35,7 +33,8 @@ fn can_identify_lack_of_saddle_points_when_there_are_none() {
#[ignore]
fn can_identify_multiple_saddle_points_in_a_column() {
let input = &[vec![4, 5, 4], vec![3, 5, 5], vec![1, 5, 4]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(0, 1), (1, 1), (2, 1)];
assert_eq!(output, expected);
}
Expand All @@ -44,7 +43,8 @@ fn can_identify_multiple_saddle_points_in_a_column() {
#[ignore]
fn can_identify_multiple_saddle_points_in_a_row() {
let input = &[vec![6, 7, 8], vec![5, 5, 5], vec![7, 5, 6]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(1, 0), (1, 1), (1, 2)];
assert_eq!(output, expected);
}
Expand All @@ -53,7 +53,8 @@ fn can_identify_multiple_saddle_points_in_a_row() {
#[ignore]
fn can_identify_saddle_point_in_bottom_right_corner() {
let input = &[vec![8, 7, 9], vec![6, 7, 6], vec![3, 2, 5]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(2, 2)];
assert_eq!(output, expected);
}
Expand All @@ -62,7 +63,8 @@ fn can_identify_saddle_point_in_bottom_right_corner() {
#[ignore]
fn can_identify_saddle_points_in_a_non_square_matrix() {
let input = &[vec![3, 1, 3], vec![3, 2, 4]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(0, 0), (0, 2)];
assert_eq!(output, expected);
}
Expand All @@ -71,7 +73,8 @@ fn can_identify_saddle_points_in_a_non_square_matrix() {
#[ignore]
fn can_identify_that_saddle_points_in_a_single_column_matrix_are_those_with_the_minimum_value() {
let input = &[vec![2], vec![1], vec![4], vec![1]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(1, 0), (3, 0)];
assert_eq!(output, expected);
}
Expand All @@ -80,7 +83,8 @@ fn can_identify_that_saddle_points_in_a_single_column_matrix_are_those_with_the_
#[ignore]
fn can_identify_that_saddle_points_in_a_single_row_matrix_are_those_with_the_maximum_value() {
let input = &[vec![2, 5, 3, 5]];
let output = find_sorted_saddle_points(input);
let mut output = find_saddle_points(input);
output.sort_unstable();
let expected = &[(0, 1), (0, 3)];
assert_eq!(output, expected);
}

0 comments on commit d47d407

Please sign in to comment.