diff --git a/exercises/practice/proverb/.docs/instructions.md b/exercises/practice/proverb/.docs/instructions.md index 0da9da2cb..f6fb85932 100644 --- a/exercises/practice/proverb/.docs/instructions.md +++ b/exercises/practice/proverb/.docs/instructions.md @@ -2,7 +2,8 @@ For want of a horseshoe nail, a kingdom was lost, or so the saying goes. -Given a list of inputs, generate the relevant proverb. For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme: +Given a list of inputs, generate the relevant proverb. +For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme: ```text For want of a nail the shoe was lost. @@ -14,4 +15,5 @@ For want of a battle the kingdom was lost. And all for the want of a nail. ``` -Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length (including zero elements, generating empty output) and content. No line of the output text should be a static, unchanging string; all should vary according to the input given. +Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. +No line of the output text should be a static, unchanging string; all should vary according to the input given. diff --git a/exercises/practice/proverb/.meta/config.json b/exercises/practice/proverb/.meta/config.json index d3b955805..a2346dfa0 100644 --- a/exercises/practice/proverb/.meta/config.json +++ b/exercises/practice/proverb/.meta/config.json @@ -32,5 +32,5 @@ }, "blurb": "For want of a horseshoe nail, a kingdom was lost, or so the saying goes. Output the full text of this proverbial rhyme.", "source": "Wikipedia", - "source_url": "http://en.wikipedia.org/wiki/For_Want_of_a_Nail" + "source_url": "https://en.wikipedia.org/wiki/For_Want_of_a_Nail" } diff --git a/exercises/practice/proverb/.meta/test_template.tera b/exercises/practice/proverb/.meta/test_template.tera new file mode 100644 index 000000000..0560a6f7d --- /dev/null +++ b/exercises/practice/proverb/.meta/test_template.tera @@ -0,0 +1,16 @@ +{% for test in cases %} +#[test] +{% if loop.index != 1 -%} +#[ignore] +{% endif -%} +fn {{ test.description | slugify | replace(from="-", to="_") }}() { + let input = &{{ test.input.strings | json_encode() }}; + let output = {{ crate_name }}::{{ fn_names[0] }}(input); + {% if test.expected | length == 0 -%} + let expected = String::new(); + {%- else -%} + let expected: String = {{ test.expected | json_encode() }}.join("\n"); + {%- endif %} + assert_eq!(output, expected); +} +{% endfor -%} diff --git a/exercises/practice/proverb/.meta/tests.toml b/exercises/practice/proverb/.meta/tests.toml index be690e975..dc92a0c96 100644 --- a/exercises/practice/proverb/.meta/tests.toml +++ b/exercises/practice/proverb/.meta/tests.toml @@ -1,3 +1,28 @@ -# 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. + +[e974b73e-7851-484f-8d6d-92e07fe742fc] +description = "zero pieces" + +[2fcd5f5e-8b82-4e74-b51d-df28a5e0faa4] +description = "one piece" + +[d9d0a8a1-d933-46e2-aa94-eecf679f4b0e] +description = "two pieces" + +[c95ef757-5e94-4f0d-a6cb-d2083f5e5a83] +description = "three pieces" + +[433fb91c-35a2-4d41-aeab-4de1e82b2126] +description = "full proverb" + +[c1eefa5a-e8d9-41c7-91d4-99fab6d6b9f7] +description = "four pieces modernized" diff --git a/exercises/practice/proverb/tests/proverb.rs b/exercises/practice/proverb/tests/proverb.rs index 5a921790e..be930b16d 100644 --- a/exercises/practice/proverb/tests/proverb.rs +++ b/exercises/practice/proverb/tests/proverb.rs @@ -1,53 +1,55 @@ -use proverb::build_proverb; +#[test] +fn zero_pieces() { + let input = &[]; + let output = proverb::build_proverb(input); + let expected = String::new(); + assert_eq!(output, expected); +} #[test] +#[ignore] +fn one_piece() { + let input = &["nail"]; + let output = proverb::build_proverb(input); + let expected: String = ["And all for the want of a nail."].join("\n"); + assert_eq!(output, expected); +} + +#[test] +#[ignore] fn two_pieces() { - let input = vec!["nail", "shoe"]; - let expected = [ + let input = &["nail", "shoe"]; + let output = proverb::build_proverb(input); + let expected: String = [ "For want of a nail the shoe was lost.", "And all for the want of a nail.", ] .join("\n"); - assert_eq!(build_proverb(&input), expected); + assert_eq!(output, expected); } -// Notice the change in the last line at three pieces. #[test] #[ignore] fn three_pieces() { - let input = vec!["nail", "shoe", "horse"]; - let expected = [ + let input = &["nail", "shoe", "horse"]; + let output = proverb::build_proverb(input); + let expected: String = [ "For want of a nail the shoe was lost.", "For want of a shoe the horse was lost.", "And all for the want of a nail.", ] .join("\n"); - assert_eq!(build_proverb(&input), expected); -} - -#[test] -#[ignore] -fn one_piece() { - let input = vec!["nail"]; - let expected = String::from("And all for the want of a nail."); - assert_eq!(build_proverb(&input), expected); -} - -#[test] -#[ignore] -fn zero_pieces() { - let input: Vec<&str> = vec![]; - let expected = String::new(); - assert_eq!(build_proverb(&input), expected); + assert_eq!(output, expected); } #[test] #[ignore] -fn full() { - let input = vec![ +fn full_proverb() { + let input = &[ "nail", "shoe", "horse", "rider", "message", "battle", "kingdom", ]; - let expected = [ + let output = proverb::build_proverb(input); + let expected: String = [ "For want of a nail the shoe was lost.", "For want of a shoe the horse was lost.", "For want of a horse the rider was lost.", @@ -57,19 +59,20 @@ fn full() { "And all for the want of a nail.", ] .join("\n"); - assert_eq!(build_proverb(&input), expected); + assert_eq!(output, expected); } #[test] #[ignore] -fn three_pieces_modernized() { - let input = vec!["pin", "gun", "soldier", "battle"]; - let expected = [ +fn four_pieces_modernized() { + let input = &["pin", "gun", "soldier", "battle"]; + let output = proverb::build_proverb(input); + let expected: String = [ "For want of a pin the gun was lost.", "For want of a gun the soldier was lost.", "For want of a soldier the battle was lost.", "And all for the want of a pin.", ] .join("\n"); - assert_eq!(build_proverb(&input), expected); + assert_eq!(output, expected); }