-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
AnagramTest.ceylon
47 lines (45 loc) · 1.83 KB
/
AnagramTest.ceylon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ceylon.test { ... }
shared {[String, {String*}, {String*}]*} cases =>
{
// no matches
["diaper", {"hello", "world", "zombies", "pants"}, {}],
// detects simple anagram
["ant", {"tan", "stand", "at"}, {"tan"}],
// does not detect false positives
["galea", {"eagle"}, {}],
// detects multiple anagrams
["master", {"stream", "pigeon", "maters"}, {"stream", "maters"}],
// does not detect anagram subsets
["good", {"dog", "goody"}, {}],
// detects anagram
["listen", {"enlists", "google", "inlets", "banana"}, {"inlets"}],
// detects multiple anagrams
[
"allergy",
{"gallery", "ballerina", "regally", "clergy", "largely", "leading"},
{"gallery", "regally", "largely"}
],
// does not detect identical words
["corn", {"corn", "dark", "Corn", "rank", "CORN", "cron", "park"}, {"cron"}],
// does not detect non-anagrams with identical checksum
["mass", {"last"}, {}],
// detects anagrams case-insensitively
["Orchestra", {"cashregister", "Carthorse", "radishes"}, {"Carthorse"}],
// detects anagrams using case-insensitive subject
["Orchestra", {"cashregister", "carthorse", "radishes"}, {"carthorse"}],
// detects anagrams using case-insensitive possible matches
["orchestra", {"cashregister", "Carthorse", "radishes"}, {"Carthorse"}],
// does not detect a word as its own anagram
["banana", {"Banana"}, {}],
// does not detect a anagram if the original word is repeated
["go", {"go Go GO"}, {}],
// anagrams must use all letters exactly once
["tapper", {"patter"}, {}],
// capital word is not own anagram
["BANANA", {"Banana"}, {}]
};
test
parameters(`value cases`)
shared void testAnagram(String subject, {String*} candidates, {String*} expected) {
assertEquals(sort(anagrams(subject, candidates)), sort(expected));
}