Browse Source

Check variations of compound taboo words

Thomas Dy 10 years ago
parent
commit
c8d035551b
2 changed files with 22 additions and 1 deletions
  1. 5 1
      app/models/Card.scala
  2. 17 0
      test/ApplicationSpec.scala

+ 5 - 1
app/models/Card.scala

@@ -51,10 +51,14 @@ object Card {
 
 case class Card(word: String, taboo: Set[String]) {
 
-  lazy val tabooRegex = (taboo + word).map { word =>
+  lazy val tabooRegex = (taboo + word).flatMap(compoundWords).map { word =>
     ("\\b"+word.toLowerCase+"\\b").r
   }
 
+  def compoundWords(text: String): Seq[String] = {
+    text.split(" ") :+ text.replace(" ", "")
+  }
+
   def isTaboo(text: String) = {
     val lower = text.toLowerCase
 

+ 17 - 0
test/ApplicationSpec.scala

@@ -61,6 +61,23 @@ class ApplicationSpec extends Specification {
       card.isTaboo("swords") must beFalse
     }
 
+    val compoundCard = Card("test card", Set("much words", "such test", "very pass"))
+
+    "Check compound taboo word variations" in {
+      compoundCard.isTaboo("test") must beTrue
+      compoundCard.isTaboo("card") must beTrue
+      compoundCard.isTaboo("much") must beTrue
+      compoundCard.isTaboo("such") must beTrue
+      compoundCard.isTaboo("words") must beTrue
+      compoundCard.isTaboo("very") must beTrue
+      compoundCard.isTaboo("pass") must beTrue
+
+      compoundCard.isTaboo("testcard") must beTrue
+      compoundCard.isTaboo("muchwords") must beTrue
+      compoundCard.isTaboo("suchtest") must beTrue
+      compoundCard.isTaboo("verypass") must beTrue
+    }
+
   }
 
   "Team" should {