ClojureScript+React/Om clone of 2048
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.9KB

  1. (ns ttfe.board-test
  2. (:require [ttfe.board :refer [move-right move-left move-up move-down
  3. movements-left?]]
  4. [purnam.test :refer [toSatisfy]])
  5. (:use-macros [purnam.test :only [describe it is is-not]]))
  6. (describe test-move-right
  7. (it "Can move a single number"
  8. (is (move-right [[nil nil 4 nil]
  9. [nil nil nil nil]
  10. [nil nil nil nil]
  11. [nil nil nil nil]])
  12. [[nil nil nil 4 ]
  13. [nil nil nil nil]
  14. [nil nil nil nil]
  15. [nil nil nil nil]]))
  16. (it "Can move two numbers in different rows"
  17. (is (move-right [[nil nil 4 nil]
  18. [nil nil nil nil]
  19. [nil 2 nil nil]
  20. [nil nil nil nil]])
  21. [[nil nil nil 4 ]
  22. [nil nil nil nil]
  23. [nil nil nil 2 ]
  24. [nil nil nil nil]]))
  25. (it "Can combine simple numbers"
  26. (is (move-right [[nil nil 2 2 ]
  27. [nil nil nil nil]
  28. [nil nil nil nil]
  29. [nil nil nil nil]])
  30. [[nil nil nil 4 ]
  31. [nil nil nil nil]
  32. [nil nil nil nil]
  33. [nil nil nil nil]]))
  34. (it "Can combine chains of numbers"
  35. (is (move-right [[ 4 4 2 2 ]
  36. [nil nil nil nil]
  37. [nil nil nil nil]
  38. [nil nil nil nil]])
  39. [[nil nil 8 4 ]
  40. [nil nil nil nil]
  41. [nil nil nil nil]
  42. [nil nil nil nil]]))
  43. (it "Can combine numbers that aren't adjacent"
  44. (is (move-right [[nil 2 nil 2 ]
  45. [nil nil nil nil]
  46. [nil nil nil nil]
  47. [nil nil nil nil]])
  48. [[nil nil nil 4 ]
  49. [nil nil nil nil]
  50. [nil nil nil nil]
  51. [nil nil nil nil]]))
  52. (it "Number combination starts the right way"
  53. (is (move-right [[ 2 2 nil 2 ]
  54. [nil nil nil nil]
  55. [nil nil nil nil]
  56. [nil nil nil nil]])
  57. [[nil nil 2 4 ]
  58. [nil nil nil nil]
  59. [nil nil nil nil]
  60. [nil nil nil nil]])))
  61. (describe test-move-left
  62. (it "Can move two numbers in different rows"
  63. (is (move-left [[nil nil 4 nil]
  64. [nil nil nil nil]
  65. [nil 2 nil nil]
  66. [nil nil nil nil]])
  67. [[ 4 nil nil nil]
  68. [nil nil nil nil]
  69. [ 2 nil nil nil]
  70. [nil nil nil nil]])))
  71. (describe test-move-up
  72. (it "Can move two numbers in different rows"
  73. (is (move-up [[nil nil nil nil]
  74. [nil nil 4 nil]
  75. [nil 2 nil nil]
  76. [nil nil nil nil]])
  77. [[nil 2 4 nil]
  78. [nil nil nil nil]
  79. [nil nil nil nil]
  80. [nil nil nil nil]])))
  81. (describe test-move-down
  82. (it "Can move two numbers in different rows"
  83. (is (move-down [[nil nil nil nil]
  84. [nil nil 4 nil]
  85. [nil 2 nil nil]
  86. [nil nil nil nil]])
  87. [[nil nil nil nil]
  88. [nil nil nil nil]
  89. [nil nil nil nil]
  90. [nil 2 4 nil]])))
  91. (describe test-movements-left?
  92. (it "Movements left in trivial example"
  93. (is (movements-left? [[nil nil nil nil]
  94. [nil nil 4 nil]
  95. [nil 2 nil nil]
  96. [nil nil nil nil]])
  97. true))
  98. (it "Movements left when only right/down is possible"
  99. (is (movements-left? [[ 2 4 8 128]
  100. [ 2 8 4 8 ]
  101. [ 4 2 32 4 ]
  102. [256 16 8 nil]])
  103. true))
  104. (it "Movements left when only right/up is possible"
  105. (is (movements-left? [[ 2 4 8 nil]
  106. [ 2 8 4 8 ]
  107. [ 4 2 32 4 ]
  108. [256 16 8 128]])
  109. true))
  110. (it "Movements left when only left/up is possible"
  111. (is (movements-left? [[nil 4 8 2 ]
  112. [ 2 8 4 8 ]
  113. [ 4 2 32 4 ]
  114. [256 16 8 128]])
  115. true))
  116. (it "Movements left when only left/down is possible"
  117. (is (movements-left? [[256 4 8 2 ]
  118. [ 2 8 4 8 ]
  119. [ 4 2 32 4 ]
  120. [nil 16 8 128]])
  121. true))
  122. (it "Movements left when only horizontal is possible"
  123. (is (movements-left? [[ 4 4 8 2 ]
  124. [ 2 8 4 8 ]
  125. [ 4 2 32 4 ]
  126. [256 16 8 128]])
  127. true))
  128. (it "No movements left"
  129. (is (movements-left? [[ 4 2 8 2 ]
  130. [ 2 8 4 8 ]
  131. [ 4 2 32 4 ]
  132. [256 16 8 128]])
  133. false)))