Skip to content

Commit

Permalink
update acronym exercise using test generator
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Sep 9, 2023
1 parent b4376f3 commit 615028e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 46 deletions.
13 changes: 11 additions & 2 deletions exercises/practice/acronym/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@ Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name
like Portable Network Graphics to its acronym (PNG).
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).

Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input.

For example:

|Input|Output|
|-|-|
|As Soon As Possible|ASAP|
|Liquid-crystal display|LCD|
|Thank George It's Friday!|TGIF|
12 changes: 12 additions & 0 deletions exercises/practice/acronym/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% for test in cases %}
#[test]
{% if loop.index != 1 -%}
#[ignore]
{% endif -%}
fn {{ test.description | replace(from=" ", to="_") }}() {
let input = "{{ test.input.phrase }}";
let output = acronym::abbreviate(input);
let expected = "{{ test.expected }}";
assert_eq!(output, expected);
}
{% endfor -%}
13 changes: 10 additions & 3 deletions exercises/practice/acronym/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# 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.

[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4]
description = "basic"
Expand Down
77 changes: 36 additions & 41 deletions exercises/practice/acronym/tests/acronym.rs
Original file line number Diff line number Diff line change
@@ -1,84 +1,79 @@
#[test]
fn empty() {
assert_eq!(acronym::abbreviate(""), "");
}

#[test]
#[ignore]
fn basic() {
assert_eq!(acronym::abbreviate("Portable Network Graphics"), "PNG");
let input = "Portable Network Graphics";
let output = acronym::abbreviate(input);
let expected = "PNG";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn lowercase_words() {
assert_eq!(acronym::abbreviate("Ruby on Rails"), "ROR");
}

#[test]
#[ignore]
fn camelcase() {
assert_eq!(acronym::abbreviate("HyperText Markup Language"), "HTML");
let input = "Ruby on Rails";
let output = acronym::abbreviate(input);
let expected = "ROR";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn punctuation() {
assert_eq!(acronym::abbreviate("First In, First Out"), "FIFO");
let input = "First In, First Out";
let output = acronym::abbreviate(input);
let expected = "FIFO";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn all_caps_word() {
assert_eq!(
acronym::abbreviate("GNU Image Manipulation Program"),
"GIMP"
);
}

#[test]
#[ignore]
fn all_caps_word_with_punctuation() {
assert_eq!(acronym::abbreviate("PHP: Hypertext Preprocessor"), "PHP");
let input = "GNU Image Manipulation Program";
let output = acronym::abbreviate(input);
let expected = "GIMP";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn punctuation_without_whitespace() {
assert_eq!(
acronym::abbreviate("Complementary metal-oxide semiconductor"),
"CMOS"
);
let input = "Complementary metal-oxide semiconductor";
let output = acronym::abbreviate(input);
let expected = "CMOS";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn very_long_abbreviation() {
assert_eq!(
acronym::abbreviate(
"Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
),
"ROTFLSHTMDCOALM"
);
let input = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me";
let output = acronym::abbreviate(input);
let expected = "ROTFLSHTMDCOALM";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn consecutive_delimiters() {
assert_eq!(
acronym::abbreviate("Something - I made up from thin air"),
"SIMUFTA"
);
let input = "Something - I made up from thin air";
let output = acronym::abbreviate(input);
let expected = "SIMUFTA";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn apostrophes() {
assert_eq!(acronym::abbreviate("Halley's Comet"), "HC");
let input = "Halley's Comet";
let output = acronym::abbreviate(input);
let expected = "HC";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn underscore_emphasis() {
assert_eq!(acronym::abbreviate("The Road _Not_ Taken"), "TRNT");
let input = "The Road _Not_ Taken";
let output = acronym::abbreviate(input);
let expected = "TRNT";
assert_eq!(output, expected);
}

0 comments on commit 615028e

Please sign in to comment.