Sha256: ab48481c43d42c8771926f86de50ce812febacf9956dca35a1fb3d30a057eef6

Contents?: true

Size: 952 Bytes

Versions: 4

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

require 'helper'

class TestGeolocation < Test::Unit::TestCase
  include DeterministicHelper

  assert_methods_are_deterministic(FFaker::Geolocation, :lat, :lng)

  def test_lat
    assert_match(/[0-9]+/, FFaker::Geolocation.lat.to_s)
  end

  def test_lng
    assert_match(/[0-9]+/, FFaker::Geolocation.lng.to_s)
  end

  def test_boxed_coords
    coords_list = [
      [[1, 1], [3, 3]],
      [[12.3455, 23.3434], [34.3434, 36.34343]],
      [[12.3455, 23.3434], [10.3434, 6.34343]]
    ]

    coords_list.each do |coords|
      lat_min = [coords[0][0], coords[1][0]].min
      lat_max = [coords[0][0], coords[1][0]].max
      lon_min = [coords[0][1], coords[1][1]].min
      lon_max = [coords[0][1], coords[1][1]].max

      new_coords = FFaker::Geolocation.boxed_coords(coords[0], coords[1])

      assert (lat_min..lat_max).cover? new_coords[0]
      assert (lon_min..lon_max).cover? new_coords[1]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ffaker-2.18.0 test/test_geolocation.rb
ffaker-2.17.0 test/test_geolocation.rb
ffaker-2.16.0 test/test_geolocation.rb
ffaker-2.15.0 test/test_geolocation.rb