1 2# -*- coding: utf-8 -*- 3 4# Test gars module. 5 6__all__ = ('Tests',) 7__version__ = '20.01.22' 8 9from base import TestsBase 10 11from pygeodesy import degDMS, fstr, gars, Garef, S_MIN 12 13 14class Tests(TestsBase): 15 16 def testCodec3(self, g, x, prec=4): 17 self.test('codec3', Garef(g), g) 18 t = gars.decode3(g) 19 self.test('decode3', fstr(t, prec=prec), x) 20 self.test('encode', gars.encode(*t), g) 21 22 def testGars(self, LL): 23 24 # Karney's geographiclib/1.49/examples/example-GARS.cpp 25 # <https://SourceForge.net/p/geographiclib/code/ci/release/tree/examples/example-GARS.cpp> 26 g = Garef('57.64911, 10.40744', precision=2) 27 self.test('Garef', g, '381NH45') 28 self.test('Garef', g.toStr(), '381NH45') 29 self.test('Garef', g.toRepr(), "Garef('381NH45')") 30 self.test('Garef', g.toRepr(std=True), "'381NH45'") 31 self.test_('Garef', repr(g), "Garef('381NH45')", "'381NH45'") # PYGEODESY_NAMEDSTR_REPR 32 self.test('Garef.precision', g.precision, 2) 33 self.testCopy(g) 34 35 self.test('Garef.latlon', fstr(g.latlon, prec=5), '57.64911, 10.40744') 36 t = g.toLatLon(LL) 37 self.test('Garef.toLatLon', repr(t), 'LatLon(57°38′56.8″N, 010°24′26.78″E)') 38 self.testCodec3(g, '57.625, 10.375, 2.0', prec=4) 39 t = Garef(t, precision=2, name='self') 40 self.test('Garef(LatLon)', t, g) 41 self.testCopy(t) 42 43 for t in range(-1, 4): 44 r = gars.resolution(t) 45 p = gars.precision(r) 46 self.test('precision', t, p, known=t < 0 or t > 2) 47 b = degDMS(r, prec=0, s_D='', s_S='') # only S_MIN 48 x = ('30' + S_MIN) if p < 1 else ( 49 ('15' + S_MIN) if p < 2 else ('5' + S_MIN)) 50 self.test('resolution', b, x) # also to test degDMS 51 52 53if __name__ == '__main__': 54 55 from pygeodesy import ellipsoidalVincenty 56 57 t = Tests(__file__, __version__, gars) 58 t.testGars(ellipsoidalVincenty.LatLon) 59 t.results() 60 t.exit() 61