ApplicationSpec.scala 3.0 KB

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