Sha256: 3fa953e8b55abd753ff79e6ceb4cd0dd309bf53ed3f77519e8476deb3bbcb079

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'
module Alf
  describe Aggregator do

    let(:input){[
      {:a => 1, :sign => -1},
      {:a => 2, :sign => 1 },
      {:a => 3, :sign => -1},
      {:a => 1, :sign => -1},
    ]}

    it "should keep track of registered aggregators" do
      Aggregator.aggregators.should_not be_empty
      Aggregator.each do |agg|
        agg.should be_a(Class)
      end
    end

    it "should allow specific tuple computations" do
      Aggregator.sum{ 1.0 * a * sign }.aggregate(input).should == -3.0
    end

    describe "coerce" do
     
      subject{ Aggregator.coerce(arg) }
      
      describe "from an Aggregator" do
        let(:arg){ Aggregator.sum{a} }
        it{ should eq(arg) }
      end
      
      describe "from a String" do
        let(:arg){ "sum{a}" }

        it { 
          should be_a(Aggregator::Sum) 
        }

        it 'should have source code' do
          subject.has_source_code!.should eq("sum{a}")
        end

        specify{ 
          subject.aggregate(input).should eql(7) 
        }

      end
      
    end

    it 'should implement optimistic equality based on source code' do
      ag1 = Aggregator.coerce("sum{ qty }")
      ag2 = Aggregator.coerce("sum{ qty }")
      ag1.should eq(ag2)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 spec/unit/alf-core/test_aggregator.rb
alf-0.12.1 spec/unit/alf-core/test_aggregator.rb
alf-0.12.0 spec/unit/alf-core/test_aggregator.rb
alf-0.11.1 spec/unit/alf-core/test_aggregator.rb
alf-0.11.0 spec/unit/alf-core/test_aggregator.rb