Sha256: ed3355787f8b0eca2d472a134182e2ab5280418d94e664314942d0aef09847e8

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe "Reducers" do
  describe :moments do
    include_context "reducers"
    it_behaves_like 'a processor', :named => :moments

    it "behaves like group when not called with any arguments" do
      processor(:moments).given(*strings.sort).should emit(
        {group: 'apple',  count: 2, results: {}},
        {group: 'banana', count: 1, results: {}},
        {group: 'cookie', count: 1, results: {}}
      )
    end

    it "behaves calculates the moments of numeric fields" do
      processor(:moments, group_by: 'outer', of: 'data.n').given(*json_sorted_outer).should emit(
        {group: nil,      count: 2, results: {"data.n" => {}}},
        {group: 'apple',  count: 2, results: {"data.n"=>{:count=>2, :mean=>3.0,   :std_dev=>2.0}}},
        {group: 'banana', count: 1, results: {"data.n"=>{:count=>1, :mean=>100.0, :std_dev=>0.0}}},
        {group: 'cookie', count: 1, results: {"data.n"=>{:count=>1, :mean=>10.0,  :std_dev=>0.0}}}
      )
    end

    it "will leave off the standard deviation if desired" do
      processor(:moments, group_by: 'outer', of: 'data.n', no_std_dev: true).given(*json_sorted_outer).should emit(
        {group: nil,      count: 2, results: {"data.n" => {}}},
        {group: 'apple',  count: 2, results: {"data.n"=>{:count=>2, :mean=>3.0   }}},
        {group: 'banana', count: 1, results: {"data.n"=>{:count=>1, :mean=>100.0 }}},
        {group: 'cookie', count: 1, results: {"data.n"=>{:count=>1, :mean=>10.0  }}}
      )
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ul-wukong-4.1.1 spec/wukong/widget/reducers/moments_spec.rb
ul-wukong-4.1.0 spec/wukong/widget/reducers/moments_spec.rb
wukong-4.0.0 spec/wukong/widget/reducers/moments_spec.rb
wukong-3.0.1 spec/wukong/widget/reducers/moments_spec.rb
wukong-3.0.0 spec/wukong/widget/reducers/moments_spec.rb