ApplicationSpec.scala 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import org.specs2.mutable._
  2. import org.specs2.runner._
  3. import org.junit.runner._
  4. import play.api.test._
  5. import play.api.test.Helpers._
  6. import models.Card
  7. import models.Team
  8. @RunWith(classOf[JUnitRunner])
  9. class ApplicationSpec extends Specification {
  10. "Card" should {
  11. val card = Card("test", Set("these", "words", "are", "not", "allowed"))
  12. "Check Taboo words correctly" in {
  13. card.isTaboo("test") must beTrue
  14. card.isTaboo("these") must beTrue
  15. card.isTaboo("words") must beTrue
  16. card.isTaboo("are") must beTrue
  17. card.isTaboo("not") must beTrue
  18. card.isTaboo("allowed") must beTrue
  19. }
  20. "Check guessed words correctly" in {
  21. card.isCorrect("test") must beTrue
  22. card.isCorrect("these") must beFalse
  23. card.isCorrect("words") must beFalse
  24. card.isCorrect("are") must beFalse
  25. card.isCorrect("not") must beFalse
  26. card.isCorrect("allowed") must beFalse
  27. }
  28. "Check case insensitively" in {
  29. card.isCorrect("test") must beTrue
  30. card.isCorrect("Test") must beTrue
  31. card.isCorrect("tEst") must beTrue
  32. card.isCorrect("teSt") must beTrue
  33. card.isCorrect("tesT") must beTrue
  34. card.isCorrect("TEST") must beTrue
  35. card.isTaboo("These") must beTrue
  36. card.isTaboo("wOrds") must beTrue
  37. card.isTaboo("arE") must beTrue
  38. card.isTaboo("nOt") must beTrue
  39. card.isTaboo("ALLOWED") must beTrue
  40. }
  41. "Check the entire message" in {
  42. card.isTaboo("The word is test") must beTrue
  43. card.isTaboo("I am not allowed to say") must beTrue
  44. card.isTaboo("*words*") must beTrue
  45. card.isTaboo("these/not/allowed") must beTrue
  46. }
  47. "Don't check parts of words" in {
  48. card.isTaboo("area") must beFalse
  49. card.isTaboo("knots") must beFalse
  50. card.isTaboo("care") must beFalse
  51. card.isTaboo("swords") must beFalse
  52. }
  53. val compoundCard = Card("test card", Set("much words", "such test", "very pass"))
  54. "Check compound taboo word variations" in {
  55. compoundCard.isTaboo("test") must beTrue
  56. compoundCard.isTaboo("card") must beTrue
  57. compoundCard.isTaboo("much") must beTrue
  58. compoundCard.isTaboo("such") must beTrue
  59. compoundCard.isTaboo("words") must beTrue
  60. compoundCard.isTaboo("very") must beTrue
  61. compoundCard.isTaboo("pass") must beTrue
  62. compoundCard.isTaboo("testcard") must beTrue
  63. compoundCard.isTaboo("muchwords") must beTrue
  64. compoundCard.isTaboo("suchtest") must beTrue
  65. compoundCard.isTaboo("verypass") must beTrue
  66. }
  67. }
  68. "Team" should {
  69. val team = new Team()
  70. "Allow players to join" in {
  71. team.join("player1")
  72. team.join("player2")
  73. team.join("player2")
  74. team.join("player3")
  75. team.hasPlayer("player1") must beTrue
  76. team.hasPlayer("player2") must beTrue
  77. team.hasPlayer("player3") must beTrue
  78. team.hasPlayer("player4") must beFalse
  79. }
  80. "Allow players to leave" in {
  81. team.leave("player3")
  82. team.hasPlayer("player3") must beFalse
  83. // should be a noop
  84. team.leave("player3")
  85. team.hasPlayer("player3") must beFalse
  86. }
  87. "Cycle between players correctly" in {
  88. team.nextPlayer() must equalTo("player1")
  89. team.nextPlayer() must equalTo("player2")
  90. team.nextPlayer() must equalTo("player1")
  91. team.join("player3")
  92. team.join("player4")
  93. team.nextPlayer() must equalTo("player2")
  94. team.nextPlayer() must equalTo("player3")
  95. team.nextPlayer() must equalTo("player4")
  96. team.nextPlayer() must equalTo("player1")
  97. team.nextPlayer() must equalTo("player2")
  98. team.leave("player3")
  99. team.nextPlayer() must equalTo("player4")
  100. team.leave("player4")
  101. team.nextPlayer() must equalTo("player1")
  102. team.nextPlayer() must equalTo("player2")
  103. }
  104. "Give the correct current player and guessers" in {
  105. team.nextPlayer() must equalTo("player1")
  106. team.player must equalTo("player1")
  107. team.guessers("player2") must beTrue
  108. }
  109. }
  110. }