ApplicationSpec.scala 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. }
  54. "Team" should {
  55. val team = new Team()
  56. "Allow players to join" in {
  57. team.join("player1")
  58. team.join("player2")
  59. team.join("player2")
  60. team.join("player3")
  61. team.hasPlayer("player1") must beTrue
  62. team.hasPlayer("player2") must beTrue
  63. team.hasPlayer("player3") must beTrue
  64. team.hasPlayer("player4") must beFalse
  65. }
  66. "Allow players to leave" in {
  67. team.leave("player3")
  68. team.hasPlayer("player3") must beFalse
  69. // should be a noop
  70. team.leave("player3")
  71. team.hasPlayer("player3") must beFalse
  72. }
  73. "Cycle between players correctly" in {
  74. team.nextPlayer() must equalTo("player1")
  75. team.nextPlayer() must equalTo("player2")
  76. team.nextPlayer() must equalTo("player1")
  77. team.join("player3")
  78. team.join("player4")
  79. team.nextPlayer() must equalTo("player2")
  80. team.nextPlayer() must equalTo("player3")
  81. team.nextPlayer() must equalTo("player4")
  82. team.nextPlayer() must equalTo("player1")
  83. team.nextPlayer() must equalTo("player2")
  84. team.leave("player3")
  85. team.nextPlayer() must equalTo("player4")
  86. team.leave("player4")
  87. team.nextPlayer() must equalTo("player1")
  88. team.nextPlayer() must equalTo("player2")
  89. }
  90. "Give the correct current player and guessers" in {
  91. team.nextPlayer() must equalTo("player1")
  92. team.player must equalTo("player1")
  93. team.guessers("player2") must beTrue
  94. }
  95. }
  96. }