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

Sync anagram exercise #262

Merged
merged 1 commit into from
Dec 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description = "no matches"

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

[03eb9bbe-8906-4ea0-84fa-ffe711b52c8b]
description = "detects two anagrams"
Expand Down Expand Up @@ -45,12 +46,35 @@ 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

[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"
31 changes: 17 additions & 14 deletions exercises/practice/anagram/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.4.0 *)
(* version 1.5.0 *)

use "testlib.sml";
use "anagram.sml";
Expand All @@ -11,14 +11,8 @@ val testsuite =
test "no matches"
(fn _ => anagramsFor "diaper" ["hello", "world", "zombies", "pants"] |> Expect.equalTo []),

test "detects simple anagram"
(fn _ => anagramsFor "ant" ["tan", "stand", "at"] |> Expect.equalTo ["tan"]),

test "does not detect false positives"
(fn _ => anagramsFor "galea" ["eagle"] |> Expect.equalTo []),

test "detects two anagrams"
(fn _ => anagramsFor "master" ["stream", "pigeon", "maters"] |> Expect.equalTo ["stream", "maters"]),
(fn _ => anagramsFor "solemn" ["lemons", "cherry", "melons"] |> Expect.equalTo ["lemons", "melons"]),

test "does not detect anagram subsets"
(fn _ => anagramsFor "good" ["dog", "goody"] |> Expect.equalTo []),
Expand All @@ -29,8 +23,8 @@ val testsuite =
test "detects three anagrams"
(fn _ => anagramsFor "allergy" ["gallery", "ballerina", "regally", "clergy", "largely", "leading"] |> Expect.equalTo ["gallery", "regally", "largely"]),

test "does not detect identical words"
(fn _ => anagramsFor "corn" ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"] |> Expect.equalTo ["cron"]),
test "detects multiple anagrams with different case"
(fn _ => anagramsFor "nose" ["Eons", "ONES"] |> Expect.equalTo ["Eons", "ONES"]),

test "does not detect non-anagrams with identical checksum"
(fn _ => anagramsFor "mass" ["last"] |> Expect.equalTo []),
Expand All @@ -44,14 +38,23 @@ val testsuite =
test "detects anagrams using case-insensitive possible matches"
(fn _ => anagramsFor "orchestra" ["cashregister", "Carthorse", "radishes"] |> Expect.equalTo ["Carthorse"]),

test "does not detect a anagram if the original word is repeated"
(fn _ => anagramsFor "go" ["go Go GO"] |> Expect.equalTo []),
test "does not detect an anagram if the original word is repeated"
(fn _ => anagramsFor "go" ["goGoGO"] |> Expect.equalTo []),

test "anagrams must use all letters exactly once"
(fn _ => anagramsFor "tapper" ["patter"] |> Expect.equalTo []),

test "words are not anagrams of themselves (case-insensitive)"
(fn _ => anagramsFor "BANANA" ["BANANA", "Banana", "banana"] |> Expect.equalTo [])
test "words are not anagrams of themselves"
(fn _ => anagramsFor "BANANA" ["BANANA"] |> Expect.equalTo []),

test "words are not anagrams of themselves even if letter case is partially different"
(fn _ => anagramsFor "BANANA" ["Banana"] |> Expect.equalTo []),

test "words are not anagrams of themselves even if letter case is completely different"
(fn _ => anagramsFor "BANANA" ["banana"] |> Expect.equalTo []),

test "words other than themselves can be anagrams"
(fn _ => anagramsFor "LISTEN" ["LISTEN", "Silent"] |> Expect.equalTo ["Silent"])
]

val _ = Test.run testsuite