Sha256: e75be0463d5e3d026e9941004ffa24fb6537bc2ec1479930cd686cd99e6f2588

Contents?: true

Size: 1016 Bytes

Versions: 18

Compression:

Stored size: 1016 Bytes

Contents

require "spec_helper"

describe Mongoid::Spacial::Formulas do
    context "#n_vector" do
      it {
        bna = [-86.67, 36.12]
        lax = [-118.40, 33.94]
        dist1 = Mongoid::Spacial::Formulas.n_vector(bna, lax)
        dist2 = Mongoid::Spacial::Formulas.n_vector(lax, bna)

        # target is 0.45306
        dist1.should be_within(0.00001).of(0.45306)
        dist2.should be_within(0.00001).of(0.45306)
      }
      it {
        # actual distance 2471.788
        jfk = [-73.77694444, 40.63861111 ]
        lax = [-118.40, 33.94]

        dist = Mongoid::Spacial::Formulas.n_vector(jfk, lax) * Mongoid::Spacial.earth_radius[:mi]
        dist.should be_within(1).of(2469)
      }
    end

    context "#haversine" do
      it {
        # actual distance 2471.788
        jfk = [-73.77694444, 40.63861111 ]
        lax = [-118.40, 33.94]

        dist = Mongoid::Spacial::Formulas.haversine(jfk, lax) * Mongoid::Spacial.earth_radius[:mi]
        dist.should be_within(1).of(2469)
      }
    end

end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
mongoid_spacial-0.2.17 spec/unit/mongoid/spacial/formulas_spec.rb
sig_mongoid_spacial-0.2.17 spec/unit/mongoid/spacial/formulas_spec.rb
cb_mongoid_spacial-0.2.16 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.16 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.13 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.12 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.11 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.10 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.8 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.7 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.6 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.5 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.4 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.3 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.2 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.2.0 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.1.1 spec/unit/mongoid/spacial/formulas_spec.rb
mongoid_spacial-0.1.0 spec/unit/mongoid/spacial/formulas_spec.rb