Coverage for tests/test_NormalizedAngle.py: 22%

46 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 NormalizedAngleTestCase(unittest.TestCase): 

30 """Test normalized angle.""" 

31 

32 def testConstruction(self): 

33 a1 = NormalizedAngle(1.0) 

34 a2 = NormalizedAngle.fromRadians(1.0) 

35 a3 = NormalizedAngle.fromDegrees(57.29577951308232) 

36 self.assertEqual(a1, a2) 

37 self.assertEqual(a1.asRadians(), 1.0) 

38 self.assertEqual(a1, a3) 

39 self.assertEqual(a1.asDegrees(), 57.29577951308232) 

40 self.assertEqual(NormalizedAngle.between(NormalizedAngle(0), NormalizedAngle(1)), NormalizedAngle(1)) 

41 a = NormalizedAngle.center(NormalizedAngle(0), NormalizedAngle(1)) 

42 self.assertAlmostEqual(a.asRadians(), 0.5, places=15) 

43 a = NormalizedAngle(LonLat.fromDegrees(45, 0), LonLat.fromDegrees(90, 0)) 

44 self.assertAlmostEqual(a.asDegrees(), 45.0, places=13) 

45 a = NormalizedAngle(UnitVector3d.Y(), UnitVector3d.Z()) 

46 self.assertAlmostEqual(a.asDegrees(), 90.0, places=13) 

47 

48 def testComparisonOperators(self): 

49 a1 = NormalizedAngle(1) 

50 a2 = NormalizedAngle(2) 

51 self.assertNotEqual(a1, a2) 

52 self.assertLess(a1, a2) 

53 self.assertLessEqual(a1, a2) 

54 self.assertGreater(a2, a1) 

55 self.assertGreaterEqual(a2, a1) 

56 

57 def testArithmeticOperators(self): 

58 a = NormalizedAngle(1) 

59 b = -a 

60 self.assertEqual(a + b, Angle(0)) 

61 self.assertEqual(a - b, 2.0 * a) 

62 self.assertEqual(a - b, a * 2.0) 

63 self.assertEqual(a / 1.0, a) 

64 self.assertEqual(a / a, 1.0) 

65 

66 def testAngleTo(self): 

67 self.assertEqual(NormalizedAngle(1).getAngleTo(NormalizedAngle(2)), NormalizedAngle(1)) 

68 

69 def testString(self): 

70 self.assertEqual(str(NormalizedAngle(1)), "1.0") 

71 self.assertEqual(repr(NormalizedAngle(1)), "NormalizedAngle(1.0)") 

72 a = NormalizedAngle(0.5) 

73 self.assertEqual(a, eval(repr(a), {"NormalizedAngle": NormalizedAngle})) 

74 

75 def testPickle(self): 

76 a = NormalizedAngle(1.5) 

77 b = pickle.loads(pickle.dumps(a)) 

78 self.assertEqual(a, b) 

79 

80 

81if __name__ == "__main__": 

82 unittest.main()