# Path: pyeqs/dsl/geo.py
# class GeoDistance(dict):
# 
#     def __init__(self, coordinates, distance, field_name="location"):
#         """
#         Geo Distance Filter
# 
#         Acceptable Input Styles:
#         GeoDistance({'lat': 40, 'lon': -70}, '10km')
#         GeoDistance({'lat': 40, 'lng': -70}, '10km')
#         GeoDistance([40, -70], '10km')
#         GeoDistance("-70,40", '10km')
#         """
#         super(GeoDistance, self).__init__()
#         self.coordinates = list(self._parse_coordinates(coordinates))
#         self.distance = distance
#         self.field_name = field_name
#         self["geo_distance"] = self._build_dict()
# 
#     def _build_dict(self):
#         geo_distance = {
#             "distance": self.distance,
#             self.field_name: {
#                 'lat': self.coordinates[0],
#                 'lon': self.coordinates[1]
#             }
#         }
#         return geo_distance
# 
#     def _parse_coordinates(self, coordinates):
#         if isinstance(coordinates, list):
#             lat = coordinates[1]
#             lon = coordinates[0]
#         if isinstance(coordinates, dict):
#             lat = coordinates.pop('lat')
#             lon = list(coordinates.values())[0]
#         if isinstance(coordinates, string_types):
#             lat, lon = coordinates.split(",")
#         return map(float, [lat, lon])
# 
# Path: tests/helpers.py
# def homogeneous(a, b):
#     json.dumps(a, sort_keys=True).should.equal(json.dumps(b, sort_keys=True))


from pyeqs.dsl import GeoDistance
from tests.helpers import homogeneous
from __future__ import unicode_literals



def test_add_geo_distance_with_dict():
    """
    Create Geo Distance with Dictionary
    """
    # When add a Geo Distance field
    t = GeoDistance({"lat": 1.0, "lon": 2.0}, "20mi")

    # Then I see the appropriate JSON
    results = {
        "geo_distance": {
            "distance": "20mi",
            "location": {
                "lat": 1.0,
                "lon": 2.0
            }
        }
    }

    homogeneous(t, results)


def test_add_geo_distance_with_string():
    """
    Create Geo Distance with String
    """
    # When add a Geo Distance field

# Path: pyeqs/dsl/geo.py
# class GeoDistance(dict):
# 
#     def __init__(self, coordinates, distance, field_name="location"):
#         """
#         Geo Distance Filter
# 
#         Acceptable Input Styles:
#         GeoDistance({'lat': 40, 'lon': -70}, '10km')
#         GeoDistance({'lat': 40, 'lng': -70}, '10km')
#         GeoDistance([40, -70], '10km')
#         GeoDistance("-70,40", '10km')
#         """
#         super(GeoDistance, self).__init__()
#         self.coordinates = list(self._parse_coordinates(coordinates))
#         self.distance = distance
#         self.field_name = field_name
#         self["geo_distance"] = self._build_dict()
# 
#     def _build_dict(self):
#         geo_distance = {
#             "distance": self.distance,
#             self.field_name: {
#                 'lat': self.coordinates[0],
#                 'lon': self.coordinates[1]
#             }
#         }
#         return geo_distance
# 
#     def _parse_coordinates(self, coordinates):
#         if isinstance(coordinates, list):
#             lat = coordinates[1]
#             lon = coordinates[0]
#         if isinstance(coordinates, dict):
#             lat = coordinates.pop('lat')
#             lon = list(coordinates.values())[0]
#         if isinstance(coordinates, string_types):
#             lat, lon = coordinates.split(",")
#         return map(float, [lat, lon])
# 
# Path: tests/helpers.py
# def homogeneous(a, b):
#     json.dumps(a, sort_keys=True).should.equal(json.dumps(b, sort_keys=True))


# Path: tests/unit/test_geo_distance.py
from pyeqs.dsl import GeoDistance
from tests.helpers import homogeneous

from __future__ import unicode_literals



def test_add_geo_distance_with_dict():
    """
    Create Geo Distance with Dictionary
    """
    # When add a Geo Distance field
    t = GeoDistance({"lat": 1.0, "lon": 2.0}, "20mi")

    # Then I see the appropriate JSON
    results = {
        "geo_distance": {
            "distance": "20mi",
            "location": {
                "lat": 1.0,
                "lon": 2.0
            }
        }
    }

    homogeneous(t, results)


def test_add_geo_distance_with_string():
    """
    Create Geo Distance with String
    """
    # When add a Geo Distance field

    t = GeoDistance("1.0,2.0", "20mi")