File tree Expand file tree Collapse file tree 3 files changed +40
-18
lines changed
src/lambdaisland/deep_diff2
test/lambdaisland/deep_diff2 Expand file tree Collapse file tree 3 files changed +40
-18
lines changed Original file line number Diff line number Diff line change 9797 (diff-seq-insertions ins)
9898 (into []))))
9999
100+ (defn diff-set [exp act]
101+ (into
102+ (into #{}
103+ (map (fn [e]
104+ (if (contains? act e)
105+ e
106+ (->Deletion e))))
107+ exp)
108+ (map ->Insertion)
109+ (remove #(contains? exp %) act)))
110+
111+ (let [exp {false 0 , 0 0 }
112+ act {false 0 , 0 0 }
113+ exp-ks (keys exp)
114+ act-ks (concat (filter #(contains? (set (keys act)) %) exp-ks)
115+ (remove #(contains? (set exp-ks) %) (keys act)))
116+ [del ins] (del+ins exp-ks act-ks)]
117+ [del ins])
118+ (del+ins [0 false ] [0 false ])
119+
100120(defn diff-map [exp act]
101121 (first
102122 (let [exp-ks (keys exp)
103- act-ks (concat (filter ( set (keys act)) exp-ks)
104- (remove ( set exp-ks) (keys act)))
123+ act-ks (concat (filter #( contains? ( set (keys act)) % ) exp-ks)
124+ (remove #( contains? ( set exp-ks) % ) (keys act)))
105125 [del ins] (del+ins exp-ks act-ks)]
106126 (reduce
107127 (fn [[m idx] k]
162182(extend-protocol Diff
163183 #?(:clj java.util.Set :cljs cljs.core/PersistentHashSet)
164184 (-diff-similar [exp act]
165- (let [exp-seq (seq exp)
166- act-seq (seq act)]
167- (set (diff-seq exp-seq (concat (filter act exp-seq)
168- (remove exp act-seq))))))
185+ (diff-set exp act))
169186 #?@(:clj
170187 [java.util.List
171188 (-diff-similar [exp act] (diff-seq exp act))
Original file line number Diff line number Diff line change 212212 (gen/such-that (complement NaN?) gen/simple-type)))
213213
214214(defspec round-trip-diff 100
215- (prop/for-all [x gen-any-except-NaN
216- y gen-any-except-NaN]
217- (let [diff (diff/diff x y)]
218- (= [x y] [(diff/left-undiff diff) (diff/right-undiff diff)]))))
215+ (prop/for-all
216+ [x gen-any-except-NaN
217+ y gen-any-except-NaN]
218+ (let [diff (diff/diff x y)]
219+ (= [x y] [(diff/left-undiff diff) (diff/right-undiff diff)]))))
220+
221+ (defspec diff-same-is-same 100
222+ (prop/for-all
223+ [x gen-any-except-NaN]
224+ (= x (diff/diff x x))))
219225
220226(deftest diff-seq-test
221227 (is (= [(diff/->Insertion 1 ) 2 (diff/->Insertion 3 )]
Original file line number Diff line number Diff line change 7070 [])))))
7171
7272; ; "diff itself and remove-unchanged yields empty"
73- (comment
74- (defspec diff-itself 100
75- (prop/for-all [x diff-test/gen-any-except-NaN]
76- (if (coll? x)
77- (= (manipulate/remove-unchanged (ddiff/diff x x))
78- (empty x))
79- (= (manipulate/remove-unchanged (ddiff/diff x x))
80- nil )))))
73+ (defspec diff-itself 100
74+ (prop/for-all
75+ [x diff-test/gen-any-except-NaN]
76+ (if (coll? x)
77+ (= (manipulate/remove-unchanged (ddiff/diff x x))
78+ (empty x))
79+ (nil? (manipulate/remove-unchanged (ddiff/diff x x))))))
You can’t perform that action at this time.
0 commit comments