Coverage for tests/test_LonLat.py: 32%

25 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-12 10:50 -0700

1# 

2# LSST Data Management System 

3# See COPYRIGHT file at the top of the source tree. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <https://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23import pickle 

24import unittest 

25 

26from lsst.sphgeom import Angle, LonLat, NormalizedAngle, UnitVector3d 

27 

28 

29class LonLatTestCase(unittest.TestCase): 

30 """Test LonLat.""" 

31 

32 def testConstruction(self): 

33 p = LonLat.fromDegrees(45, 45) 

34 self.assertEqual(p, LonLat(NormalizedAngle.fromDegrees(45), Angle.fromDegrees(45))) 

35 u = UnitVector3d(p) 

36 q = LonLat(u) 

37 self.assertAlmostEqual(p.getLon().asRadians(), q.getLon().asRadians(), places=13) 

38 self.assertAlmostEqual(p.getLat().asRadians(), q.getLat().asRadians(), places=13) 

39 self.assertAlmostEqual(p.getLon().asRadians(), LonLat.latitudeOf(u).asRadians(), places=13) 

40 self.assertAlmostEqual(p.getLon().asRadians(), LonLat.longitudeOf(u).asRadians(), places=13) 

41 

42 def testComparisonOperators(self): 

43 self.assertEqual(LonLat.fromDegrees(45, 45), LonLat.fromDegrees(45, 45)) 

44 self.assertNotEqual(LonLat.fromDegrees(0, 0), LonLat.fromDegrees(45, 45)) 

45 

46 def testString(self): 

47 p = LonLat.fromRadians(1, 1) 

48 self.assertEqual(str(p), "[1.0, 1.0]") 

49 self.assertEqual(repr(p), "LonLat.fromRadians(1.0, 1.0)") 

50 self.assertEqual(p, eval(repr(p), {"LonLat": LonLat})) 

51 

52 def testPickle(self): 

53 p = LonLat.fromRadians(2, 1) 

54 q = pickle.loads(pickle.dumps(p)) 

55 self.assertEqual(p, q) 

56 

57 

58if __name__ == "__main__": 

59 unittest.main()