PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/test/jbot/ai_test.clj

https://github.com/jennifersmith/aichallenge-ants-clj
Clojure | 54 lines | 44 code | 10 blank | 0 comment | 0 complexity | 12e6274ff15083065ee76a12279634fa MD5 | raw file
  1. (ns jbot.ai_test
  2. (:use
  3. ai
  4. environment
  5. clojure.test
  6. midje.sweet))
  7. (fact
  8. "If only one move available just return that"
  9. (preferred-moves :current-pos :history {:S :over-there})=> [:S])
  10. (fact
  11. "Remove recent positions from the available dirs"
  12. (preferred-moves [20 10] {:positions [:here :there]} {:E :here :S :brand-new-pos}) => [ :S]
  13. )
  14. (fact
  15. "ignore history greater than 10 moves old"
  16. (preferred-moves [20 10] {:positions [:here :there :somehwere :nowhere :there :outer-space :saturn :jupiter :bangor :venice :plano]} {:E :here :S :new-place}) => [:E :S])
  17. (fact
  18. "If no history don't remove recent positions"
  19. (preferred-moves [] {} {:E :there :S :here}) => [:E :S])
  20. (fact
  21. "If removing recent history results in no routes, remove only the most recent"
  22. (preferred-moves [10 10] {:positions [:there :here :mars :chicago]} {:E :there :W :chicago } )=> [:E])
  23. (fact
  24. "return a nil if poor ant is stuck"
  25. (ant-next-move {:directions {}}) => nil)
  26. (fact
  27. (ant-next-move
  28. {
  29. :history :ant-history
  30. :pos [10 10]
  31. :directions {:foo :bar}}) => {:pos [10 10] :direction :the-way-to-go}
  32. (provided
  33. (preferred-moves [10 10] :ant-history {:foo :bar}) => :preferred-moves
  34. (rand-nth :preferred-moves) => :the-way-to-go))
  35. (fact "Passes ant pos history and available directions to compute next move"
  36. (move-ants {:a :history-a :b :history-b} {:my-ants {:ants [:a :b :c]} :environment :env :random-generator :rand}) =>
  37. [:ant-move-one :ant-move-two]
  38. (provided
  39. (get-available-directions :env :a) => :a-directions
  40. (get-available-directions :env :b) => :b-directions
  41. (get-available-directions :env :c) => :c-directions
  42. (ant-next-move {:pos :a :history :history-a :directions :a-directions}) => :ant-move-one
  43. (ant-next-move {:pos :b :history :history-b :directions :b-directions}) => :ant-move-two
  44. (ant-next-move {:pos :c :history {} :directions :c-directions}) => nil))