Created
May 19, 2014 09:46
-
-
Save AeroNotix/3fa20f28d5832e00562d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Given a set of :add operations followed by a final :read, verifies that | |
every successfully added element is present in the read, and that the read | |
contains only elements for which an add was attempted." | |
(reify Checker | |
(check [this test model history] | |
(let [attempts (->> history | |
(r/filter knossos/invoke?) | |
(r/filter #(= :add (:f %))) | |
(r/map :value) | |
(into #{})) | |
adds (->> history | |
(r/filter knossos/ok?) | |
(r/filter #(= :add (:f %))) | |
(r/map :value) | |
(into #{})) | |
final-read (->> history | |
(r/filter knossos/ok?) | |
(r/filter #(= :read (:f %))) | |
(r/map :value) | |
(reduce (fn [_ x] x) nil))] | |
(if-not final-read | |
{:valid? false | |
:error "Set was never read"}) | |
(let [; The OK set is every read value which we tried to add | |
ok (set/intersection final-read attempts) | |
; Unexpected records are those we *never* attempted. | |
unexpected (set/difference final-read attempts) | |
; Lost records are those we definitely added but weren't read | |
lost (set/difference adds final-read) | |
; Recovered records are those where we didn't know if the add | |
; succeeded or not, but we found them in the final set. | |
recovered (set/difference ok adds)] | |
{:valid? (and (empty? lost) (empty? unexpected)) | |
:ok (util/integer-interval-set-str ok) | |
:lost (util/integer-interval-set-str lost) | |
:unexpected (util/integer-interval-set-str unexpected) | |
:recovered (util/integer-interval-set-str recovered) | |
:ok-frac (util/fraction (count ok) (count attempts)) | |
:unexpected-frac (util/fraction (count unexpected) (count attempts)) | |
:lost-frac (util/fraction (count lost) (count attempts)) | |
:recovered-frac (util/fraction (count recovered) (count attempts))}))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment