From 63814ba8ffe151e6a723111d6393a1fd97c3b4af Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Mon, 20 Nov 2023 15:29:49 +0100 Subject: [PATCH] Sync rectangles with problem-specifications (#1785) --- .../rectangles/.meta/test_template.tera | 19 +++ .../practice/rectangles/.meta/tests.toml | 55 +++++++- .../practice/rectangles/tests/rectangles.rs | 121 +++++++++++------- 3 files changed, 147 insertions(+), 48 deletions(-) create mode 100644 exercises/practice/rectangles/.meta/test_template.tera diff --git a/exercises/practice/rectangles/.meta/test_template.tera b/exercises/practice/rectangles/.meta/test_template.tera new file mode 100644 index 000000000..0813a456a --- /dev/null +++ b/exercises/practice/rectangles/.meta/test_template.tera @@ -0,0 +1,19 @@ +{% for test in cases %} +#[test] +{% if loop.index != 1 -%} +#[ignore] +{% endif -%} +fn test_{{ test.description | slugify | replace(from="-", to="_") }}() { + {% if test.input.strings | length > 1 -%} + #[rustfmt::skip] + {%- endif %} + let input = &[ + {%- for row in test.input.strings %} + {{ row | json_encode }}, + {%- endfor %} + ]; + let output = {{ crate_name }}::{{ fn_names[0] }}(input); + let expected = {{ test.expected | json_encode() }}; + assert_eq!(output, expected); +} +{% endfor -%} diff --git a/exercises/practice/rectangles/.meta/tests.toml b/exercises/practice/rectangles/.meta/tests.toml index be690e975..282015033 100644 --- a/exercises/practice/rectangles/.meta/tests.toml +++ b/exercises/practice/rectangles/.meta/tests.toml @@ -1,3 +1,52 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[485b7bab-4150-40aa-a8db-73013427d08c] +description = "no rows" + +[076929ed-27e8-45dc-b14b-08279944dc49] +description = "no columns" + +[0a8abbd1-a0a4-4180-aa4e-65c1b1a073fa] +description = "no rectangles" + +[a4ba42e9-4e7f-4973-b7c7-4ce0760ac6cd] +description = "one rectangle" + +[ced06550-83da-4d23-98b7-d24152e0db93] +description = "two rectangles without shared parts" + +[5942d69a-a07c-41c8-8b93-2d13877c706a] +description = "five rectangles with shared parts" + +[82d70be4-ab37-4bf2-a433-e33778d3bbf1] +description = "rectangle of height 1 is counted" + +[57f1bc0e-2782-401e-ab12-7c01d8bfc2e0] +description = "rectangle of width 1 is counted" + +[ef0bb65c-bd80-4561-9535-efc4067054f9] +description = "1x1 square is counted" + +[e1e1d444-e926-4d30-9bf3-7d8ec9a9e330] +description = "only complete rectangles are counted" + +[ca021a84-1281-4a56-9b9b-af14113933a4] +description = "rectangles can be of different sizes" + +[51f689a7-ef3f-41ae-aa2f-5ea09ad897ff] +description = "corner is required for a rectangle to be complete" + +[d78fe379-8c1b-4d3c-bdf7-29bfb6f6dc66] +description = "large input with many rectangles" + +[6ef24e0f-d191-46da-b929-4faca24b4cd2] +description = "rectangles must have four sides" diff --git a/exercises/practice/rectangles/tests/rectangles.rs b/exercises/practice/rectangles/tests/rectangles.rs index c3f72237c..6c8e467c9 100644 --- a/exercises/practice/rectangles/tests/rectangles.rs +++ b/exercises/practice/rectangles/tests/rectangles.rs @@ -1,143 +1,168 @@ -use rectangles::count; - #[test] -fn zero_area_1() { - let lines = &[]; - assert_eq!(0, count(lines)) +fn test_no_rows() { + let input = &[]; + let output = rectangles::count(input); + let expected = 0; + assert_eq!(output, expected); } #[test] #[ignore] -fn zero_area_2() { - let lines = &[""]; - assert_eq!(0, count(lines)) +fn test_no_columns() { + let input = &[""]; + let output = rectangles::count(input); + let expected = 0; + assert_eq!(output, expected); } #[test] #[ignore] -fn empty_area() { - let lines = &[" "]; - assert_eq!(0, count(lines)) +fn test_no_rectangles() { + let input = &[" "]; + let output = rectangles::count(input); + let expected = 0; + assert_eq!(output, expected); } #[test] #[ignore] -fn one_rectangle() { +fn test_one_rectangle() { #[rustfmt::skip] - let lines = &[ + let input = &[ "+-+", "| |", "+-+", ]; - assert_eq!(1, count(lines)) + let output = rectangles::count(input); + let expected = 1; + assert_eq!(output, expected); } #[test] #[ignore] -fn two_rectangles_no_shared_parts() { +fn test_two_rectangles_without_shared_parts() { #[rustfmt::skip] - let lines = &[ + let input = &[ " +-+", " | |", "+-+-+", "| | ", "+-+ ", ]; - assert_eq!(2, count(lines)) + let output = rectangles::count(input); + let expected = 2; + assert_eq!(output, expected); } #[test] #[ignore] -fn five_rectangles_three_regions() { +fn test_five_rectangles_with_shared_parts() { #[rustfmt::skip] - let lines = &[ + let input = &[ " +-+", " | |", "+-+-+", "| | |", "+-+-+", ]; - assert_eq!(5, count(lines)) + let output = rectangles::count(input); + let expected = 5; + assert_eq!(output, expected); } #[test] #[ignore] -fn rectangle_of_height_1() { +fn test_rectangle_of_height_1_is_counted() { #[rustfmt::skip] - let lines = &[ + let input = &[ "+--+", "+--+", ]; - assert_eq!(1, count(lines)) + let output = rectangles::count(input); + let expected = 1; + assert_eq!(output, expected); } #[test] #[ignore] -fn rectangle_of_width_1() { +fn test_rectangle_of_width_1_is_counted() { #[rustfmt::skip] - let lines = &[ + let input = &[ "++", "||", "++", ]; - assert_eq!(1, count(lines)) + let output = rectangles::count(input); + let expected = 1; + assert_eq!(output, expected); } #[test] #[ignore] -fn unit_square() { +fn test_1x1_square_is_counted() { #[rustfmt::skip] - let lines = &[ + let input = &[ "++", "++", ]; - assert_eq!(1, count(lines)) + let output = rectangles::count(input); + let expected = 1; + assert_eq!(output, expected); } #[test] #[ignore] -fn incomplete_rectangles() { +fn test_only_complete_rectangles_are_counted() { #[rustfmt::skip] - let lines = &[ + let input = &[ " +-+", " |", "+-+-+", "| | -", "+-+-+", ]; - assert_eq!(1, count(lines)) + let output = rectangles::count(input); + let expected = 1; + assert_eq!(output, expected); } #[test] #[ignore] -fn complicated() { - let lines = &[ +fn test_rectangles_can_be_of_different_sizes() { + #[rustfmt::skip] + let input = &[ "+------+----+", "| | |", "+---+--+ |", "| | |", "+---+-------+", ]; - assert_eq!(3, count(lines)) + let output = rectangles::count(input); + let expected = 3; + assert_eq!(output, expected); } #[test] #[ignore] -fn not_so_complicated() { - let lines = &[ +fn test_corner_is_required_for_a_rectangle_to_be_complete() { + #[rustfmt::skip] + let input = &[ "+------+----+", "| | |", "+------+ |", "| | |", "+---+-------+", ]; - assert_eq!(2, count(lines)) + let output = rectangles::count(input); + let expected = 2; + assert_eq!(output, expected); } #[test] #[ignore] -fn large_input_with_many_rectangles() { - let lines = &[ +fn test_large_input_with_many_rectangles() { + #[rustfmt::skip] + let input = &[ "+---+--+----+", "| +--+----+", "+---+--+ |", @@ -147,19 +172,25 @@ fn large_input_with_many_rectangles() { "+------+ | |", " +-+", ]; - assert_eq!(60, count(lines)) + let output = rectangles::count(input); + let expected = 60; + assert_eq!(output, expected); } #[test] #[ignore] -fn three_rectangles_no_shared_parts() { +fn test_rectangles_must_have_four_sides() { #[rustfmt::skip] - let lines = &[ - " +-+ ", + let input = &[ + "+-+ +-+", + "| | | |", + "+-+-+-+", " | | ", "+-+-+-+", "| | | |", "+-+ +-+", ]; - assert_eq!(3, count(lines)) + let output = rectangles::count(input); + let expected = 5; + assert_eq!(output, expected); }