Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync proverb with problem-specifications #1789

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions exercises/practice/proverb/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
2 changes: 1 addition & 1 deletion exercises/practice/proverb/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
16 changes: 16 additions & 0 deletions exercises/practice/proverb/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -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 -%}
31 changes: 28 additions & 3 deletions exercises/practice/proverb/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
67 changes: 35 additions & 32 deletions exercises/practice/proverb/tests/proverb.rs
Original file line number Diff line number Diff line change
@@ -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.",
Expand All @@ -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);
}