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')
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_) # <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') for a in range(0, 90, 7): d = m2degrees(degrees2m(45, lat=a), lat=a) self.test('m2-degrees-2m(%s, lat=%s)' % (45, a), d, '45.00', fmt='%.2f') self.test('isPoints2', isPoints2(None), False)
def testElliptic(self): RC = elliptic._RC RD = elliptic._RD RF = elliptic._RF RG = elliptic._RG RJ = elliptic._RJ eps4 = EPS * 4 self.test('eps4', eps4, eps4, fmt='%.9e') y = 0.1 for x in range(2, 100): x *= 0.01 rc = RC(x, y) rf = RF(x, y, y) k = abs(rc - rf) < eps4 t = 'RC, RF(%.3f, ...)' % (x, ) self.test(t, rc, rf, fmt='%.12f', known=k) y = x for kp2 in range(1, 100): kp2 *= 0.01 rd = RD(0, kp2, 1) rj = RJ(0, kp2, 1, 1) k = abs(rd - rj) < eps4 t = 'RD, RJ(%.3f, ...)' % (kp2, ) self.test(t, rd, rj, fmt='%.12f', known=k) self.test('eps4', eps4, eps4, fmt='%.9e', nl=1) # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1EllipticFunction.html> e = elliptic.Elliptic(0.1) self.test('cK', e.cK, '1.612441349', fmt='%.9f') self.test('cE', e.cE, '1.530757637', fmt='%.9f') self.test('eps', e.eps, '0.0263340', fmt='%.7f') phi = radians(20) sn, cn = sincos2(phi) self.test('fE(phi)', e.fE(phi), '0.348372822', fmt='%.9f') dn = e.fDelta(sn, cn) self.test('fDelta(sn, cn)', dn, '0.994133906', fmt='%.9f') self.test('fD(sn, cn, dn)', e.fD(sn, cn, dn), '0.013885234', fmt='%.9f') self.test('fE(sn, cn, dn)', e.fE(sn, cn, dn), '0.348372822', fmt='%.9f') self.test('fEd(PI_2)', e.fEd(PI_2), '0.027415224', fmt='%.9f') self.test('fEinv(PI_2)', e.fEinv(PI_2), '1.612999420', fmt='%.9f') self.test('fF(sn, cn, dn)', e.fF(sn, cn, dn), '0.349761345', fmt='%.9f') self.test('fG(sn, cn, dn)', e.fG(sn, cn, dn), '0.348372822', fmt='%.9f') self.test('fH(sn, cn, dn)', e.fH(sn, cn, dn), '0.363646580', fmt='%.9f') self.test('fPi(sn, cn, dn)', e.fPi(sn, cn, dn), '0.349761345', fmt='%.9f') try: t = e.fPi(0, None, 1) except EllipticError as x: t = str(x) self.test('fPi(sn, None, dn)', t, 'invokation Elliptic.fPi(0, None, 1): invalid') try: t = e.fPi(0, 1, None) except EllipticError as x: t = str(x) self.test('fPi(sn, dn, None)', t, 'invokation Elliptic.fPi(0, 1, None): invalid') self.test('deltaD(sn, cn, dn)', e.deltaD(sn, cn, dn), '-0.3223642', fmt='%.7f', nl=1) self.test('deltaE(sn, cn, dn)', e.deltaE(sn, cn, dn), '0.0084191', fmt='%.7f') self.test('deltaEinv(sn, cn)', e.deltaEinv(sn, cn), '-0.0082518', fmt='%.7f') self.test('deltaF(sn, cn, dn)', e.deltaF(sn, cn, dn), '-0.0083379', fmt='%.7f') self.test('deltaG(sn, cn, dn)', e.deltaG(sn, cn, dn), '0.0084191', fmt='%.7f') self.test('deltaH(sn, cn, dn)', e.deltaH(sn, cn, dn), '0.3688975', fmt='%.7f') self.test('deltaPi(sn, cn, dn)', e.deltaPi(sn, cn, dn), '-0.0083379', fmt='%.7f') try: t = e.deltaPi(0, None, 1) except EllipticError as x: t = str(x) self.test('deltaPi(sn, None, dn)', t, 'invokation Elliptic.deltaPi(0, None, 1): invalid') try: t = e.deltaPi(0, 1, None) except EllipticError as x: t = str(x) self.test('deltaPi(sn, dn, None)', t, 'invokation Elliptic.deltaPi(0, 1, None): invalid') # U{Carlson<https://ArXiv.org/pdf/math/9409227.pdf>} 3 Numerical checks self.test('RF(1, 2, 0)', RF(1, 2, 0), '1.3110287771461', fmt='%.13f', nl=1) self.test('RF(2, 3, 4)', RF(2, 3, 4), '0.58408284167715', fmt='%.14f') self.test('RC(0, 1/4)', RC(0, 0.25), '3.1415926535898', fmt='%.13f') # PI self.test('RC(9/4, 2)', RC(2.25, 2), '0.69314718055995', fmt='%.14f') # ln(2) self.test('RJ(0, 1, 2, 3)', RJ(0, 1, 2, 3), '0.77688623778582', fmt='%.14f') self.test('RJ(2, 3, 4, 5)', RJ(2, 3, 4, 5), '0.14297579667157', fmt='%.14f') self.test('RD(0, 2, 1)', RD(0, 2, 1), '1.7972103521034', fmt='%.13f') self.test('RD(2, 3, 4)', RD(2, 3, 4), '0.16510527294261', fmt='%.14f') self.test('RG(0, 16, 16)', RG(0, 16, 16), '3.1415926535898', fmt='%.13f') # PI self.test('RG(2, 3, 4)', RG(2, 3, 4), '1.7255030280692', fmt='%.13f') self.test('RG(0, 0.0796, 4)', RG(0, 0.0796, 4), '1.0284758090288', fmt='%.13f') e.reset(0, 0) self.test('sncndn(x)', fstr(e.sncndn(0), prec=9), '0.0, 1.0, 1.0', nl=1) self.test('sncndn(x)', fstr(e.sncndn(PI_2), prec=9), '1.0, -0.0, 1.0', known=True) e.reset(1, 1) self.test('sncndn(x)', fstr(e.sncndn(0), prec=9), '0.0, 1.0, 1.0') self.test('sncndn(x)', fstr(e.sncndn(PI_2), prec=9), '0.917152336, 0.398536815, 0.398536815') self.test('sncndn(x)', type(e.sncndn(PI_4)), elliptic.Elliptic3Tuple) self.testCopy(e) for f in range(4): # coverage t = (f / 4.0, ) * 4 e = elliptic.Elliptic(*t) s = 'k2 alpha2 kp2 alphap2' e = tuple(getattr(e, a) for a in s.split()) t = tuple(Scalar(f, name=n) for n, f in zip(s.split(), t)) self.test(s, e, t)
def testElliptic(self): _RC = elliptic._RC _RD = elliptic._RD _RF = elliptic._RF _RG = elliptic._RG _RJ = elliptic._RJ eps = EPS * 4 self.test('eps', eps, eps, fmt='%.12e') y = 0.1 for x in range(2, 100): x *= 0.01 rc = _RC(x, y) rf = _RF(x, y, y) k = abs(rc - rf) < eps t = '_RC, _RF(%.3f, ...)' % (x, ) self.test(t, rc, rf, fmt='%.12f', known=k) y = x for kp2 in range(1, 100): kp2 *= 0.01 rd = _RD(0, kp2, 1) rj = _RJ(0, kp2, 1, 1) k = abs(rd - rj) < eps t = '_RD, _RJ(%.3f, ...)' % (kp2, ) self.test(t, rd, rj, fmt='%.12f', known=k) self.test('eps', eps, eps, fmt='%.12e') # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1EllipticFunction.html> e = elliptic.Elliptic(0.1) self.test('cK', e.cK, '1.612441349', fmt='%.9f') self.test('cE', e.cE, '1.530757637', fmt='%.9f') phi = radians(20) sn, cn = sincos2(phi) self.test('fE(phi)', e.fE(phi), '0.348372822', fmt='%.9f') dn = e.fDelta(sn, cn) self.test('fDelta', dn, '0.994133906', fmt='%.9f') self.test('fE(sn, cn, Delta)', e.fE(sn, cn, dn), '0.348372822', fmt='%.9f') self.test('fEd(PI_2)', e.fEd(PI_2), '0.027415224', fmt='%.9f') self.test('fEinv(PI_2)', e.fEinv(PI_2), '1.612999420', fmt='%.9f') self.test('fF(sn, cn, dn)', e.fF(sn, cn, dn), '0.349761345', fmt='%.9f') self.test('fG(sn, cn, dn)', e.fG(sn, cn, dn), '0.348372822', fmt='%.9f') self.test('fH(sn, cn, dn)', e.fH(sn, cn, dn), '0.363646580', fmt='%.9f') self.test('fPi(sn, cn, dn)', e.fPi(sn, cn, dn), '0.349761345', fmt='%.9f') self.test('_RF(1, 2, 0)', _RF(1, 2, 0), '1.311028777', fmt='%.9f') self.test('_RF(2, 3, 4)', _RF(2, 3, 4), '0.584082842', fmt='%.9f') self.test('_RC(0, 1/4)', _RC(0, 0.25), '3.141592654', fmt='%.9f') self.test('_RC(9/4, 2)', _RC(2.25, 2), '0.693147181', fmt='%.9f') self.test('_RC(1/4,-2)', _RC(0.25, -2), '0.231049060', fmt='%.9f') self.test('_RJ(0, 1, 2, 3)', _RJ(0, 1, 2, 3), '0.776886238', fmt='%.9f') self.test('_RJ(2, 3, 4, 5)', _RJ(2, 3, 4, 5), '0.142975797', fmt='%.9f') self.test('_RD(0, 2, 1)', _RD(0, 2, 1), '1.797210352', fmt='%.9f') self.test('_RD(2, 3, 4)', _RD(2, 3, 4), '0.165105273', fmt='%.9f') self.test('_RG(0, 16, 16)', _RG(0, 16, 16), '3.141592654', fmt='%.9f') self.test('_RG(2, 3, 4)', _RG(2, 3, 4), '1.725503028', fmt='%.9f') self.test('_RG(0, 0.0796, 4)', _RG(0, 0.0796, 4), '1.028475809', fmt='%.9f') e.reset(0, 0) self.test('sncndn(x)', fStr(e.sncndn(0), prec=9), '0.0, 1.0, 1.0') self.test('sncndn(x)', fStr(e.sncndn(PI_2), prec=9), '1.0, -0.0, 1.0', known=True) e.reset(1, 1) self.test('sncndn(x)', fStr(e.sncndn(0), prec=9), '0.0, 1.0, 1.0') self.test('sncndn(x)', fStr(e.sncndn(PI_2), prec=9), '0.917152336, 0.398536815, 0.398536815')
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.0) self.test('wrap90(180)', wrap90(180), -180.0) self.test('wrap90(360)', wrap90(360), 0.0) self.test('wrap90(-90)', wrap90(-90), -90.0) self.test('wrap90(-180)', wrap90(-180), -180.0) self.test('wrap90(-360)', wrap90(-360), 0.0) self.test('wrap180(90)', wrap180(90), 90.0) self.test('wrap180(180)', wrap180(180), 180.0) self.test('wrap180(360)', wrap180(360), 0.0) self.test('wrap180(-90)', wrap180(-90), -90.0) self.test('wrap180(-180)', wrap180(-180), -180.0) self.test('wrap180(-360)', wrap180(-360), 0.0) self.test('wrap360(90)', wrap360(90), 90.0) self.test('wrap360(180)', wrap360(180), 180.0) self.test('wrap360(360)', wrap360(360), 0.0) self.test('wrap360(-90)', wrap360(-90), 270.0) self.test('wrap360(-180)', wrap360(-180), 180.0) self.test('wrap360(-360)', wrap360(-360), 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)', 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 = t = 0 for a in range(-1000, 1000, 2): 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 Math: # compare with geographiclib t = max(t, abs(atan2d(sr, cr) - atand(sr, cr))) 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 Math: self.test('atand', t, EPS, known=t < EPS) self.test('sincosd ', g, EPS_, known=g < EPS_) self.test('sincos*d', f, EPS_, known=f < EPS_) # <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, prec=2) self.test('m2iFt', m2ft(757050), 2483759.84, prec=2) self.test('m2sFt', m2ft(187441, usurvey=True), 614962.68, prec=2) self.test('m2sFt', m2ft(757050, usurvey=True), 2483754.87, prec=2) for f, m in ((m2yard, '1.093613'), (acre2ha, '0.404686'), (acre2m2, '4046.856422'), (chain2m, '20.116800'), (fathom2m, '1.828800'), (furlong2m, '201.168000'), (yard2m, '0.914400')): self.test(f.__name__, f(1), m, prec=6) 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') t = 'm2degrees2m(%s, lat=%s)' for a in range(0, 90, 7): d = m2degrees(degrees2m(45, lat=a), lat=a) self.test(t % (45, a), d, '45.00', prec=2) self.test('isPoints2', isPoints2(None), False)
def testElliptic(self): _RC = elliptic._RC _RD = elliptic._RD _RF = elliptic._RF _RG = elliptic._RG _RJ = elliptic._RJ eps4 = EPS * 4 self.test('eps4', eps4, eps4, fmt='%.9e') y = 0.1 for x in range(2, 100): x *= 0.01 rc = _RC(x, y) rf = _RF(x, y, y) k = abs(rc - rf) < eps4 t = '_RC, _RF(%.3f, ...)' % (x, ) self.test(t, rc, rf, fmt='%.12f', known=k) y = x for kp2 in range(1, 100): kp2 *= 0.01 rd = _RD(0, kp2, 1) rj = _RJ(0, kp2, 1, 1) k = abs(rd - rj) < eps4 t = '_RD, _RJ(%.3f, ...)' % (kp2, ) self.test(t, rd, rj, fmt='%.12f', known=k) self.test('eps4', eps4, eps4, fmt='%.9e') # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1EllipticFunction.html> e = elliptic.Elliptic(0.1) self.test('cK', e.cK, '1.612441349', fmt='%.9f') self.test('cE', e.cE, '1.530757637', fmt='%.9f') self.test('eps', e.eps, '0.0263340', fmt='%.7f') phi = radians(20) sn, cn = sincos2(phi) self.test('fE(phi)', e.fE(phi), '0.348372822', fmt='%.9f') dn = e.fDelta(sn, cn) self.test('fDelta(sn, cn)', dn, '0.994133906', fmt='%.9f') self.test('fD(sn, cn, dn)', e.fD(sn, cn, dn), '0.013885234', fmt='%.9f') self.test('fE(sn, cn, dn)', e.fE(sn, cn, dn), '0.348372822', fmt='%.9f') self.test('fEd(PI_2)', e.fEd(PI_2), '0.027415224', fmt='%.9f') self.test('fEinv(PI_2)', e.fEinv(PI_2), '1.612999420', fmt='%.9f') self.test('fF(sn, cn, dn)', e.fF(sn, cn, dn), '0.349761345', fmt='%.9f') self.test('fG(sn, cn, dn)', e.fG(sn, cn, dn), '0.348372822', fmt='%.9f') self.test('fH(sn, cn, dn)', e.fH(sn, cn, dn), '0.363646580', fmt='%.9f') self.test('fPi(sn, cn, dn)', e.fPi(sn, cn, dn), '0.349761345', fmt='%.9f') try: t = e.fPi(0, None, 1) except EllipticError as x: t = str(x) self.test('fPi(sn, None, dn)', t, 'invokation invalid: Elliptic.fPi(0, None, 1)') try: t = e.fPi(0, 1, None) except EllipticError as x: t = str(x) self.test('fPi(sn, dn, None)', t, 'invokation invalid: Elliptic.fPi(0, 1, None)') self.test('deltaD(sn, cn, dn)', e.deltaD(sn, cn, dn), '-0.3223642', fmt='%.7f') self.test('deltaE(sn, cn, dn)', e.deltaE(sn, cn, dn), '0.0084191', fmt='%.7f') self.test('deltaEinv(sn, cn)', e.deltaEinv(sn, cn), '-0.0082518', fmt='%.7f') self.test('deltaF(sn, cn, dn)', e.deltaF(sn, cn, dn), '-0.0083379', fmt='%.7f') self.test('deltaG(sn, cn, dn)', e.deltaG(sn, cn, dn), '0.0084191', fmt='%.7f') self.test('deltaH(sn, cn, dn)', e.deltaH(sn, cn, dn), '0.3688975', fmt='%.7f') self.test('deltaPi(sn, cn, dn)', e.deltaPi(sn, cn, dn), '-0.0083379', fmt='%.7f') try: t = e.deltaPi(0, None, 1) except EllipticError as x: t = str(x) self.test('deltaPi(sn, None, dn)', t, 'invokation invalid: Elliptic.deltaPi(0, None, 1)') try: t = e.deltaPi(0, 1, None) except EllipticError as x: t = str(x) self.test('deltaPi(sn, dn, None)', t, 'invokation invalid: Elliptic.deltaPi(0, 1, None)') self.test('_RF(1, 2, 0)', _RF(1, 2, 0), '1.311028777', fmt='%.9f') self.test('_RF(2, 3, 4)', _RF(2, 3, 4), '0.584082842', fmt='%.9f') self.test('_RC(0, 1/4)', _RC(0, 0.25), '3.141592654', fmt='%.9f') self.test('_RC(9/4, 2)', _RC(2.25, 2), '0.693147181', fmt='%.9f') self.test('_RC(1/4,-2)', _RC(0.25, -2), '0.231049060', fmt='%.9f') self.test('_RJ(0, 1, 2, 3)', _RJ(0, 1, 2, 3), '0.776886238', fmt='%.9f') self.test('_RJ(2, 3, 4, 5)', _RJ(2, 3, 4, 5), '0.142975797', fmt='%.9f') self.test('_RD(0, 2, 1)', _RD(0, 2, 1), '1.797210352', fmt='%.9f') self.test('_RD(2, 3, 4)', _RD(2, 3, 4), '0.165105273', fmt='%.9f') self.test('_RG(0, 16, 16)', _RG(0, 16, 16), '3.141592654', fmt='%.9f') self.test('_RG(2, 3, 4)', _RG(2, 3, 4), '1.725503028', fmt='%.9f') self.test('_RG(0, 0.0796, 4)', _RG(0, 0.0796, 4), '1.028475809', fmt='%.9f') e.reset(0, 0) self.test('sncndn(x)', fStr(e.sncndn(0), prec=9), '0.0, 1.0, 1.0') self.test('sncndn(x)', fStr(e.sncndn(PI_2), prec=9), '1.0, -0.0, 1.0', known=True) e.reset(1, 1) self.test('sncndn(x)', fStr(e.sncndn(0), prec=9), '0.0, 1.0, 1.0') self.test('sncndn(x)', fStr(e.sncndn(PI_2), prec=9), '0.917152336, 0.398536815, 0.398536815') self.test('sncndn(x)', type(e.sncndn(PI_4)), elliptic.Elliptic3Tuple) self.testCopy(e) for t in range(4): # coverage t = (t / 4.0, ) * 4 e = elliptic.Elliptic(*t) self.test('k2, alpha2, kp2, alphap2', (e.k2, e.alpha2, e.kp2, e.alphap2), t)