Coverage for tests/test_NormalizedAngle.py: 27%

48 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-19 11:56 +0000

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 def testConstruction(self): 

31 a1 = NormalizedAngle(1.0) 

32 a2 = NormalizedAngle.fromRadians(1.0) 

33 a3 = NormalizedAngle.fromDegrees(57.29577951308232) 

34 self.assertEqual(a1, a2) 

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

36 self.assertEqual(a1, a3) 

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

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

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

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

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

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

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

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

45 

46 def testComparisonOperators(self): 

47 a1 = NormalizedAngle(1) 

48 a2 = NormalizedAngle(2) 

49 self.assertNotEqual(a1, a2) 

50 self.assertLess(a1, a2) 

51 self.assertLessEqual(a1, a2) 

52 self.assertGreater(a2, a1) 

53 self.assertGreaterEqual(a2, a1) 

54 

55 def testArithmeticOperators(self): 

56 a = NormalizedAngle(1) 

57 b = -a 

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

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

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

61 self.assertEqual(a / 1.0, a) 

62 self.assertEqual(a / a, 1.0) 

63 

64 def testAngleTo(self): 

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

66 

67 def testString(self): 

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

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

70 a = NormalizedAngle(0.5) 

71 self.assertEqual(a, eval(repr(a), dict(NormalizedAngle=NormalizedAngle))) 

72 

73 def testPickle(self): 

74 a = NormalizedAngle(1.5) 

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

76 self.assertEqual(a, b) 

77 

78 

79if __name__ == "__main__": 79 ↛ 80line 79 didn't jump to line 80, because the condition on line 79 was never true

80 unittest.main()