Coverage for tests/test_NormalizedAngle.py: 22%

46 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-02 03:12 -0700

1# This file is part of sphgeom. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

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

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

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

18# (at your option) any later version. 

19# 

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

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

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

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <http://www.gnu.org/licenses/>. 

27 

28import pickle 

29import unittest 

30 

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

32 

33 

34class NormalizedAngleTestCase(unittest.TestCase): 

35 """Test normalized angle.""" 

36 

37 def testConstruction(self): 

38 a1 = NormalizedAngle(1.0) 

39 a2 = NormalizedAngle.fromRadians(1.0) 

40 a3 = NormalizedAngle.fromDegrees(57.29577951308232) 

41 self.assertEqual(a1, a2) 

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

43 self.assertEqual(a1, a3) 

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

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

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

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

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

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

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

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

52 

53 def testComparisonOperators(self): 

54 a1 = NormalizedAngle(1) 

55 a2 = NormalizedAngle(2) 

56 self.assertNotEqual(a1, a2) 

57 self.assertLess(a1, a2) 

58 self.assertLessEqual(a1, a2) 

59 self.assertGreater(a2, a1) 

60 self.assertGreaterEqual(a2, a1) 

61 

62 def testArithmeticOperators(self): 

63 a = NormalizedAngle(1) 

64 b = -a 

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

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

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

68 self.assertEqual(a / 1.0, a) 

69 self.assertEqual(a / a, 1.0) 

70 

71 def testAngleTo(self): 

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

73 

74 def testString(self): 

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

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

77 a = NormalizedAngle(0.5) 

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

79 

80 def testPickle(self): 

81 a = NormalizedAngle(1.5) 

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

83 self.assertEqual(a, b) 

84 

85 

86if __name__ == "__main__": 

87 unittest.main()