Sha256: bb21b691888f2b5c304f111edf5add590c1762064d8d4752a78c9c9e926e9465

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require_relative '../lib/geo_swap'

module GeoSwap

  describe GeoSwap do
    DATA = [
      {
        lat: 29.979175,
        long: 31.1343583,
        utm: "36R 320010mE 3317942mN",
      },
      {
        lat: 41.8901694,
        long: 12.4922694,
        utm: "33T 291952mE 4640622mN",
      }
    ]

    describe 'lat_long_to_utm' do
      def conversion(lat, long)
        GeoSwap.lat_long_to_utm(lat, long)
      end

      def check_error(lat, long, message)
        expect { conversion(lat, long) }.
          to raise_error(InputError, message)
      end

      it 'rejects data too close to the north pole' do
        check_error(84.1, 0.0, 'Conversions are unreliable close to the polar regions')
      end

      it 'rejects data too close to the south pole' do
        check_error(-80.1, 0.0, 'Conversions are unreliable close to the polar regions')
      end

      it 'rejects data outside the possible lat/long range' do
        check_error(0.0,200.0, 'Input coordinates are invalid')
      end

      it 'correctly converts several reference points' do
        DATA.each do |data|
          GeoSwap.lat_long_to_utm(data[:lat], data[:long]).to_s.
            should == data[:utm]
        end
      end
    end

    describe 'utm_to_usng' do
      it 'converts utm to usng' do
        GeoSwap.utm_to_usng(560921.64, 4308133.45, 15, 'S').should == '15S WD 60922 8133'
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geo_swap-0.2.1 spec/geo_swap_spec.rb
geo_swap-0.2.0 spec/geo_swap_spec.rb