Cosmetics

This commit is contained in:
Michael Klishin 2014-05-29 00:40:27 +04:00
parent 96f05c7c01
commit 53ce5808c4

View file

@ -16,12 +16,12 @@
(use-fixtures :each purge-collections) (use-fixtures :each purge-collections)
(deftest test-basic-single-stage-$project-aggregation (deftest test-basic-single-stage-$project-aggregation
(let [batch [{ :state "CA" :quantity 1 :price 199.00 } (let [batch [{:state "CA" :quantity 1 :price 199.00}
{ :state "NY" :quantity 2 :price 199.00 } {:state "NY" :quantity 2 :price 199.00}
{ :state "NY" :quantity 1 :price 299.00 } {:state "NY" :quantity 1 :price 299.00}
{ :state "IL" :quantity 2 :price 11.50 } {:state "IL" :quantity 2 :price 11.50 }
{ :state "CA" :quantity 2 :price 2.95 } {:state "CA" :quantity 2 :price 2.95 }
{ :state "IL" :quantity 3 :price 5.50 }] {:state "IL" :quantity 3 :price 5.50 }]
expected #{{:quantity 1 :state "CA"} expected #{{:quantity 1 :state "CA"}
{:quantity 2 :state "NY"} {:quantity 2 :state "NY"}
{:quantity 1 :state "NY"} {:quantity 1 :state "NY"}
@ -36,12 +36,12 @@
(deftest test-basic-projection-with-multiplication (deftest test-basic-projection-with-multiplication
(let [batch [{ :state "CA" :quantity 1 :price 199.00 } (let [batch [{:state "CA" :quantity 1 :price 199.00}
{ :state "NY" :quantity 2 :price 199.00 } {:state "NY" :quantity 2 :price 199.00}
{ :state "NY" :quantity 1 :price 299.00 } {:state "NY" :quantity 1 :price 299.00}
{ :state "IL" :quantity 2 :price 11.50 } {:state "IL" :quantity 2 :price 11.50 }
{ :state "CA" :quantity 2 :price 2.95 } {:state "CA" :quantity 2 :price 2.95 }
{ :state "IL" :quantity 3 :price 5.50 }] {:state "IL" :quantity 3 :price 5.50 }]
expected #{{:_id "NY" :subtotal 398.0} expected #{{:_id "NY" :subtotal 398.0}
{:_id "NY" :subtotal 299.0} {:_id "NY" :subtotal 299.0}
{:_id "IL" :subtotal 23.0} {:_id "IL" :subtotal 23.0}
@ -55,12 +55,12 @@
(deftest test-basic-total-aggregation (deftest test-basic-total-aggregation
(let [batch [{ :state "CA" :quantity 1 :price 199.00 } (let [batch [{:state "CA" :quantity 1 :price 199.00}
{ :state "NY" :quantity 2 :price 199.00 } {:state "NY" :quantity 2 :price 199.00}
{ :state "NY" :quantity 1 :price 299.00 } {:state "NY" :quantity 1 :price 299.00}
{ :state "IL" :quantity 2 :price 11.50 } {:state "IL" :quantity 2 :price 11.50 }
{ :state "CA" :quantity 2 :price 2.95 } {:state "CA" :quantity 2 :price 2.95 }
{ :state "IL" :quantity 3 :price 5.50 }] {:state "IL" :quantity 3 :price 5.50 }]
expected #{{:_id "CA" :total 204.9} {:_id "IL" :total 39.5} {:_id "NY" :total 697.0}}] expected #{{:_id "CA" :total 204.9} {:_id "IL" :total 39.5} {:_id "NY" :total 697.0}}]
(mc/insert-batch db coll batch) (mc/insert-batch db coll batch)
(let [result (set (mc/aggregate db coll [{$project {:subtotal {$multiply ["$quantity", "$price"]} (let [result (set (mc/aggregate db coll [{$project {:subtotal {$multiply ["$quantity", "$price"]}
@ -72,17 +72,17 @@
(deftest test-$first-aggregation-operator (deftest test-$first-aggregation-operator
(let [batch [{ :state "CA" } (let [batch [{:state "CA"}
{ :state "IL"}] {:state "IL"}]
expected "CA"] expected "CA"]
(mc/insert-batch db coll batch) (mc/insert-batch db coll batch)
(let [result (:state (first (mc/aggregate db coll [{$group { :_id 1 :state {$first "$state"} }}])))] (let [result (:state (first (mc/aggregate db coll [{$group {:_id 1 :state {$first "$state"}}}])))]
(is (= expected result))))) (is (= expected result)))))
(deftest test-$last-aggregation-operator (deftest test-$last-aggregation-operator
(let [batch [{ :state "CA" } (let [batch [{:state "CA"}
{ :state "IL"}] {:state "IL"}]
expected "IL"] expected "IL"]
(mc/insert-batch db coll batch) (mc/insert-batch db coll batch)
(let [result (:state (first (mc/aggregate db coll [{$group { :_id 1 :state {$last "$state"} }}])))] (let [result (:state (first (mc/aggregate db coll [{$group {:_id 1 :state {$last "$state"}}}])))]
(is (= expected result)))))) (is (= expected result))))))