Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Apply rest of patch #66 to add test for group function

  • Loading branch information...
commit 856980bfbc41613619164d929ee49cd7794b0ac4 1 parent 43be6e6
@seancorfield seancorfield authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 test/somnium/test/congomongo.clj
View
19 test/somnium/test/congomongo.clj
@@ -610,3 +610,22 @@ function ()
(catch Exception e
(is true)))))
+(deftest test-group-command
+ (with-test-mongo
+ (drop-coll! :test-group )
+ (insert! :test-group {:fruit "bananas" :count 1})
+ (insert! :test-group {:fruit "bananas" :count 2})
+ (insert! :test-group {:fruit "plantains" :count 3})
+ (insert! :test-group {:fruit "plantains" :count 2})
+ (insert! :test-group {:fruit "pineapples" :count 4})
+ (insert! :test-group {:fruit "pineapples" :count 2})
+ (let [reduce-count-fn "function(obj,prev){prev.count+=obj.count;}"
+ bananas-count (group :test-group :key [:fruit ] :initial {:count 0} :reducefn reduce-count-fn
+ :where {:fruit "bananas"})
+ all-count-keyf (group :test-group :keyfn "function(obj){return {'category':obj.fruit};}"
+ :initial {:count 0} :reducefn reduce-count-fn
+ :finalizefn "function(obj) {return {'items':obj.count,'fruit':obj.category};}")]
+ (is (= bananas-count
+ [{:fruit "bananas", :count 3.0}]))
+ (is (= all-count-keyf
+ [{:items 3.0, :fruit "bananas"} {:items 5.0, :fruit "plantains"} {:items 6.0, :fruit "pineapples"}])))))
Please sign in to comment.
Something went wrong with that request. Please try again.