Full coverage on coordinates
This commit is contained in:
parent
0e4c24046b
commit
736ec62d3b
|
@ -1,5 +1,5 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from math import trunc, floor, ceil
|
from math import trunc, floor, ceil, radians
|
||||||
from urbantz.utils import Coordinates
|
from urbantz.utils import Coordinates
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,5 +59,30 @@ class TestCoordinates(TestCase):
|
||||||
def test_ceil(self):
|
def test_ceil(self):
|
||||||
self.assertTupleEqual(tuple(ceil(self.coords)), (13, -13))
|
self.assertTupleEqual(tuple(ceil(self.coords)), (13, -13))
|
||||||
|
|
||||||
|
def test_add(self):
|
||||||
|
other = Coordinates(lat=7.43, lng=-6.51)
|
||||||
|
self.assertEqual(self.coords + other, Coordinates(lat=20, lng=-20))
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
self.coords + 4
|
||||||
|
|
||||||
|
def test_sub(self):
|
||||||
|
other = Coordinates(lat=2.57, lng=-3.49)
|
||||||
|
self.assertEqual(self.coords - other, Coordinates(lat=10, lng=-10))
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
self.coords - "lol"
|
||||||
|
|
||||||
def test_toJSON(self):
|
def test_toJSON(self):
|
||||||
self.assertListEqual(self.coords.toJSON(), [-13.49, 12.57])
|
self.assertListEqual(self.coords.toJSON(), [-13.49, 12.57])
|
||||||
|
|
||||||
|
def test_fromJSON(self):
|
||||||
|
self.assertEqual(Coordinates.fromJSON([-13.49, 12.57]), self.coords)
|
||||||
|
|
||||||
|
def test_to_radians(self):
|
||||||
|
self.assertTupleEqual(self.coords.to_radians(), (radians(12.57), radians(-13.49)))
|
||||||
|
|
||||||
|
def test_distance(self):
|
||||||
|
other = Coordinates(lat=2.57, lng=-3.49)
|
||||||
|
self.assertEqual(self.coords.distance(other), other.distance(self.coords))
|
||||||
|
self.assertEqual(self.coords.distance(other), 1564640.3229974532)
|
||||||
|
with self.assertRaises(NotImplementedError):
|
||||||
|
self.coords.distance("lol")
|
||||||
|
|
|
@ -42,7 +42,7 @@ class Coordinates(object):
|
||||||
tuple(self) == tuple(other)
|
tuple(self) == tuple(other)
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
if not hasattr(other, 'lat') or hasattr(other, 'lng'):
|
if not hasattr(other, 'lat') or not hasattr(other, 'lng'):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return self.__class__(
|
return self.__class__(
|
||||||
lat=self.lat + other.lat,
|
lat=self.lat + other.lat,
|
||||||
|
@ -50,7 +50,7 @@ class Coordinates(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __sub__(self, other):
|
def __sub__(self, other):
|
||||||
if not hasattr(other, 'lat') or hasattr(other, 'lng'):
|
if not hasattr(other, 'lat') or not hasattr(other, 'lng'):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return self.__class__(
|
return self.__class__(
|
||||||
lat=self.lat - other.lat,
|
lat=self.lat - other.lat,
|
||||||
|
|
Reference in New Issue