Skip to content

Commit

Permalink
Sync proverb with problem-specifications (#1789)
Browse files Browse the repository at this point in the history
[no important files changed]
  • Loading branch information
senekor authored Nov 20, 2023
1 parent f9278f3 commit a6688ba
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 35 deletions.
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);
}

0 comments on commit a6688ba

Please sign in to comment.