Guest User

Untitled

a guest
May 7th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. ; test that the test framework behaves as expected because the doco is abstract
  2. (ns com.quzanti
  3. (:use clojure.test)
  4. (:import java.util.TreeSet)
  5. )
  6.  
  7. (def whats-run (new TreeSet))
  8.  
  9. (def onceres nil)
  10.  
  11. (def eachres nil)
  12.  
  13. (def oncevar (new StringBuffer))
  14.  
  15. (def eachvar (new StringBuffer))
  16.  
  17. (defn once-test-fixture
  18. [zefn]
  19. (binding [onceres (do (. oncevar append "o")
  20. (. oncevar toString))]
  21. (println "once test called")
  22. (zefn)
  23. )
  24. )
  25.  
  26. (use-fixtures :once once-test-fixture)
  27.  
  28. (defn each-test-fixture
  29. [zefn]
  30. (binding [eachres (do (. eachvar append "e")
  31. (. eachvar toString))]
  32. (println "each test called")
  33. (zefn)
  34. )
  35. )
  36.  
  37. (use-fixtures :each each-test-fixture)
  38.  
  39. (with-test
  40. (defn once-firstly
  41. []
  42. (. whats-run add "a")
  43. (println "Doing once firstly")
  44. onceres
  45. )
  46. (is (= (once-firstly) "o"))
  47. )
  48.  
  49. (with-test
  50. (defn once-secondly
  51. []
  52. (. whats-run add "b")
  53. (println "Doing once secondly")
  54. onceres
  55. )
  56. (is (= (once-secondly) "o"))
  57. )
  58.  
  59. (with-test
  60. (defn each-firstly
  61. []
  62. (. whats-run add "c")
  63. (println "Doing each firstly")
  64. eachres
  65. )
  66. (is (= (each-firstly) (apply str (repeat (. whats-run size) "e"))))
  67. (is (= (each-firstly) (apply str (repeat (. whats-run size) "e"))))
  68. )
  69.  
  70. (with-test
  71. (defn each-secondly
  72. []
  73. (. whats-run add "d")
  74. (println "Doing each secondly")
  75. eachres
  76. )
  77. (is (= (each-secondly) (apply str (repeat (. whats-run size) "e"))))
  78. (is (= (each-secondly) (apply str (repeat (. whats-run size) "e"))))
  79. )
Add Comment
Please, Sign In to add comment