Skip to content

Commit

Permalink
Merge pull request #596 from ricemery/anagram
Browse files Browse the repository at this point in the history
Update anagram exercise to match latest test data. Refs #488
  • Loading branch information
ErikSchierboom authored Jan 1, 2019
2 parents f8be82c + 7edcd1c commit 308d2fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion exercises/anagram/example.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Anagram {
def anagrams(word: String, anagrams: Seq[String]) =
def findAnagrams(word: String, anagrams: Seq[String]) =
anagrams.filter(w => doesMatch(word, w)).filterNot(w => isIdentical(word, w))

private def doesMatch(word1: String, word2: String) =
Expand Down
50 changes: 29 additions & 21 deletions exercises/anagram/src/test/scala/AnagramTest.scala
Original file line number Diff line number Diff line change
@@ -1,77 +1,85 @@
import org.scalatest.{Matchers, FunSuite}

/** @version 1.2.0 */
/** @version 1.4.0 */
class AnagramTest extends FunSuite with Matchers {

test("no matches") {
Anagram.anagrams("diaper", List("hello", "world", "zombies", "pants")) should be(
Anagram.findAnagrams("diaper", List("hello", "world", "zombies", "pants")) should be(
List())
}

test("detects two anagrams") {
pending
Anagram.anagrams("master", List("stream", "pigeon", "maters")) should be(
Anagram.findAnagrams("master", List("stream", "pigeon", "maters")) should be(
List("stream", "maters"))
}

test("does not detect anagram subsets") {
pending
Anagram.anagrams("good", List("dog", "goody")) should be(List())
Anagram.findAnagrams("good", List("dog", "goody")) should be(List())
}

test("detects anagram") {
pending
Anagram.anagrams("listen", List("enlists", "google", "inlets", "banana")) should be(
List("inlets"))
Anagram.findAnagrams(
"listen",
List("enlists", "google", "inlets", "banana")) should be(List("inlets"))
}

test("detects three anagrams") {
pending
Anagram.anagrams("allergy",
List("gallery",
"ballerina",
"regally",
"clergy",
"largely",
"leading")) should be(
Anagram.findAnagrams("allergy",
List("gallery",
"ballerina",
"regally",
"clergy",
"largely",
"leading")) should be(
List("gallery", "regally", "largely"))
}

test("does not detect non-anagrams with identical checksum") {
pending
Anagram.anagrams("mass", List("last")) should be(List())
Anagram.findAnagrams("mass", List("last")) should be(List())
}

test("detects anagrams case-insensitively") {
pending
Anagram.anagrams("Orchestra", List("cashregister", "Carthorse", "radishes")) should be(
Anagram.findAnagrams(
"Orchestra",
List("cashregister", "Carthorse", "radishes")) should be(
List("Carthorse"))
}

test("detects anagrams using case-insensitive subject") {
pending
Anagram.anagrams("Orchestra", List("cashregister", "carthorse", "radishes")) should be(
Anagram.findAnagrams(
"Orchestra",
List("cashregister", "carthorse", "radishes")) should be(
List("carthorse"))
}

test("detects anagrams using case-insensitive possible matches") {
pending
Anagram.anagrams("orchestra", List("cashregister", "Carthorse", "radishes")) should be(
Anagram.findAnagrams(
"orchestra",
List("cashregister", "Carthorse", "radishes")) should be(
List("Carthorse"))
}

test("does not detect a anagram if the original word is repeated") {
pending
Anagram.anagrams("go", List("go Go GO")) should be(List())
Anagram.findAnagrams("go", List("go Go GO")) should be(List())
}

test("anagrams must use all letters exactly once") {
pending
Anagram.anagrams("tapper", List("patter")) should be(List())
Anagram.findAnagrams("tapper", List("patter")) should be(List())
}

test("capital word is not own anagram") {
test("words are not anagrams of themselves (case-insensitive)") {
pending
Anagram.anagrams("BANANA", List("Banana")) should be(List())
Anagram.findAnagrams("BANANA", List("BANANA", "Banana", "banana")) should be(
List())
}
}

0 comments on commit 308d2fd

Please sign in to comment.