Skip to content

Commit

Permalink
Sync scrabble-score with problem-specifications (#1772)
Browse files Browse the repository at this point in the history
The additional tests were not upstreamed, because they are unicode related.
Handling unicode is tedious and out-of-scope for many languages.
  • Loading branch information
senekor authored Nov 17, 2023
1 parent a8d71fe commit ffa30af
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 28 deletions.
20 changes: 20 additions & 0 deletions exercises/practice/scrabble-score/.meta/additional-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uuid": "9e0faee7-dc23-460b-afec-17c7145ae564",
"description": "non english scrabble letters do not score",
"property": "score",
"input": {
"word": "piñata"
},
"expected": 7
},
{
"uuid": "3099e8fd-0077-4520-be33-54bb9a1c0dc7",
"description": "german letters do not score",
"property": "score",
"input": {
"word": "STRAßE"
},
"expected": 5
}
]
12 changes: 12 additions & 0 deletions exercises/practice/scrabble-score/.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 | slugify | replace(from="-", to="_") }}() {
let input = {{ test.input.word | json_encode() }};
let output = {{ crate_name }}::{{ fn_names[0] }}(input);
let expected = {{ test.expected | json_encode() }};
assert_eq!(output, expected);
}
{% endfor -%}
43 changes: 40 additions & 3 deletions exercises/practice/scrabble-score/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
# 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.

[f46cda29-1ca5-4ef2-bd45-388a767e3db2]
description = "lowercase letter"

[f7794b49-f13e-45d1-a933-4e48459b2201]
description = "uppercase letter"

[eaba9c76-f9fa-49c9-a1b0-d1ba3a5b31fa]
description = "valuable letter"

[f3c8c94e-bb48-4da2-b09f-e832e103151e]
description = "short word"

[71e3d8fa-900d-4548-930e-68e7067c4615]
description = "short, valuable word"

[d3088ad9-570c-4b51-8764-c75d5a430e99]
description = "medium word"

[fa20c572-ad86-400a-8511-64512daac352]
description = "medium, valuable word"

[9336f0ba-9c2b-4fa0-bd1c-2e2d328cf967]
description = "long, mixed-case word"

[1e34e2c3-e444-4ea7-b598-3c2b46fd2c10]
description = "english-like word"

[4efe3169-b3b6-4334-8bae-ff4ef24a7e4f]
description = "empty input"

[3b305c1c-f260-4e15-a5b5-cb7d3ea7c3d7]
description = "entire alphabet available"
91 changes: 66 additions & 25 deletions exercises/practice/scrabble-score/tests/scrabble-score.rs
Original file line number Diff line number Diff line change
@@ -1,74 +1,115 @@
use scrabble_score::*;

#[test]
fn a_is_worth_one_point() {
assert_eq!(score("a"), 1);
fn lowercase_letter() {
let input = "a";
let output = scrabble_score::score(input);
let expected = 1;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn scoring_is_case_insensitive() {
assert_eq!(score("A"), 1);
fn uppercase_letter() {
let input = "A";
let output = scrabble_score::score(input);
let expected = 1;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn f_is_worth_four() {
assert_eq!(score("f"), 4);
fn valuable_letter() {
let input = "f";
let output = scrabble_score::score(input);
let expected = 4;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn two_one_point_letters_make_a_two_point_word() {
assert_eq!(score("at"), 2);
fn short_word() {
let input = "at";
let output = scrabble_score::score(input);
let expected = 2;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn three_letter_word() {
assert_eq!(score("zoo"), 12);
fn short_valuable_word() {
let input = "zoo";
let output = scrabble_score::score(input);
let expected = 12;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn medium_word() {
assert_eq!(score("street"), 6);
let input = "street";
let output = scrabble_score::score(input);
let expected = 6;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn longer_words_with_valuable_letters() {
assert_eq!(score("quirky"), 22);
fn medium_valuable_word() {
let input = "quirky";
let output = scrabble_score::score(input);
let expected = 22;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn long_mixed_case_word() {
assert_eq!(score("OxyphenButazone"), 41);
let input = "OxyphenButazone";
let output = scrabble_score::score(input);
let expected = 41;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn non_english_scrabble_letters_do_not_score() {
assert_eq!(score("pinata"), 8, "'n' should score 1");
assert_eq!(score("piñata"), 7, "'ñ' should score 0");
fn english_like_word() {
let input = "pinata";
let output = scrabble_score::score(input);
let expected = 8;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn empty_words_are_worth_zero() {
assert_eq!(score(""), 0);
fn empty_input() {
let input = "";
let output = scrabble_score::score(input);
let expected = 0;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn all_letters_work() {
assert_eq!(score("abcdefghijklmnopqrstuvwxyz"), 87);
fn entire_alphabet_available() {
let input = "abcdefghijklmnopqrstuvwxyz";
let output = scrabble_score::score(input);
let expected = 87;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn non_english_scrabble_letters_do_not_score() {
let input = "piñata";
let output = scrabble_score::score(input);
let expected = 7;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn german_letters_do_not_score() {
assert_eq!(score("STRASSE"), 7, "\"SS\" should score 2");
assert_eq!(score("STRAßE"), 5, "'ß' should score 0");
let input = "STRAßE";
let output = scrabble_score::score(input);
let expected = 5;
assert_eq!(output, expected);
}

0 comments on commit ffa30af

Please sign in to comment.