diff --git a/src/test/grub/test/unit/sync.clj b/src/test/grub/test/unit/sync.clj index c198d80..1aa8dd4 100644 --- a/src/test/grub/test/unit/sync.clj +++ b/src/test/grub/test/unit/sync.clj @@ -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))