from unittest import TestCase from math import trunc, floor, ceil from urbantz.utils import Coordinates class TestCoordinates(TestCase): """ Unit tests for :class:`urbantz.utils.Coordinates` """ @classmethod def setUpClass(cls): cls.coords = Coordinates(lat=12.57, lng=-13.49) def test_init(self): self.assertEqual(self.coords.lat, 12.57) self.assertEqual(self.coords.lng, -13.49) def test_repr(self): self.assertEqual( repr(self.coords), 'Coordinates(lat=12.57, lng=-13.49)', ) def test_str(self): self.assertEqual(str(self.coords), '12.57, -13.49') def test_hash(self): self.assertEqual(hash(self.coords), hash((12.57, -13.49))) def test_tuple(self): self.assertTupleEqual(tuple(self.coords), (12.57, -13.49)) def test_len(self): self.assertEqual(len(self.coords), 2) def test_length_hint(self): self.assertEqual(self.coords.__length_hint__(), 2) def test_pos(self): self.assertEqual(+self.coords, self.coords) def test_neg(self): self.assertTupleEqual(tuple(-self.coords), (-12.57, 13.49)) def test_abs(self): self.assertTupleEqual(tuple(abs(self.coords)), (12.57, 13.49)) def test_round(self): self.assertTupleEqual(tuple(round(self.coords)), (13, -13)) self.assertTupleEqual(tuple(round(self.coords, 1)), (12.6, -13.5)) def test_trunc(self): self.assertTupleEqual(tuple(trunc(self.coords)), (12, -13)) def test_floor(self): self.assertTupleEqual(tuple(floor(self.coords)), (12, -14)) def test_ceil(self): self.assertTupleEqual(tuple(ceil(self.coords)), (13, -13)) def test_toJSON(self): self.assertListEqual(self.coords.toJSON(), [-13.49, 12.57])