Skip to content

Commit

Permalink
Tests for set resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
reiddraper committed Jan 2, 2012
1 parent 01421d3 commit 99f2fd3
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions test/knockbox/test/sets.clj
@@ -1,36 +1,23 @@
(ns knockbox.test.sets
(:require [knockbox.sets])
(:require knockbox.sets)
(:require [knockbox.core :as kbc])
(:use midje.sweet)
(:use clojure.test))

(fact
(let [s (knockbox.sets/observed-remove)]
(contains? s :foo) => false))

(fact
(let [s (knockbox.sets/observed-remove)
f (conj s :foo)]
(contains? f :foo) => true))

(fact
(let [s (knockbox.sets/observed-remove)
f (conj s :foo)]
(contains? f :foo) => true))

(tabular
(fact "sets contain items properly"
(let [obs-rem (knockbox.sets/observed-remove)
lww (knockbox.sets/lww)
(let [obs-rem (knockbox.sets/observed-remove)
lww (knockbox.sets/lww)
two-phase (knockbox.sets/two-phase)]
(contains? ?set ?item) => ?expected))
?set ?item ?expected
obs-rem :foo false
lww :foo false
two-phase :foo false
?set ?item ?expected
obs-rem :foo false
lww :foo false
two-phase :foo false

(conj obs-rem :foo) :foo true
(conj lww :foo) :foo true
(conj two-phase :foo) :foo true
(conj obs-rem :foo) :foo true
(conj lww :foo) :foo true
(conj two-phase :foo) :foo true


(-> obs-rem (conj :foo) (disj :foo)) :foo false
Expand All @@ -41,4 +28,26 @@
(-> lww (conj :foo) (disj :bar)) :foo true
(-> two-phase (conj :foo) (disj :bar)) :foo true)


(tabular
(fact "sets resolve properly"
(let [obs-rem (knockbox.sets/observed-remove)
lww (knockbox.sets/lww)
two-phase (knockbox.sets/two-phase)

obr-a (into obs-rem #{:foo :bar :baz})
lww-a (into lww #{:foo :bar :baz})
tp-a (into two-phase #{:foo :bar :baz})

obr-b (disj obr-a :foo)
lww-b (disj lww :foo)
tp-b (disj tp-a :foo)]
(contains? ?set ?item) => ?expected))
?set ?item ?expected
(kbc/resolve [obr-a obr-b]) :foo false
(kbc/resolve [lww-a lww-b]) :foo false
(kbc/resolve [tp-a tp-b]) :foo false

; args are commutative
(kbc/resolve [obr-b obr-a]) :foo false
(kbc/resolve [lww-b lww-a]) :foo false
(kbc/resolve [tp-b tp-a]) :foo false)

0 comments on commit 99f2fd3

Please sign in to comment.