Add more tests for history states

This commit is contained in:
Nicholas Kariniemi 2014-10-10 20:58:04 +03:00
parent 421a921fd4
commit e581f34afc

View file

@ -25,3 +25,21 @@
(s/get-history-state states "hash1") => {:a :b}
(s/get-history-state states "hash2") => {:c :d}
(s/get-history-state states "hash3") => {:e :f}))
(fact "Add history state appends state to the end"
(let [states [{:hash "hash1" :state {:a :b}}
{:hash "hash2" :state {:c :d}}]]
(:state (last (s/add-history-state states {:e :f}))) => {:e :f}))
(fact "Add history state appends state to the end and drops first state if full"
(let [states (into [] (for [i (range 20)] {:hash (str "hash" i) :state {:i i}}))
new-states (s/add-history-state states {:i 21})]
(count new-states) => 20
(:state (last new-states)) => {:i 21}
(:state (first new-states)) => {:i 1}))
(fact "Add history state does not add consecutive duplicate states"
(let [hash (hasch/uuid {:c :d})
states [{:hash "hash1" :state {:a :b}}
{:hash hash :state {:c :d}}]]
(s/add-history-state states {:c :d}) => states))