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

Update anagram tests #784

Merged
merged 8 commits into from
Feb 1, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 46 additions & 3 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# 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.

[dd40c4d2-3c8b-44e5-992a-f42b393ec373]
description = "no matches"

[b3cca662-f50a-489e-ae10-ab8290a09bdc]
description = "detects two anagrams"
include = false

[03eb9bbe-8906-4ea0-84fa-ffe711b52c8b]
description = "detects two anagrams"
reimplements = "b3cca662-f50a-489e-ae10-ab8290a09bdc"

[a27558ee-9ba0-4552-96b1-ecf665b06556]
description = "does not detect anagram subsets"
Expand Down Expand Up @@ -34,12 +46,43 @@ description = "detects anagrams using case-insensitive possible matches"

[7cc195ad-e3c7-44ee-9fd2-d3c344806a2c]
description = "does not detect an anagram if the original word is repeated"
include = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaeng Should this test be included in the C++ unit test file or not?
The canonical data says it's superseded and this line of tests.toml says it's not included, but the unit test file now includes it.


[630abb71-a94e-4715-8395-179ec1df9f91]
description = "does not detect an anagram if the original word is repeated"
reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c"

[9878a1c9-d6ea-4235-ae51-3ea2befd6842]
description = "anagrams must use all letters exactly once"

[85757361-4535-45fd-ac0e-3810d40debc1]
description = "words are not anagrams of themselves (case-insensitive)"
include = false

[68934ed0-010b-4ef9-857a-20c9012d1ebf]
description = "words are not anagrams of themselves"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[589384f3-4c8a-4e7d-9edc-51c3e5f0c90e]
description = "words are not anagrams of themselves even if letter case is partially different"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[ba53e423-7e02-41ee-9ae2-71f91e6d18e6]
description = "words are not anagrams of themselves even if letter case is completely different"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[a0705568-628c-4b55-9798-82e4acde51ca]
description = "words other than themselves can be anagrams"
include = false

[33d3f67e-fbb9-49d3-a90e-0beb00861da7]
description = "words other than themselves can be anagrams"
reimplements = "a0705568-628c-4b55-9798-82e4acde51ca"

[a6854f66-eec1-4afd-a137-62ef2870c051]
description = "handles case of greek letters"
include = false

[fd3509e5-e3ba-409d-ac3d-a9ac84d13296]
description = "different characters may have the same bytes"
include = false
56 changes: 37 additions & 19 deletions exercises/practice/anagram/anagram_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ TEST_CASE("no_matches")
}

#if defined(EXERCISM_RUN_ALL_TESTS)
TEST_CASE("detects_two_anagrams")
TEST_CASE("detects_two_anagrams", "[findAnagrams][03eb9bbe-8906-4ea0-84fa-ffe711b52c8b]")
{
auto subject = anagram::anagram("master");
auto matches = subject.matches({"stream", "pigeon", "maters"});
vector<string> expected{"stream", "maters"};
auto subject = anagram::anagram("solemn");
auto matches = subject.matches({"lemons", "cherry", "melons"});
vector<string> expected{"lemons", "melons"};

REQUIRE(expected == matches);
}

TEST_CASE("does_not_detect_anagram_subsets")
TEST_CASE("does_not_detect_anagram_subsets", "[findAnagrams][a27558ee-9ba0-4552-96b1-ecf665b06556]")
{
auto subject = anagram::anagram("good");
auto matches = subject.matches({"dog", "goody"});
Expand All @@ -38,7 +38,7 @@ TEST_CASE("does_not_detect_anagram_subsets")
REQUIRE(expected == matches);
}

TEST_CASE("detects_anagram")
TEST_CASE("detects_anagram", "[findAnagrams][64cd4584-fc15-4781-b633-3d814c4941a4]")
{
auto subject = anagram::anagram("listen");
auto matches = subject.matches({"enlists", "google", "inlets", "banana"});
Expand All @@ -47,7 +47,7 @@ TEST_CASE("detects_anagram")
REQUIRE(expected == matches);
}

TEST_CASE("detects_three_anagrams")
TEST_CASE("detects_three_anagrams", "[findAnagrams][99c91beb-838f-4ccd-b123-935139917283]")
{
auto subject = anagram::anagram("allergy");
auto matches = subject.matches({
Expand All @@ -63,7 +63,7 @@ TEST_CASE("detects_three_anagrams")
REQUIRE(expected == matches);
}

TEST_CASE("detects_multiple_anagrams_with_different_case")
TEST_CASE("detects_multiple_anagrams_with_different_case", "[findAnagrams][78487770-e258-4e1f-a646-8ece10950d90]")
{
auto subject = anagram::anagram("nose");
auto matches = subject.matches({"Eons", "ONES"});
Expand All @@ -72,7 +72,7 @@ TEST_CASE("detects_multiple_anagrams_with_different_case")
REQUIRE(expected == matches);
}

TEST_CASE("does_not_detect_non_anagrams_with_identical_checksum")
TEST_CASE("does_not_detect_non_anagrams_with_identical_checksum", "[findAnagrams][1d0ab8aa-362f-49b7-9902-3d0c668d557b]")
{
auto subject = anagram::anagram("mass");
auto matches = subject.matches({"last"});
Expand All @@ -81,7 +81,7 @@ TEST_CASE("does_not_detect_non_anagrams_with_identical_checksum")
REQUIRE(expected == matches);
}

TEST_CASE("detects_anagrams_case_insensitively")
TEST_CASE("detects_anagrams_case_insensitively", "[findAnagrams][9e632c0b-c0b1-4804-8cc1-e295dea6d8a8]")
{
auto subject = anagram::anagram("Orchestra");
auto matches = subject.matches({"cashregister", "Carthorse", "radishes"});
Expand All @@ -90,7 +90,7 @@ TEST_CASE("detects_anagrams_case_insensitively")
REQUIRE(expected == matches);
}

TEST_CASE("detects_anagrams_using_case_insensitive_subject")
TEST_CASE("detects_anagrams_using_case_insensitive_subject", "[findAnagrams][b248e49f-0905-48d2-9c8d-bd02d8c3e392]")
{
auto subject = anagram::anagram("Orchestra");
auto matches = subject.matches({"cashregister", "carthorse", "radishes"});
Expand All @@ -99,7 +99,7 @@ TEST_CASE("detects_anagrams_using_case_insensitive_subject")
REQUIRE(expected == matches);
}

TEST_CASE("detects_anagrams_using_case_insensitive_possible_matches")
TEST_CASE("detects_anagrams_using_case_insensitive_possible_matches", "[findAnagrams][f367325c-78ec-411c-be76-e79047f4bd54]")
{
auto subject = anagram::anagram("orchestra");
auto matches = subject.matches({"cashregister", "Carthorse", "radishes"});
Expand All @@ -108,16 +108,16 @@ TEST_CASE("detects_anagrams_using_case_insensitive_possible_matches")
REQUIRE(expected == matches);
}

TEST_CASE("does_not_detect_a_anagram_if_the_original_word_is_repeated")
TEST_CASE("does_not_detect_an_anagram_if_the_original_word_is_repeated", "[findAnagrams][630abb71-a94e-4715-8395-179ec1df9f91]")
{
auto subject = anagram::anagram("go");
auto matches = subject.matches({"go Go GO"});
auto matches = subject.matches({"goGoGO"});
vector<string> expected;

REQUIRE(expected == matches);
}

TEST_CASE("anagrams_must_use_all_letters_exactly_once")
TEST_CASE("anagrams_must_use_all_letters_exactly_once", "[findAnagrams][9878a1c9-d6ea-4235-ae51-3ea2befd6842]")
{
auto subject = anagram::anagram("tapper");
auto matches = subject.matches({"patter"});
Expand All @@ -126,19 +126,37 @@ TEST_CASE("anagrams_must_use_all_letters_exactly_once")
REQUIRE(expected == matches);
}

TEST_CASE("words_are_not_anagrams_of_themselves_case_insensitive")
TEST_CASE("words_are_not_anagrams_of_themselves", "[findAnagrams][68934ed0-010b-4ef9-857a-20c9012d1ebf]")
{
auto subject = anagram::anagram("BANANA");
auto matches = subject.matches({"BANANA", "Banana", "banana"});
auto matches = subject.matches({"BANANA"});
vector<string> expected;

REQUIRE(expected == matches);
}

TEST_CASE("words_other_than_themselves_can_be_anagrams")
TEST_CASE("words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different", "[findAnagrams][589384f3-4c8a-4e7d-9edc-51c3e5f0c90e]")
{
auto subject = anagram::anagram("BANANA");
auto matches = subject.matches({"Banana"});
vector<string> expected;

REQUIRE(expected == matches);
}

TEST_CASE("words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different", "[findAnagrams][ba53e423-7e02-41ee-9ae2-71f91e6d18e6]")
{
auto subject = anagram::anagram("BANANA");
auto matches = subject.matches({"banana"});
vector<string> expected;

REQUIRE(expected == matches);
}

TEST_CASE("words_other_than_themselves_can_be_anagrams", "[findAnagrams][33d3f67e-fbb9-49d3-a90e-0beb00861da7]")
{
auto subject = anagram::anagram("LISTEN");
auto matches = subject.matches({"Listen", "Silent", "LISTEN"});
auto matches = subject.matches({"Silent", "LISTEN"});
vector<string> expected{"Silent"};

REQUIRE(expected == matches);
Expand Down