Sha256: 52479806a76795834a4843d44d5582d9a09fb321c96af37302cd384127dd670c

Contents?: true

Size: 1.81 KB

Versions: 133

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe Picky::Calculations::Location do

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

  context 'with precision 3' do
    before(:each) do
      @calculation = described_class.new 1.5, 42.7, 3
    end
    describe 'calculate' do
      it 'sets the anchor close value to the minimum minus user grid' do
        @calculation.calculate(41.2).should == 1
      end
      it 'sets the anchor value to 1 plus precision' do
        @calculation.calculate(42.7).should == 4
      end
      it 'sets the anchor value plus 2/3 of the grid size plus 1 plus precision plus 1 grid length' do
        @calculation.calculate(43.7).should == 6
      end
      it 'sets the anchor value plus 20/3 of the grid size to 2 plus 10 grid length' do
        @calculation.calculate(52.7).should == 27
      end
    end
  end

end

Version data entries

133 entries across 133 versions & 1 rubygems

Version Path
picky-3.6.8 spec/lib/calculations/location_spec.rb
picky-3.6.7 spec/lib/calculations/location_spec.rb
picky-3.6.6 spec/lib/calculations/location_spec.rb
picky-3.6.4 spec/lib/calculations/location_spec.rb
picky-3.6.3 spec/lib/calculations/location_spec.rb
picky-3.6.2 spec/lib/calculations/location_spec.rb
picky-3.6.1 spec/lib/calculations/location_spec.rb
picky-3.6.0 spec/lib/calculations/location_spec.rb
picky-3.5.4 spec/lib/calculations/location_spec.rb
picky-3.5.3 spec/lib/calculations/location_spec.rb
picky-3.5.2 spec/lib/calculations/location_spec.rb
picky-3.5.1 spec/lib/calculations/location_spec.rb
picky-3.5.0 spec/lib/calculations/location_spec.rb