/Clojure/Clojure/Bootstrap/test.clj

http://github.com/richhickey/clojure-clr · Clojure · 39 lines · 13 code · 14 blank · 12 comment · 4 complexity · bddeacd0772035c29b57d028e3f94fa0 MD5 · raw file

  1. ; Copyright (c) David Miller. All rights reserved.
  2. ; The use and distribution terms for this software are covered by the
  3. ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  4. ; which can be found in the file epl-v10.html at the root of this distribution.
  5. ; By using this software in any fashion, you are agreeing to be bound by
  6. ; the terms of this license.
  7. ; You must not remove this notice, or any other, from this software.
  8. (ns clojure.test)
  9. ; check generation of boolean test when test is known to be of type bool.
  10. (defn test-if [i n] ( if (> i n) 'a 'b))
  11. ; check generation of boolean test when test type is not known.
  12. (defn test-if2-test [i n] (> i n))
  13. (defn test-if2 [i n] (if (test-if2-test i n) 'a 'b))
  14. ; check generation of boolean test when return type is not bool.
  15. (defn test-if3 [i n] (if i n 'b))
  16. ; basic check of type tagging from the Clojure docs:
  17. (defn len [x] (. x Length))
  18. (defn len2 [#^String x] (. x Length))
  19. (defn test-len [] (time (reduce + (map len (replicate 10000 "asdf")))))
  20. (defn test-len2 [] (time (reduce + (map len2 (replicate 10000 "asdf")))))
  21. ; my first test ever. It still runs slow
  22. (defn f1 [l n] (if (> (count l) n) nil (recur (cons 'a l) n)))
  23. (defn test-f1 [] (time (f1 nil 10000)))
  24. (defn f-dotimes [n] (dotimes [i n] (list i)))
  25. (defn test-dotimes [] (time (f-dotimes 100000)))