Sha256: e2f58786a29425f5f02cf049e3516eccf43685a7bc771702f298a290c0808794

Contents?: true

Size: 1.91 KB

Versions: 30

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe Picky::Calculations::Location do
  
  context 'with precision 1' do
    before(:each) do
      @calculation = described_class.new 1.5, 1
      @calculation.minimum = 42.7
    end
    describe 'recalculated_range' do
      it 'returns the right range' do
        @calculation.recalculated_range(40.0).should == (-2..0)
      end
      it 'returns the right range' do
        @calculation.recalculated_range(41.0).should == (-1..1)
      end
      it 'returns the right range' do
        @calculation.recalculated_range(0).should == (-42..-40)
      end
    end
    describe 'recalculate' do
      it 'sets the minimum close value to the minimum minus user grid' do
        @calculation.recalculate(41.2).should == 1
      end
      it 'sets the minimum value to 1 plus precision' do
        @calculation.recalculate(42.7).should == 2
      end
      it 'sets the minimum value plus 2/3 of the grid size to 2 plus 1 grid length' do
        @calculation.recalculate(43.7).should == 3
      end
      it 'sets the minimum value plus 20/3 of the grid size to 2 plus 10 grid length' do
        @calculation.recalculate(52.7).should == 12
      end
    end
  end
  
  context 'with precision 3' do
    before(:each) do
      @calculation = described_class.new 1.5, 3
      @calculation.minimum = 42.7
    end
    describe 'recalculate' do
      it 'sets the minimum close value to the minimum minus user grid' do
        @calculation.recalculate(41.2).should == 1
      end
      it 'sets the minimum value to 1 plus precision' do
        @calculation.recalculate(42.7).should == 4
      end
      it 'sets the minimum value plus 2/3 of the grid size plus 1 plus precision plus 1 grid length' do
        @calculation.recalculate(43.7).should == 6
      end
      it 'sets the minimum value plus 20/3 of the grid size to 2 plus 10 grid length' do
        @calculation.recalculate(52.7).should == 27
      end
    end
  end
  
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
picky-3.1.2 spec/lib/calculations/location_spec.rb
picky-3.1.1 spec/lib/calculations/location_spec.rb
picky-3.1.0 spec/lib/calculations/location_spec.rb
picky-3.0.1 spec/lib/calculations/location_spec.rb
picky-3.0.0 spec/lib/calculations/location_spec.rb
picky-3.0.0.pre5 spec/lib/calculations/location_spec.rb
picky-3.0.0.pre4 spec/lib/calculations/location_spec.rb
picky-3.0.0.pre3 spec/lib/calculations/location_spec.rb
picky-3.0.0.pre2 spec/lib/calculations/location_spec.rb
picky-3.0.0.pre1 spec/lib/calculations/location_spec.rb