Skip to content

Commit

Permalink
Sync pig-latin with problem-specifications (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor authored Dec 19, 2023
1 parent 1234952 commit f3e544c
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 30 deletions.
14 changes: 14 additions & 0 deletions exercises/practice/pig-latin/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use {{ crate_name }}::*;

{% for test in cases %}
#[test]
{% if loop.index != 1 -%}
#[ignore]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
let input = {{ test.input.phrase | json_encode() }};
let output = {{ fn_names[0] }}(input);
let expected = {{ test.expected | json_encode() }};
assert_eq!(output, expected);
}
{% endfor -%}
79 changes: 76 additions & 3 deletions exercises/practice/pig-latin/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
# 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.

[11567f84-e8c6-4918-aedb-435f0b73db57]
description = "ay is added to words that start with vowels -> word beginning with a"

[f623f581-bc59-4f45-9032-90c3ca9d2d90]
description = "ay is added to words that start with vowels -> word beginning with e"

[7dcb08b3-23a6-4e8a-b9aa-d4e859450d58]
description = "ay is added to words that start with vowels -> word beginning with i"

[0e5c3bff-266d-41c8-909f-364e4d16e09c]
description = "ay is added to words that start with vowels -> word beginning with o"

[614ba363-ca3c-4e96-ab09-c7320799723c]
description = "ay is added to words that start with vowels -> word beginning with u"

[bf2538c6-69eb-4fa7-a494-5a3fec911326]
description = "ay is added to words that start with vowels -> word beginning with a vowel and followed by a qu"

[e5be8a01-2d8a-45eb-abb4-3fcc9582a303]
description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with p"

[d36d1e13-a7ed-464d-a282-8820cb2261ce]
description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with k"

[d838b56f-0a89-4c90-b326-f16ff4e1dddc]
description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with x"

[bce94a7a-a94e-4e2b-80f4-b2bb02e40f71]
description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with q without a following u"

[c01e049a-e3e2-451c-bf8e-e2abb7e438b8]
description = "some letter clusters are treated like a single consonant -> word beginning with ch"

[9ba1669e-c43f-4b93-837a-cfc731fd1425]
description = "some letter clusters are treated like a single consonant -> word beginning with qu"

[92e82277-d5e4-43d7-8dd3-3a3b316c41f7]
description = "some letter clusters are treated like a single consonant -> word beginning with qu and a preceding consonant"

[79ae4248-3499-4d5b-af46-5cb05fa073ac]
description = "some letter clusters are treated like a single consonant -> word beginning with th"

[e0b3ae65-f508-4de3-8999-19c2f8e243e1]
description = "some letter clusters are treated like a single consonant -> word beginning with thr"

[20bc19f9-5a35-4341-9d69-1627d6ee6b43]
description = "some letter clusters are treated like a single consonant -> word beginning with sch"

[54b796cb-613d-4509-8c82-8fbf8fc0af9e]
description = "some letter clusters are treated like a single vowel -> word beginning with yt"

[8c37c5e1-872e-4630-ba6e-d20a959b67f6]
description = "some letter clusters are treated like a single vowel -> word beginning with xr"

[a4a36d33-96f3-422c-a233-d4021460ff00]
description = "position of y in a word determines if it is a consonant or a vowel -> y is treated like a consonant at the beginning of a word"

[adc90017-1a12-4100-b595-e346105042c7]
description = "position of y in a word determines if it is a consonant or a vowel -> y is treated like a vowel at the end of a consonant cluster"

[29b4ca3d-efe5-4a95-9a54-8467f2e5e59a]
description = "position of y in a word determines if it is a consonant or a vowel -> y as second letter in two letter word"

[44616581-5ce3-4a81-82d0-40c7ab13d2cf]
description = "phrases are translated -> a whole phrase"
126 changes: 99 additions & 27 deletions exercises/practice/pig-latin/tests/pig-latin.rs
Original file line number Diff line number Diff line change
@@ -1,126 +1,198 @@
use pig_latin as pl;
use pig_latin::*;

#[test]
fn word_beginning_with_a() {
assert_eq!(pl::translate("apple"), "appleay");
let input = "apple";
let output = translate(input);
let expected = "appleay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_e() {
assert_eq!(pl::translate("ear"), "earay");
let input = "ear";
let output = translate(input);
let expected = "earay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_i() {
assert_eq!(pl::translate("igloo"), "iglooay");
let input = "igloo";
let output = translate(input);
let expected = "iglooay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_o() {
assert_eq!(pl::translate("object"), "objectay");
let input = "object";
let output = translate(input);
let expected = "objectay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_u() {
assert_eq!(pl::translate("under"), "underay");
let input = "under";
let output = translate(input);
let expected = "underay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_a_vowel_and_followed_by_a_qu() {
assert_eq!(pl::translate("equal"), "equalay");
let input = "equal";
let output = translate(input);
let expected = "equalay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_p() {
assert_eq!(pl::translate("pig"), "igpay");
let input = "pig";
let output = translate(input);
let expected = "igpay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_k() {
assert_eq!(pl::translate("koala"), "oalakay");
}

#[test]
#[ignore]
fn word_beginning_with_y() {
assert_eq!(pl::translate("yellow"), "ellowyay");
let input = "koala";
let output = translate(input);
let expected = "oalakay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_x() {
assert_eq!(pl::translate("xenon"), "enonxay");
let input = "xenon";
let output = translate(input);
let expected = "enonxay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_q_without_a_following_u() {
assert_eq!(pl::translate("qat"), "atqay");
let input = "qat";
let output = translate(input);
let expected = "atqay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_ch() {
assert_eq!(pl::translate("chair"), "airchay");
let input = "chair";
let output = translate(input);
let expected = "airchay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_qu() {
assert_eq!(pl::translate("queen"), "eenquay");
let input = "queen";
let output = translate(input);
let expected = "eenquay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_qu_and_a_preceding_consonant() {
assert_eq!(pl::translate("square"), "aresquay");
let input = "square";
let output = translate(input);
let expected = "aresquay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_th() {
assert_eq!(pl::translate("therapy"), "erapythay");
let input = "therapy";
let output = translate(input);
let expected = "erapythay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_thr() {
assert_eq!(pl::translate("thrush"), "ushthray");
let input = "thrush";
let output = translate(input);
let expected = "ushthray";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_sch() {
assert_eq!(pl::translate("school"), "oolschay");
let input = "school";
let output = translate(input);
let expected = "oolschay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_yt() {
assert_eq!(pl::translate("yttria"), "yttriaay");
let input = "yttria";
let output = translate(input);
let expected = "yttriaay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn word_beginning_with_xr() {
assert_eq!(pl::translate("xray"), "xrayay");
let input = "xray";
let output = translate(input);
let expected = "xrayay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn y_is_treated_like_a_consonant_at_the_beginning_of_a_word() {
let input = "yellow";
let output = translate(input);
let expected = "ellowyay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn y_is_treated_like_a_vowel_at_the_end_of_a_consonant_cluster() {
assert_eq!(pl::translate("rhythm"), "ythmrhay");
let input = "rhythm";
let output = translate(input);
let expected = "ythmrhay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn y_as_second_letter_in_two_letter_word() {
let input = "my";
let output = translate(input);
let expected = "ymay";
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn a_whole_phrase() {
assert_eq!(pl::translate("quick fast run"), "ickquay astfay unray");
let input = "quick fast run";
let output = translate(input);
let expected = "ickquay astfay unray";
assert_eq!(output, expected);
}

0 comments on commit f3e544c

Please sign in to comment.