def testErrors(self, InvalidError, IsnotError): e = InvalidError(zero=1) self.test(InvalidError.__name__, e, 'zero (1): invalid') self.test(InvalidError.__name__, repr(e).replace(',)', ')'), "ValueError('zero (1): invalid')") e = InvalidError(zero=1, one=2, txt='outside') self.test(InvalidError.__name__, e, 'one (2) or zero (1): outside') self.test(InvalidError.__name__, repr(e).replace(',)', ')'), "ValueError('one (2) or zero (1): outside')") e = InvalidError(zero=1, Error=RangeError, one=2, txt='outside') self.test(InvalidError.__name__, e, 'one (2) or zero (1): outside') self.test(InvalidError.__name__, repr(e).replace(',)', ')'), "RangeError('one (2) or zero (1): outside')") e = InvalidError(two=2, Error=ValueError) # coverage e = IsnotError(int.__name__, float.__name__, _None=None) self.test(IsnotError.__name__, e, '_None (None) not an int or float') self.test(IsnotError.__name__, repr(e).replace(',)', ')'), "TypeError('_None (None) not an int or float')") e = IsnotError('scalar', _None=None) self.test(IsnotError.__name__, e, '_None (None) not scalar') self.test(IsnotError.__name__, repr(e).replace(',)', ')'), "TypeError('_None (None) not scalar')") e = IsnotError('scalar', Error=LimitError, _None=None) self.test(IsnotError.__name__, e, '_None (None) not scalar: invalid') self.test(IsnotError.__name__, repr(e).replace(',)', ')'), "LimitError('_None (None) not scalar: invalid')") try: raise LenError(LenError, a=1, b=2, c=3, d=4) self.test(LenError.__name__, None, LenError.__name__) except ValueError as x: self.test(LenError.__name__, str(x), 'LenError(a, b, c, d) len 1 vs 2 vs 3 vs 4: invalid') self.test(crosserrors.__name__, crosserrors(False), True) self.test(crosserrors.__name__, crosserrors(True), False) self.test(limiterrors.__name__, limiterrors(False), True) self.test(limiterrors.__name__, limiterrors(True), False) self.test(rangerrors.__name__, rangerrors(False), True) self.test(rangerrors.__name__, rangerrors(True), False) x = True if environ.get('PYGEODESY_EXCEPTION_CHAINING', None) else False self.test(exception_chaining.__name__, exception_chaining(), x if isPython3 else None) self.test(exception_chaining.__name__, exception_chaining(RangeError()), None) self.test(exception_chaining.__name__, exception_chaining(TypeError()), None)
def testUtily(self): # Python 2.6.9 on Travis Ubuntu 14.04 produces -0.0 self.test('degrees90(PI_2)', degrees90(PI_2), 90.0) self.test('degrees90(PI)', degrees90(PI), -180.0) # XXX self.test('degrees90(PI2)', degrees90(PI2), 0.0) self.test('degrees90(-PI_2)', degrees90(-PI_2), -90.0) self.test('degrees90(-PI)', degrees90(-PI), -180.0) # XXX self.test('degrees90(-PI2)', abs(degrees90(-PI2)), 0.0) # -0.0 self.test('degrees180(PI_2)', degrees180(PI_2), 90.0) self.test('degrees180(PI)', degrees180(PI), 180.0) # XXX self.test('degrees180(PI2)', degrees180(PI2), 0.0) self.test('degrees180(-PI_2)', degrees180(-PI_2), -90.0) self.test('degrees180(-PI)', degrees180(-PI), -180.0) # XXX self.test('degrees180(-PI2)', abs(degrees180(-PI2)), 0.0) # -0.0 self.test('degrees360(PI_2)', degrees360(PI_2), 90.0) self.test('degrees360(PI)', degrees360(PI), 180.0) # XXX self.test('degrees360(PI2)', degrees360(PI2), 0.0) self.test('degrees360(-PI_2)', degrees360(-PI_2), 270.0) self.test('degrees360(-PI)', degrees360(-PI), 180.0) # XXX self.test('degrees360(-PI2)', abs(degrees360(-PI2)), 0.0) # -0.0 self.test('radiansPI_2(90)', radiansPI_2(90), PI_2) self.test('radiansPI_2(180)', radiansPI_2(180), -PI) self.test('radiansPI_2(360)', radiansPI_2(360), 0.0) self.test('radiansPI_2(-90)', radiansPI_2(-90), -PI_2) self.test('radiansPI_2(-180)', radiansPI_2(-180), -PI) self.test('radiansPI_2(-360)', abs(radiansPI_2(-360)), 0.0) # -0.0 self.test('radiansPI(90)', radiansPI(90), PI_2) self.test('radiansPI(180)', radiansPI(180), PI) self.test('radiansPI(360)', radiansPI(360), 0.0) self.test('radiansPI(-90)', radiansPI(-90), -PI_2) self.test('radiansPI(-180)', radiansPI(-180), -PI) self.test('radiansPI(-360)', abs(radiansPI(-360)), 0.0) # -0.0 self.test('radiansPI2(90)', radiansPI2(90), PI_2) self.test('radiansPI2(180)', radiansPI2(180), PI) self.test('radiansPI2(360)', radiansPI2(360), 0.0) self.test('radiansPI2(-90)', radiansPI2(-90), PI_2+PI) self.test('radiansPI2(-180)', radiansPI2(-180), PI) self.test('radiansPI2(-360)', abs(radiansPI2(-360)), 0.0) # -0.0 self.test('wrap90(90)', wrap90(90), 90) self.test('wrap90(180)', wrap90(180), -180) self.test('wrap90(360)', wrap90(360), 0) self.test('wrap90(-90)', wrap90(-90), -90) self.test('wrap90(-180)', wrap90(-180), -180) self.test('wrap90(-360)', wrap90(-360), 0) self.test('wrap180(90)', wrap180(90), 90) self.test('wrap180(180)', wrap180(180), 180) self.test('wrap180(360)', wrap180(360), 0) self.test('wrap180(-90)', wrap180(-90), -90) self.test('wrap180(-180)', wrap180(-180), -180) self.test('wrap180(-360)', wrap180(-360), 0) self.test('wrap360(90)', wrap360(90), 90) self.test('wrap360(180)', wrap360(180), 180) self.test('wrap360(360)', wrap360(360), 0) self.test('wrap360(-90)', wrap360(-90), 270) self.test('wrap360(-180)', wrap360(-180), 180) self.test('wrap360(-360)', wrap360(-360), 0) self.test('wrapPI_2(PI_2)', wrapPI_2(PI_2), PI_2) self.test('wrapPI_2(PI)', wrapPI_2(PI), -PI) # XXX self.test('wrapPI_2(PI2)', wrapPI_2(PI2), 0.0) self.test('wrapPI_2(-PI_2)', wrapPI_2(-PI_2), -PI_2) self.test('wrapPI_2(-PI)', wrapPI_2(-PI), -PI) # XXX self.test('wrapPI_2(-PI2)', abs(wrapPI_2(-PI2)), 0.0) self.test('wrapPI(PI_2)', wrapPI(PI_2), PI_2) self.test('wrapPI(PI)', wrapPI(PI), PI) # XXX self.test('wrapPI(PI2)', wrapPI(PI2), 0.0) self.test('wrapPI(-PI_2)', wrapPI(-PI_2), -PI_2) self.test('wrapPI(-PI)', wrapPI(-PI), -PI) # XXX self.test('wrapPI(-PI2)', abs(wrapPI(-PI2)), 0.0) # -0.0 self.test('wrapPI2(PI_2)', wrapPI2(PI_2), PI_2) self.test('wrapPI2(PI)', wrapPI2(PI), PI) # XXX self.test('wrapPI2(PI2)', wrapPI2(PI2), 0.0) self.test('wrapPI2(-PI_2)', wrapPI2(-PI_2), PI_2+PI) self.test('wrapPI2(-PI)', wrapPI2(-PI), PI) # XXX self.test('wrapPI2(-PI2)', abs(wrapPI2(-PI2)), 0.0) # -0.0 self.test('unroll180', fStr(unroll180(-90, 110, wrap=True)), '-160.0, -250.0') self.test('unroll180', fStr(unroll180(-90, 110, wrap=False)), '200.0, 110.0') self.test('unroll180', fStr(unroll180(-90, 830, wrap=True)), '-160.0, -250.0') self.test('unroll180', fStr(unroll180(-90, 830, wrap=False)), '920.0, 830.0') self.test('unroll180', fStr(unroll180(-110, 90, wrap=True)), '-160.0, -270.0') self.test('unroll180', fStr(unroll180(-110, 90, wrap=False)), '200.0, 90.0') self.test('unroll180', fStr(unroll180(-830, 90, wrap=True)), '-160.0, -990.0') self.test('unroll180', fStr(unroll180(-830, 90, wrap=False)), '920.0, 90.0') e = d = g = f = 0 for a in range(-1000, 1000): a *= 0.47 r = radians(a) sr, cr = sin(r), cos(r) s, c = sincos2(r) e = max(e, abs(sr - s), abs(cr - c)) sd, cd = sincos2d(a) d = max(d, abs(sr - sd), abs(cr - cd)) if sincosd: # compare with geographiclib s, c = sincosd(a) g = max(g, abs(sr - s), abs(cr - c)) f = max(f, abs(sd - s), abs(cd - c)) EPS_ = EPS * 8 self.test('sincos2', e, EPS, known=e < EPS_) self.test('sincos2d', d, EPS, known=d < EPS_) if sincosd: self.test('sincosd ', g, EPS, known=g < EPS_) self.test('sincos*d', f, EPS, known=f < EPS_) a, b = splice(range(10)) # PYCHOK false self.test('splice', (a, b), map1(type(a), (0, 2, 4, 6, 8), (1, 3, 5, 7, 9))) a, b, c = splice(range(10), n=3) # PYCHOK false self.test('splice', (a, b, c), map1(type(a), (0, 3, 6, 9), (1, 4, 7), (2, 5, 8))) a, b, c = splice(range(10), n=3, fill=-1) # PYCHOK false self.test('splice', (a, b, c), map1(type(a), (0, 3, 6, 9), (1, 4, 7, -1), (2, 5, 8, -1))) t = tuple(splice(range(12), n=5)) # PYCHOK false self.test('splice', t, map1(type(t[0]), (0, 5, 10), (1, 6, 11), (2, 7), (3, 8), (4, 9))) # <https://www.CivilGeo.com/when-a-foot-isnt-really-a-foot/> self.test('iFt2m', ft2m( 614963.91), 187441, fmt='%.0f') self.test('iFt2m', ft2m(2483759.84), 757050, fmt='%.0f') self.test('sFt2m', ft2m( 614962.68, usurvey=True), 187441, fmt='%.0f') self.test('sFt2m', ft2m(2483754.87, usurvey=True), 757050, fmt='%.0f') self.test('m2iFt', m2ft(187441), 614963.91, fmt='%.0f') self.test('m2iFt', m2ft(757050), 2483759.84, fmt='%.0f') self.test('m2sFt', m2ft(187441, usurvey=True), 614962.68, fmt='%.0f') self.test('m2sFt', m2ft(757050, usurvey=True), 2483754.87, fmt='%.0f') self.test('degrees2m', fStr(degrees2m(90), prec=4), '10007557.1761') self.test('degrees2m', fStr(degrees2m(90, lat=30), prec=4), '8666798.7443') self.test('m2degrees', fStr(m2degrees(degrees2m(90)), prec=1), '90.0') self.test('degrees2m', fStr(degrees2m(180), prec=4), '20015114.3522') self.test('degrees2m', fStr(degrees2m(180, lat=3-0), prec=4), '19987684.3336') self.test('m2degrees', fStr(m2degrees(degrees2m(180)), prec=1), '180.0') self.test('anStr', anStr('a-b?_'), 'a-b__') self.test('clipStr', clipStr('test/testUtily.py', limit=12), 'test/t....ily.py') self.test('isPoints2', isPoints2(None), False) self.test('limiterrors', limiterrors(False), True)
def testFormy(self): self.test('antipode1', antipode(89, 179), (-89.0, -1.0)) self.test('antipode2', antipode(-89, -179), (89.0, 1.0)) # roughly, Newport to New York self.test('bearing1', bearing(41.49, -71.31, 40.78, -73.97), 251.364, fmt='%.3f') self.test('bearing2', bearing(41.49, -71.31, 40.78, -73.97, final=False), 251.364, fmt='%.3f') self.test('bearing3', bearing(41.49, -71.31, 40.78, -73.97, final=True), 249.614, fmt='%.3f') self.test('isantipode1', isantipode(89, 179, -89, -1), True) self.test('isantipode2', isantipode(-89, -179, 89, 1), True) self.test('isantipode3', isantipode(-89, -179, -89, -1), False) self.test('isantipode4', isantipode_(*map1(radians, 89, 179, -89, -1)), True) self.test('isantipode5', isantipode_(*map1(radians, -89, -179, 89, 1)), True) self.test('isantipode6', isantipode_(*map1(radians, -89, -179, -89, -1)), False) self.test('heightOf0', heightOf(0, R_M), 2638958.23912, fmt='%.5f') self.test('heightOf45', heightOf(45, R_M), 5401080.43931, fmt='%.5f') self.test('heightOf90', heightOf(90, R_M), R_M, fmt='%.5f') # Height self.test('heightOf135', heightOf(135, R_M), 5401080.43931, fmt='%.5f') self.test('horizon0', horizon(0), 0.0) self.test('horizon10Km', horizon(10000), '357099.672', fmt='%.3f') self.test('horizon30Kft', horizon(10000, refraction=True), '392310.704', fmt='%.3f') self.test('horizon10Kft', horizon(3000, refraction=True), '214877.422', fmt='%.3f') # lat lon Auckland = -36.8485, 174.7633 Boston = 42.3541165, -71.0693514 Cleveland = 41.499498, -81.695391 LosAngeles = 34.0522, -118.2437 MtDiablo = 37.8816, -121.9142 Newport = 41.49008, -71.312796 NewYork = 40.7791472, -73.9680804 Santiago = -33.4489, -70.6693 X = 25.2522, 55.28 Y = 14.6042, 120.982 # <https://GeographicLib.SourceForge.io/cgi-bin/GeodSolve>, <https://www.Distance.to> for i, (ll1, ll2, expected) in enumerate(( (Boston, NewYork, 298009.404), # ..328,722.580 370 km (Boston, Newport, 98164.988), # ..106,147.318 99 km (Cleveland, NewYork, 651816.987), # ..736,534.840 536 km (NewYork, MtDiablo, 4084985.780), # ..4,587,896.452 3,952 km (Auckland, Santiago, 9670051.606), # ..15,045,906.074 9,665 km (Auckland, LosAngeles, 10496496.577), # ..13,002,288.857 10,940 km (LosAngeles, Santiago, 8998396.669), # ..10,578,638.162 8,993 km (X, Y, 6906867.946))): # ..6916,085.326 6,907 km self.testDistances(str(i + 1), *(ll1 + ll2), x=expected) # Thomas' S2, page 153 <https://apps.DTIC.mil/dtic/tr/fulltext/u2/703541.pdf> self.testDistances2('9', parseDMS('75 57 42.053'), 0, parseDMS('17 5 21.296'), parseDMS('85 31 54.631'), x=8044806.076, datum=Datums.NAD27) # Clarke1866 ellipsoid self.test(intersections2.__name__, intersections2.__module__, formy.__name__, nl=1) for datum in (None, R_M, Datums.WGS84): self.testIntersections2(datum) n = radical2.__name__ self.test(n, radical2(10, 4, 8), '(0.26, 2.6)', nl=1) self.test(n, radical2(10, 8, 4), '(0.74, 7.4)') self.test(n, radical2(10, 5, 5), '(0.5, 5.0)') try: # coverage self.test(n, radical2(10, 5, 4), IntersectionError.__name__, nt=1) except Exception as x: self.test(IntersectionError.__name__, str(x), 'distance (10.0), ...', known=True, nt=1) n = LimitError.__name__ t = limiterrors(True) try: # coverage self.test(n, equirectangular(0, 0, 60, 120), n) except Exception as x: self.test(n, str(x), 'delta exceeds ...', known=True) limiterrors(t)